CPython
CPython is the reference and official implementation of the Python programming language. Written in C, it is the most widely used version of Python and serves as the standard upon which other implementations are based.
When you download Python from the official website, python.org, you’re getting CPython. This implementation is known for its performance and compatibility with various C libraries, making it a popular choice for many Python developers.
Example
Once you install Python from the python.org website, you can run the python
command on a terminal window. Then, you’ll get something like the following on your screen:
Python 3.12.2 (main, Mar 10 2024, 19:25:46)...
Type "help", "copyright", "credits" or "license" for more information.
>>>
This is a Python REPL (Read-Eval-Print Loop) session where you can run Python code interactively. You can check the Python implementation you’re using by running the following code:
>>> import platform
>>> platform.python_implementation()
'CPython'
In this code, you call the python_implementation()
function from the platform
module to check the Python implementation in use.
Note: There are several alternative Python implementations. Some of the most popular include the following:
PyPy
: An implementation written in Python.Jython
: The Python implementation on the Java platform.IronPython
: The Python implementation on the .NET framework.
Related Resources
Tutorial
Your Guide to the CPython Source Code
In this detailed Python tutorial, you'll explore the CPython source code. By following this step-by-step walkthrough, you'll take a deep dive into how the CPython compiler works and how your Python code gets executed.
For additional information on related topics, take a look at the following resources:
- CPython Internals: Paperback Now Available! (Tutorial)
- PyPy: Faster Python With Minimal Effort (Tutorial)