Understand CPython
Learning Path ⋅ Skills: Python, Pointers, Memory Management, Profiling, CPython Source Code, C Extensions, Python Bindings, Memory Mapping
In this learning path, you’ll look under the hood of Python’s reference implementation, CPython. You’ll start with how Python handles pointers and memory, then learn to time and profile your code. From there, you’ll explore the CPython source code, build C extensions, create Python bindings, and work with memory-mapped file I/O.
Understand CPython
Learning Path ⋅ 8 Resources
Python Objects and Memory
CPython represents every value as a C-level object on the heap, so that is where a tour of the internals starts. You’ll see why Python’s names behave like pointers to those objects, and how the memory manager hands out and reclaims space in pools, blocks, and arenas. Everything later in this path builds on that object model.
Course
Pointers and Objects in Python
Learn about Python's object model and see why pointers don't really exist in Python. You'll also cover ways to simulate pointers in Python without managing memory.
Course
How Python Manages Memory
Get ready for a deep dive into the internals of Python to understand how it handles memory management. By the end of this course, you’ll know more about low-level computing, understand how Python abstracts lower-level operations, and find out about Python’s internal memory management algorithms.
Interactive Quiz
Memory Management in Python
Performance
You’ve seen how CPython stores objects and manages memory. Next, you’ll measure what that costs at runtime, using timer functions and profiling tools to find the bottlenecks in your code. Knowing where the time actually goes tells you which parts are worth pushing down into C.
Course
Python Timer Functions
Learn how to time your Python code with the time module, then build a reusable Timer class that works as a context manager.
Course
Profiling Performance in Python
Learn to profile Python programs with built-in and popular third-party tools, and turn performance insights into faster code.
Interactive Quiz
Profiling Performance in Python
CPython Internals
Profiling shows you where your code is slow, but fixing it sometimes means going below Python. Now you’ll read the CPython source code itself, build C extension modules, write Python bindings for existing C libraries, and use memory-mapped file I/O to work with large files without loading them fully into memory.
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.
Interactive Quiz
Your Guide to the CPython Source Code
Tutorial
Building a Python C Extension Module
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.
Tutorial
Python Bindings: Calling C or C++ From Python
What are Python bindings? Should you use ctypes, CFFI, or a different tool? In this step-by-step tutorial, you'll get an overview of some of the options you can use to call C or C++ code from Python.
Course
Python mmap: Doing File I/O With Memory Mapping
Learn how to use Python's mmap module to improve your code's performance when you're working with files. You'll get a quick overview of the different types of memory before diving into how and why memory mapping with mmap can make your file I/O operations faster.
Congratulations on completing this learning path! You’ve explored CPython’s internals, from memory management and profiling to C extensions and memory mapping.
Continue your advanced Python journey with the next learning path:
Learning Path
Ace Your Python Coding Interview
8 Resources ⋅ Skills: Coding Interviews, Practice Problems, CSV Parsing, Data Engineering, Python Books, PyCon Talks, Interview Preparation, Coding Challenges, Learning Roadmaps
You might also be interested in these related learning paths:
Got feedback on this learning path?
Looking for real-time conversation? Visit the Real Python Community Chat or join the next “Office Hours” Live Q&A Session. Happy Pythoning!