guide 03 / 08

What Is CPython Used For? Real-World Uses and Examples

What is CPython used for? From running scripts and web apps to data science, automation and C extensions, see where the standard Python interpreter fits.

Bytecode-style illustration for: What is CPython used for?

TL;DR

  • CPython runs nearly all everyday Python code: scripts, web apps, data work and automation.
  • It is the platform C extensions such as NumPy are built for.
  • Developers also use its source to learn interpreter internals and to test upcoming releases.
  • It is embedded inside other applications as a scripting engine.

01Running Python programs, everywhere

The main use of CPython is simple: it runs Python code. Every time someone types python app.py, opens a Jupyter notebook or starts a Django server with the standard interpreter, CPython does the work. It compiles source to bytecode and executes it in its evaluation loop.

02Common real-world uses

AreaTypical toolsCPython's role
Web backendsDjango, Flask, FastAPIRuns the application server code
Data science & AINumPy, pandas, PyTorchHosts C/C++ extensions through its C API
Automation & DevOpsScripts, Ansible, CLI toolsShips with many Linux distributions
EducationIDLE, REPL, ThonnyThe default interpreter taught in courses
Testingpytest, unittestRuns test suites in CI pipelines
EmbeddingBlender, GIMP, game enginesEmbedded as a scripting language inside apps

03A simple CPython example

This small program uses only the standard library that ships with CPython:

import json, statistics
from pathlib import Path

scores = [72, 88, 95, 61, 84]
report = {"mean": statistics.mean(scores), "best": max(scores)}
Path("report.json").write_text(json.dumps(report, indent=2))
print(report)

Run it with python3 report.py. CPython compiles it to bytecode (cached in __pycache__ for imported modules) and executes it. No third-party packages are needed.

04Building and loading C extensions

CPython's C API is why Python dominates scientific computing. Libraries put their heavy math in C, C++, Rust or Fortran and expose it as a Python module. NumPy arrays, pandas DataFrames and most machine-learning frameworks rely on this. Tools such as Cython, pybind11 and PyO3 make writing these extensions easier, and all of them target CPython.

05Embedding Python in other software

Applications can link against CPython and use it as an internal scripting engine. Blender's add-on system is a well-known example. The C API provides functions to initialize the interpreter, run code and exchange objects with the host program.

06Studying and contributing

Because CPython is open source, its code is also a learning resource. Developers read Python/ceval.c to understand bytecode execution, or Objects/dictobject.c to see how dictionaries work. Others build the main branch to test their libraries against the next release before it ships every October.

07CPython in teaching and research

Universities and online courses teach Python with CPython because it is free, installs easily and behaves the way textbooks describe. Researchers use it to glue together simulations, data analysis and plotting, often calling fast native libraries through the C API. Notebook tools such as Jupyter run a CPython kernel by default, so a large share of scientific work happens on CPython even when the heavy number crunching happens in compiled code.

For learners curious about computer science, CPython is also a textbook example of a real interpreter: a tokenizer, a parser, a compiler and a virtual machine, all in one readable open-source codebase.

08CPython in the operating system

Many Linux distributions ship CPython as part of the base system and use it for package management helpers, system tools and installers. That's why you shouldn't overwrite or remove the system python3. Install your own version alongside it with make altinstall, a version manager or a virtual environment.

09Who doesn't need to think about it

If you just write scripts or apps, you can use CPython without ever thinking about it, because it comes with your Python install. See Do I need CPython? for a quick decision guide.

??Quick questions

Q01Is CPython used in production?

Yes. It is the standard runtime for production Python web services, data pipelines and tools.

Q02Can CPython be embedded in other programs?

Yes. The C API lets applications embed the interpreter as a scripting engine.