Python Compiler

Write Python and run it. Real CPython in your browser - no install, no account, nothing sent to a server.

← VizLearn
main.py Python 3
Output

                

What this is

CPython compiled to WebAssembly, running on your own machine. Your code is never uploaded, and the page works offline once it has loaded the interpreter.

The first Run takes a few seconds while the interpreter downloads. Every run after that is immediate.

What works

  • The standard library — math, json, re, collections, itertools, datetime and the rest.
  • print, f-strings, comprehensions, classes, generators.
  • Tracebacks, in full. A mistake here reads exactly as it would in a terminal.

What does not

  • input() — there is no stdin to read from.
  • Reading or writing files on your computer.
  • Network calls, and packages that need to be installed.

How it runs

This is not Python translated into JavaScript. It is CPython itself — the same interpreter you would install — compiled to WebAssembly by the Pyodide project and executed by your browser. Semantics match a normal interpreter because it is one.

It runs in a worker thread, separate from the page. That is why an accidental infinite loop freezes the output rather than the whole tab, and why the editor stays responsive while your code is running. A run that has not finished within ten seconds is stopped and reported, which is almost always a loop that never exits.

The first run downloads the interpreter, which takes a few seconds on a normal connection. After that it is cached, so subsequent runs start immediately, and the page keeps working with no connection at all.

Reading a traceback

Errors appear exactly as they would in a terminal, and they are worth reading from the bottom up. The last line names the exception and the message; the lines above it show the call path that reached it, most recent last.

The four you will meet earliest: SyntaxError means the file could not be parsed at all, so nothing ran — usually a missing bracket or colon on the line before the one reported. NameError means a name was used before it was defined, which is often a typo. TypeError means an operation met a type it cannot handle, such as adding a string to a number. IndentationError means the whitespace does not describe a consistent block.

Files, timing and limits

There is an in-memory filesystem, so open, read and write all work normally. The files are real for the length of the run and gone afterwards, which makes this a genuine place to practise file handling without touching your computer.

time.perf_counter works and is accurate enough to compare two approaches, though everything runs slower than a native interpreter — often several times slower. Relative comparisons hold; absolute numbers do not transfer.

Recursion is limited by the browser stack, which is smaller than a desktop Python's. Deep recursion raises rather than crashing, and an iterative version will usually run where a recursive one will not.

Things worth trying

  • Paste code from anywhere and run it. Nothing is uploaded, so there is no reason not to.
  • Break something deliberately — index past the end of a list, divide by zero, misspell a method — and read what comes back. Recognising tracebacks is most of debugging.
  • Compare two approaches with time.perf_counter: a loop against a comprehension, a list against a set for membership tests.
  • Use collections.Counter, itertools and json — the standard library is all here, and it is larger than most people use.

Learning Python?

The Python track teaches it one idea at a time, each with an editor like this one beside the explanation — starting at your first print statement.