CPython
CPython is the reference implementation of the Python language, written in C. It is the interpreter almost everyone means when they say "Python", and its internal design explains a great deal of the behaviour learners mistake for language rules.
Detailed Explanation
Python is two separate things. There is the language, defined by a written specification. There is the implementation, an actual program that reads your .py file and does what it says. CPython is that program. When you install Python from python.org, from Homebrew, from apt, or inside a Docker image, you are installing CPython.
It is called CPython because it is written in C. Guido van Rossum wrote the first version in 1990, and it remains the implementation that new language features land in first. If a feature is not in CPython, it is not really in Python yet.
Internally, CPython does two jobs. First, it compiles your source into bytecode, a compact list of instructions for an imaginary stack machine. Second, it runs those instructions in a big loop written in C, usually called the eval loop. Every Python value it manipulates is a C struct that begins with a reference count and a pointer to its type. That layout is why Python objects carry more overhead than a C int, and why sys.getsizeof(1) reports 28 bytes rather than 4.
Memory is managed by reference counting, backed up by a generational collector that catches reference cycles. Counting has a real benefit: an object dies the moment its last reference disappears, so file handles and sockets usually close promptly without you thinking about it. It also has a cost. Every assignment touches a counter, and those counters would corrupt if two threads updated them at once.
That problem is the reason for the Global Interpreter Lock. The GIL is one mutex that a thread must hold to execute bytecode. Threads still help when your program waits on disk or network, because CPython releases the lock around blocking calls. Threads do not help CPU-bound pure-Python work, which is why the standard advice is multiprocessing or a C extension for number crunching.
CPython has not stood still. Python 3.11 introduced a specializing adaptive interpreter that rewrites hot bytecode into faster type-specific forms, giving broad speedups over 3.10 with no code changes. Python 3.13 added an optional free-threaded build that removes the GIL entirely, plus an experimental just-in-time compiler. Both are opt-in, so the GIL is still the default reality in production.
Other implementations exist and make different trade-offs:
| Implementation | Trade-off |
|---|---|
| PyPy | Tracing JIT, often several times faster on pure Python, weaker C-extension support |
| GraalPy | Runs on the JVM, useful for Java interoperability |
| MicroPython | Fits on microcontrollers, ships a reduced standard library |
| Pyodide | CPython compiled to WebAssembly, runs in a browser |
This matters because much of what you will read about Python is CPython trivia, not language law. Small-integer caching, string interning, id() values, and cleanup timing are all implementation details. Dictionary insertion order was a CPython 3.6 accident before it became a language guarantee in 3.7. Write code that depends on documented behaviour, and treat the rest as an interesting explanation of why things feel the way they do.
Code Examples
import sys
import platform
# Ask the runtime what it actually is, rather than assuming.
print(sys.implementation.name) # cpython
print(platform.python_implementation()) # CPython
print(sys.version_info[:2]) # (3, 11) on a 3.11 install
# Objects carry a reference count. getrefcount sees one extra reference,
# because passing the object to the function is itself a reference.
session_ids = [101, 102]
print(sys.getrefcount(session_ids)) # 2
alias = session_ids
print(sys.getrefcount(session_ids)) # 3# Behaviour that comes from CPython, not from the language spec.
# CPython pre-allocates one object per small integer from -5 to 256.
a = 256
b = 256
print(a is b) # True -> both names point at the cached object
# Larger integers are not cached, but the compiler folds equal constants
# inside a SINGLE code object, so this is still True in a script.
c = 257
d = 257
print(c is d) # True in a module or script
# Type the same two lines in the interactive REPL and you get False,
# because each REPL statement is compiled separately. Never compare
# numbers or strings with `is`; use == for value equality.
print(c == d) # True, and this is the reliable testCommon Gotchas
`is` is not `==`
`is` asks "the same object?", `==` asks "the same value?". Interning makes `is` accidentally work for small integers and short literals, so the bug hides until a value grows past 256 or arrives from JSON. Reserve `is` for `None`, `True`, `False`, and sentinel objects.
The GIL limits threads, not processes
spinning up eight threads to crunch numbers on eight cores gives you roughly one core of throughput plus lock overhead. Use `multiprocessing`, `concurrent.futures.ProcessPoolExecutor`, or a library like NumPy that releases the GIL inside C code.
Prompt cleanup is a refcount side effect
a file opened without `with` often closes when the last reference vanishes, and that is reference counting rather than a promise. PyPy and the free-threaded build may delay it. Use `with` so correctness does not depend on the implementation.
Version claims age quickly
"Python is slow" was measured against an older interpreter. Benchmark on the exact version you deploy, because 3.11 onwards changed the numbers substantially.