Leanpub Header

Skip to main content

CPython 3.15 Internals

Inside the Reference Interpreter: Free-Threading, JIT, and the Evolution of Python 3.15

CPython 3.15 runs without the GIL, ships an experimental JIT, and rewrites the C API for a free-threaded world. No hand-waving. No stale docs. Just the interpreter, laid open.

Minimum price

$19.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
About

About

About the Book

CPython Internals takes you inside the reference implementation of Python 3.15, the first CPython version that can run without the Global Interpreter Lock. You'll trace the eval loop, the tier-2 JIT optimizer, the free-threading infrastructure, and the new C APIs (PyModExport, PyBytesWriter, abi3t) that change how extensions are built. Every chapter covers the build system, debugging, profiling, SSL/TLS internals, and the contributor workflow. Written against the origin/3.15 branch, fact-checked to the source, and designed for engineers who need to understand CPython, not just use it.

Author

About the Author

Abdur-Rahmaan Janhangeer

Long-time Python and Open Source specialist.

Contents

Table of Contents

Intro

Introduction to CPython

  1. 1.1 What Is CPython?
  2. 1.2 The Evolution to Version 3.15

Getting the CPython Source Code

  1. 2.1 The CPython Repository
  2. 2.2 Cloning the CPython 3.15 Source
  3. 2.3 Compiling CPython 3.15 from Source
  4. What’s next

Reading CPython Source Code Effectively

  1. 3.1: Coding Conventions and Macro‑Heavy Patterns
  2. 3.2: Navigating the Source Tree
  3. 3.3: Tracing Object Lifecycles
  4. 3.4: Debugging Crashes in CPython

The CPython Object Model

  1. 4.1 Everything Is an Object
  2. 4.2 Fundamental Data Types in Depth
  3. 4.3 The Descriptor Protocol and Attribute Lookup

Memory Management

  1. 5.1: The CPython Memory Allocator Stack
  2. 5.2: Reference Counting – In Depth
  3. 5.3: The Cyclic Garbage Collector (GC)

The Execution Model

  1. 6.1 From Source Code to Bytecode
  2. 6.2 The Frame and Execution Stack
  3. 6.3 The Bytecode Interpreter
  4. 6.4 The Two‑Tier Interpreter Architecture
  5. 6.5 Calling Conventions and Vectorcall

The Global Interpreter Lock (GIL)

  1. 7.1 What Is the GIL and Why Does It Exist?
  2. 7.2 How the GIL Works in CPython 3.15
  3. 7.3 The Free‑Threaded Build (No‑GIL)
  4. 7.4 Connecting to the Previous Chapter
  5. 7.5 Preview of the Next Chapter

Chapter 8: Subinterpreters and Isolated Execution

  1. 8.1 What Are Subinterpreters?
  2. 8.2 The PyInterpreterState and PyThreadState
  3. 8.3 Interpreter State Isolation in 3.15

The JIT Compiler in CPython 3.15

  1. 9.1 Introduction to Just‑In‑Time (JIT) Compilation
  2. 9.2 How the JIT Works in 3.15
  3. 9.3 JIT Performance in Practice

Bytecode and Optimization

  1. 10.1 Python Bytecode in 3.15
  2. 10.2 The Supercompiler and Adaptive Interpreter
  3. 10.3 Performance Tuning

I/O and Performance Optimizations

  1. 11.1 Faster I/O in CPython 3.15
  2. 11.2 Asynchronous I/O and the Event Loop

The CPython Module System

  1. 12.1: Built‑in Modules vs. Extension Modules
  2. 12.2: The Import System Internals
  3. 12.3: Loading and Initializing Extension Modules
  4. 12.4: Lazy Imports (PEP 810)
  5. End of Chapter 12

The C API

  1. 13.1 The Three API Layers
  2. 13.2 The abi3t Proposal
  3. 13.3 Module Initialization
  4. 13.4 Free‑Threading Compatibility
  5. 13.5 What Does Not Change
  6. 13.6 Vectorcall
  7. 13.7 Writing an Extension for 3.15
  8. 13.8 Testing
  9. Summary

Embedding CPython

  1. 14.1: Embedding Python in a C Application
  2. 14.2: Subinterpreters in Embedded Environments
  3. 14.3: WebAssembly and CPython 3.15

Security and SSL/TLS

  1. 15.1: SSL/TLS Enhancements in 3.15
  2. 15.2: Security Best Practices for Extensions

Debugging and Profiling CPython

  1. 16.1 Debugging with GDB
  2. 16.2 The New Statistical Profiler (PEP 799)
  3. 16.3 Tracing and Instrumentation

The Build System and Cross‑Compilation

  1. 17.1 The CPython Build System
  2. 17.2 Cross‑Compiling CPython
  3. Chapter Summary

CPython Contributor’s Workflow

  1. 18.1: Setting Up a Development Environment
  2. 18.2: Argument Clinic
  3. 18.3: Testing CPython
  4. 18.4: Continuous Integration and Buildbots
  5. 18.5: Benchmarking and Performance
  6. 18.6: Working with Generated Files

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub