Python reference implementation
CPython is the reference implementation of the Python programming language. Written in C and Python, CPython is the default and most widely used implementation of the Python language. CPython can be defined โ€ฆ Wikipedia
Factsheet
Original author Guido van Rossum
Developers Python core developers and the Python community, supported by the Python Software Foundation
Initial release 26 January 1994; 32 years ago (1994-01-26)
Factsheet
Original author Guido van Rossum
Developers Python core developers and the Python community, supported by the Python Software Foundation
Initial release 26 January 1994; 32 years ago (1994-01-26)
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ CPython
CPython - Wikipedia
1 month ago - CPython is the reference implementation of the Python programming language. Written in C and Python, CPython is the default and most widely used implementation of the Python language. CPython can be defined as both an interpreter and a compiler as it compiles Python code into bytecode before ...
๐ŸŒ
Reddit
reddit.com โ€บ r โ€บ Python
r/Python
January 25, 2008 - By bringing Astralโ€™s tooling and engineering expertise to OpenAI, we will accelerate our work on Codex and expand what AI can do across the software development lifecycle. Saturday Daily Thread: Resource Request and Sharing! Daily Thread ... Stumbled upon a useful Python resource?
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ extending โ€บ extending.html
1. Extending Python with C or C++ โ€” Python 3.14.4 documentation
The C extension interface is specific to CPython, and extension modules do not work on other Python implementations. In many cases, it is possible to avoid writing C extensions and preserve portability to other implementations. For example, if your use case is calling C library functions or system calls, you should consider using the ctypes module or the cffi library rather than writing custom C code.
๐ŸŒ
Python
python.org โ€บ about
About Pythonโ„ข | Python.org
Python can be easy to pick up whether you're a first time programmer or you're experienced with other languages.
๐ŸŒ
Cornell Virtual Workshop
cvw.cac.cornell.edu โ€บ python-performance โ€บ intro โ€บ cpython-api
Cornell Virtual Workshop > Python for High Performance > Overview > CPython and the Python/C API
CPython, which is written in C, ... other language that C can interoperate with). The Python/C API allows for compiled pieces of code to be called from Python programs or executed within the CPython interpreter....
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ c-api โ€บ index.html
Python/C API reference manual โ€” Python 3.14.4 documentation
This manual documents the API used by C and C++ programmers who want to write extension modules or embed Python. It is a companion to Extending and Embedding the Python Interpreter, which describes...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ understanding what cpython actually is has greatly enhanced my understanding of python.
r/learnpython on Reddit: Understanding what CPython actually IS has greatly enhanced my understanding of Python.
May 25, 2024 -

First off, its perfectly understandable to not really care about language theory as a beginner. This stuff is not necessary to learn to code.

However, after recently doing some deep dives on what CPython really is and how it works, I have found the knowledge to be extremely enlightening. And it has really opened my eyes as to how Python is used, and why its used in the places it is.

For those who are unaware, allow me to share what I've learned.

So the key piece of information is that CPython is, at its core, a program written in C. Its purpose is to take Python code as input, then convert that Python into its own native instructions (written in C), and then execute them. And perhaps most importantly, it does this in a line-by-line manner. That just means it doesn't try to error check the entire program before running it. Potential errors just happen as it goes through each line of code, one by one.

However its also important to understand that Python is actually still semi-compiled into "bytecode", which is an intermediate stage between Python and full machine code. CPython converts your python scripts into bytecode files first, so what it actually runs is the bytecode files.

Now where it gets super interesting is that CPython is not the only "implementation" of Python (implementation means some kind of program, or system, that takes Python code as input and does something with it). More on that later.

On the subject of bytecode, it naturally leads to some other interesting questions, such as "Can I share the bytecode files?", to which the answer is no. That's one of the key aspects of CPython. The bytecode is "not platform agnostic". (I'm really sorry if that's not the correct term, I just learned all this stuff recently). That means the bytecode itself is compiled for your specific environment (the python version and dependencies). The reason for this is that its part of Python's design philosophy to be constantly improving the bytecode.

Once you understand that you can then comprehend what other implementations of Python do. PyPy for instance aims to make a Python running environment that works more like Java, where it performs "just-in-time" compilation to turn the bytecode into native machine code at runtime, and that's why it can make certain things run faster. Then you have the gamut of other ways Python can be used, such as:

  • Cython - aims to translate Python into C, which can then be compiled

  • Nuitka - aims to translate Python into C++, which is more versatile and less restrictive

  • Jython - this semi-compiles Python into Java bytecode that can be run in a Java virtual machine/runtime

  • IronPython - semi-compiles Python into C# bytecode, for running in .NET runtime

  • PyPy - A custom JIT-compiler that works in a manner philosophically similar to Java

  • MicroPython - a special version of python that's made for embedded systems and 'almost' bare-metal programming

Oh and then there's also the fact that if you want to use Python for scripting while working in other languages, its important to understand the difference between calling CPython directly, or using "embedded" CPython. For instance some game coders might opt to just call CPython as an external program. However some might opt to just build CPython directly into the game itself so that it does not need to. Different methods might be applicable to different uses.

Anyway all of this shit has been very entertaining for me so hopefully someone out there finds this interesting.

Find elsewhere
๐ŸŒ
InfoWorld
infoworld.com โ€บ home โ€บ software development โ€บ programming languages โ€บ python
PythoC: A new way to generate C code from Python | InfoWorld
December 19, 2025 - A new project, PythoC, takes a different approach. It uses type-hinted Python to programmatically generate C codeโ€”but chiefly for standalone use, and with many more compile-time code generation features than Cython has.
๐ŸŒ
Real Python
realpython.com โ€บ c-for-python-programmers
C for Python Programmers โ€“ Real Python
January 25, 2023 - In this tutorial, you'll learn the basics of the C language, which is used in the source code for CPython, the most popular Python implementation. Learning C is important for Python programmers interested in contributing to CPython.
๐ŸŒ
Real Python
realpython.com โ€บ build-python-c-extension-module
Building a Python C Extension Module โ€“ Real Python
June 27, 2023 - In this tutorial, you'll learn how to write Python interfaces in C. Find out how to invoke C functions from within Python and build Python C extension modules. You'll learn how to parse arguments, return values, and raise custom exceptions using the Python API.
๐ŸŒ
Readthedocs
reptate.readthedocs.io โ€บ developers โ€บ python_c_interface.html
Tutorial: Interfacing Python and C code โ€” RepTate 1.3.15 documentation
In our case, it is void, which translates in Python to None. See fundamental-data-types for a list of equivalence. Our C function c_square accepts three arguments: an int and two double *. Hence, our Python function python_c_square accepts three arguments too but they must by of type c_int and โ€œarray of c_doubleโ€ defined by the ctypes Python library.
๐ŸŒ
Medium
medium.com โ€บ @wansac โ€บ the-python-c-api-a-brief-introduction-7926ea0ef488
The Python/C API: A Brief Introduction | by Ashley Wans | Medium
September 14, 2020 - The Python/C API: A Brief Introduction The Python/C API brings together two of my two favorite things: Python and C. What is it? The Python/C API allows C programmers to embed Python directly into C โ€ฆ
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ using-c-codes-in-python-set-1
Using C codes in Python | Set 1 - GeeksforGeeks
July 11, 2025 - Prerequisite: How to Call a C function in Python Let's discuss the problem of accessing C code from Python. As it is very evident that many of Pythonโ€™s built-in libraries are written in C. So, to access C is a very important part of making Python talk to existing libraries.
Top answer
1 of 12
159
Python runs on an interpreter* called CPython. The interpreter takes in Python code (,compiles it into an internal representation) and runs it. CPython, as the name suggests is written in C. So, when you run a Python script like "print(5+5)", CPython, the program you usually run with the python command, reads the line, lexes it into Tokens like print, (, 5, +, 5, ) then transforms it a couple more times, until it ends up with a bytecode representation, something like: LITERAL 5, LITERAL 5, ADD, PRINT, where LITERAL pushes the number 5 onto the "stack", ADD takes the two items highest on the stack, removes them from it, and pushes their sum back onto it and PRINT removes the top item from the stack and prints it. So it works like this: INSTRUCTION: {} STACK: [] INSTRUCTION: LITERAL STACK: [5] INSTRUCTION: LITERAL STACK: [5, 5] INSTRUCTION: ADD STACK: [10] INSTRUCTION: PRINT STACK: [] stdio: "10" It's not an abstraction in C per se, as in, a C compiler can be not involved in the life of a Python program. The interpreter is compiled on someone else's computer, you can download it, and it will work without a C compiler. CPython doesn't compile Python to C, so there never is a point where your python program is a C program. *- that's the most commonly used implementation anyway
2 of 12
14
Python and C are not directly related. The official Python interpreter named CPython is written in C, but that has nothing to do with the Python language itself. Other people have written other Python interpreters in other languages.
๐ŸŒ
CodeConvert AI
codeconvert.ai โ€บ c-to-python-converter
Free C to Python Converter โ€” AI Code Translation | CodeConvert AI
Simply paste your C code into the input box and click the Convert button. Our AI will analyze your C code and produce equivalent Python code in seconds, preserving the original logic and structure.
Top answer
1 of 3
145

