DevTools Logo

Python Playground

Python Playground

Simulate a small Python subset locally — or copy a Pyodide bootstrap for a real runtime.

Runs in your browser
Try an example

Input

1 line · 14 chars

Result

7 lines · 355 chars

Python Playground is a lightweight hand-written simulator for a small Python subset — it does not run a real interpreter and no runtime is downloaded. Supported: print(), variable assignment, input() with pre-filled stdin, f-strings, arithmetic (including // floor division and float division), string concatenation, list literals, comprehensions over range(), len(), indexing, and True/False/None. Unsupported syntax (imports, functions, classes, loops, if blocks) returns an explicit error instead of pretending to run. The tool also generates a copy-paste Pyodide bootstrap so you can run the same script on a real Python runtime yourself; nothing is uploaded and packages like numpy are not loaded here.

Examples

Input
print("hi")
2 + 2
Output
hi
4

Printed lines go to stdout while the final expression is shown as a result.

Input
import json
json.dumps({"a": 1})
Output
{"a": 1}

Standard library modules are available without installing anything.

Input
1 / 0
Output
ZeroDivisionError: division by zero

Exceptions are rendered with a Python-style traceback pointing at your line.

About this tool

This is a real Python interpreter, not a JavaScript approximation. Pyodide brings CPython to WebAssembly, so the standard library, comprehensions, classes and the usual traceback format all behave as you expect.

The editor and output panes are designed for quick experiments: run with a shortcut, read stdout and stderr separately, see the final expression like a REPL, and jump to the offending line from a traceback.

The first run downloads the runtime (around 10 MB) and caches it. Packages such as numpy and matplotlib are loaded only when requested, with their sizes disclosed before you click. Execution is capped by a watchdog you can extend explicitly.

What this tool does not do

  • The runtime download is required on first use; offline visits cannot run code until it has been cached.
  • Not every PyPI package is available: binary wheels need a Pyodide build.
  • Execution is single-threaded and bounded by the watchdog; long computations belong in a real Python environment.

How to use this tool

  1. Write a script

    Type Python into the editor or load one of the example chips. Tab inserts spaces and the editor is labeled for assistive technology.

  2. Run

    Press Run or Ctrl/⌘+Enter. On first use the runtime downloads with a progress badge; later runs start from cache.

  3. Read the output

    stdout and stderr appear in separate panes. Exceptions show a Python-style traceback and the last expression is displayed REPL style.

  4. Add packages

    Click a package chip to load it, or use micropip for pure-Python wheels. Matplotlib figures appear in the figures pane.

Use cases

Learn Python

Experiment with syntax, comprehensions and the standard library without installing Python locally.

Share minimal reproductions

Paste a short script into a playground link so others can run the same code in their browser.

Data-science sketches

Load numpy, pandas or matplotlib on demand and try a data transformation without a project setup.

Output panes

PaneContents
stdoutprint() output
stderrwarnings and redirected errors
Resultrepr of the last expression
TracebackPython-style exception
Figuresmatplotlib images

A watchdog stops runaway code at the configured limit and keeps output produced so far.

Common mistakes

Mistake:Assuming every pip package works.

Fix:Pyodide runs CPython on WebAssembly. Pure-Python wheels work through micropip; compiled extensions must be Pyodide-built and are offered only where available.

Mistake:Forgetting that the first run downloads a runtime.

Fix:The first run fetches roughly 10 MB and shows progress; subsequent runs use the browser cache and start much faster.

Mistake:Leaving an infinite loop running.

Fix:A watchdog stops code at the configured limit. Partial output is kept, and you can raise the limit explicitly for genuinely long jobs.

Frequently asked questions

Which Python version does it run?

Pyodide ships CPython compiled to WebAssembly and the version is shown in the status badge once the runtime is ready. It is real CPython, so standard library behavior matches desktop Python of that version.

Can I install packages like pandas or numpy?

Yes. Common packages are offered as one-click chips with their download sizes shown. Beyond those, micropip can install pure-Python wheels from PyPI; compiled packages need a Pyodide-specific build and may not be available.

Is my code uploaded?

No. Compilation and execution happen entirely in your browser tab. The only network traffic is the one-time runtime and package download from the pinned, integrity-checked asset host.

Why does my pip package not work?

A package with C extensions must be compiled for the Pyodide WebAssembly target. Pure-Python wheels install with micropip; for compiled packages use the Pyodide-built versions offered in the package menu.

Are there execution limits?

Yes. A watchdog stops code after a default time limit, which you can extend explicitly up to a higher cap. Output is capped as well, and the interpreter cannot run in the background once you leave the page.

References & standards