From everything I've seen, it's a combination of practical and historical reasons. The (mostly) historical reason is that CPython 1.0 was released in 1989. At that time, C was just recently standardized. C++ was almost unknown and decidedly non-portable, because almost nobody had a C++ compiler.

Although C++ is much more widespread and easily available today, it would still take a fair amount of work to rewrite CPython into the subset of C that's compatible with C++. By itself, that work would provide little or no real benefit.

It's a bit like Joel's blog post about starting over and doing a complete rewrite being the worst mistake a software company can make. I'd counter that by pointing to Microsoft's conversion from the Windows 3.0 core to the Windows NT core, and Apple's conversion from MacOS 9 to Mac OS/X. Neither one killed the company -- but both were definitely large, expensive, long-term projects. Both also point to something that's crucial to success: maintaining both code bases for long enough that (most) users can switch to the new code base at their leisure, based on (at least perceived) benefits.

For a development team the size of Python's, however, that kind of change is much more difficult. Even the change from Python 2 to 3 has taken quite a bit of work, and required a similar overlap. At least in that case, however, there are direct benefits to the changes, which rewriting into C++ (by itself) wouldn't (at least immediately) provide.

Linus Torvalds's rant against C++ was brought up, so I'll mention that as well. Nothing I've seen from Guido indicates that he has that sort of strong, negative feelings toward C++. About the worst I've seen him say is that teaching C++ is often a disaster -- but he immediately went on to say that this is largely because the teachers didn't/don't know C++.

I also think that while it's possible to convert a lot of C code to C++ with relative ease, that getting much real advantage from C++ requires not only quite a bit more rewriting than that, but also requires substantial re-education of most developers involved. Most well-written C++ is substantially different from well-written C to do the same things. It's not just a matter of changing malloc to new and printf to cout, by any stretch of the imagination.

2 of 3
32

I think the reason why it was originally written in ANSI C89 is quite simply because back then, C++ was just not a workable choice what with incompatibilities between different compilers and such. I mean, it took until, what was it, 2005, to come up with an ABI specification that would allow code compiled with one compiler to call code compiled with a different compiler?

The more interesting question is why it is still written in C89.

And there is a surprising answer: because people actually use Python on platforms for which no C++ and no C99 compiler exists! When the Forth-inspired threaded-code interpreter optimizations were merged, there was a huge discussion about it, because the code (necessarily) used computed goto which is not a part of C89. There were apparently real fears that this feature might not be available on some of the platforms that Python is currently used on.

The same thing happened with Unladen Swallow, wich uses LLVM, which is written in C++. It was made very clear that a requirement for merging Unladen Swallow into CPython would be that you can compile it without the JIT compiler, since there are platforms people run Python on, for which no C++ compiler exists.

Of course, nowadays, CPython is no longer the only Python implementation. There is PyPy, which is written in RPython (a statically typed subset of Python), Jython in Java, IronPython in C#, Pynie in NQP and PIR and so on.