# python/cpython architecture

> Architecture diagram of the GitHub repository python/cpython, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/python/cpython
- Repository: https://github.com/python/cpython

## Overview

CPython is the reference Python interpreter and its standard library. The principal workflow starts when a user invokes the interpreter: its native entry point selects startup, script, or interactive behavior, with an interactive route into the Python REPL. The wider runtime provides core language services and standard-library capabilities such as I/O, networking, concurrency, and data handling. Edges below are limited to calls visible in excerpts or dependencies named by the SOURCE INDEX; unsampled runtime internals are not expanded into an assumed pipeline.

Main entry points: [`Lib/os.py`](https://github.com/python/cpython/blob/main/Lib/os.py) (OS interface), [`Lib/email/message.py`](https://github.com/python/cpython/blob/main/Lib/email/message.py) (Email messages), [`Lib/http/server.py`](https://github.com/python/cpython/blob/main/Lib/http/server.py) (HTTP server), [`Lib/xmlrpc/server.py`](https://github.com/python/cpython/blob/main/Lib/xmlrpc/server.py) (XML-RPC server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Interpreter runtime"]
  node_entry["Interpreter entry<br/>[main.c]"]
  node_repl["Interactive REPL<br/>[main.py]"]
end

subgraph group_corelib["Core libraries"]
  node_os["OS interface<br/>[os.py]"]
  node_io["Stream I/O<br/>[io.py]"]
  node_warnings["Warnings<br/>[warnings.py]"]
  node_types["Type utilities<br/>[types.py]"]
  node_argparse["CLI parsing<br/>[argparse.py]"]
end

subgraph group_network["Networking"]
  node_httpclient["HTTP client<br/>[client.py]"]
  node_httpserver["HTTP server<br/>[server.py]"]
  node_xmlrpc["XML-RPC server<br/>[server.py]"]
end

subgraph group_concurrency["Concurrency"]
  node_asyncio["Async tasks<br/>[tasks.py]"]
  node_managers["Shared-object managers<br/>[managers.py]"]
end

subgraph group_data["Data and utilities"]
  node_regex["Regular expressions<br/>[__init__.py]"]
  node_email["Email messages<br/>[message.py]"]
  node_emailcharset["Email charsets<br/>[charset.py]"]
  node_inspect["Object introspection<br/>[inspect.py]"]
  node_traceback["Traceback formatting<br/>[traceback.py]"]
  node_functools["Function utilities<br/>[functools.py]"]
  node_unittest["Test runner<br/>[main.py]"]
end

node_user(("Python user"))

node_user -->|"invokes"| node_entry
node_entry -->|"starts interactive"| node_repl
node_entry -->|"imports"| node_os
node_repl -->|"imports"| node_os
node_httpserver -->|"imports"| node_httpclient
node_httpserver -->|"imports"| node_os
node_httpserver -->|"imports"| node_argparse
node_xmlrpc -->|"imports"| node_httpserver
node_xmlrpc -->|"imports"| node_inspect
node_xmlrpc -->|"imports"| node_traceback
node_asyncio -->|"imports"| node_types
node_managers -->|"imports"| node_os
node_email -->|"imports"| node_io
node_email -->|"imports"| node_emailcharset
node_email -->|"imports"| node_regex
node_email -->|"imports"| node_functools
node_unittest -->|"imports"| node_argparse
node_unittest -->|"imports"| node_os
node_warnings -->|"used by"| node_os

click node_entry "https://github.com/python/cpython/blob/main/Modules/main.c"
click node_repl "https://github.com/python/cpython/blob/main/Lib/_pyrepl/main.py"
click node_os "https://github.com/python/cpython/blob/main/Lib/os.py"
click node_io "https://github.com/python/cpython/blob/main/Lib/io.py"
click node_warnings "https://github.com/python/cpython/blob/main/Lib/warnings.py"
click node_types "https://github.com/python/cpython/blob/main/Lib/types.py"
click node_argparse "https://github.com/python/cpython/blob/main/Lib/argparse.py"
click node_httpclient "https://github.com/python/cpython/blob/main/Lib/http/client.py"
click node_httpserver "https://github.com/python/cpython/blob/main/Lib/http/server.py"
click node_xmlrpc "https://github.com/python/cpython/blob/main/Lib/xmlrpc/server.py"
click node_asyncio "https://github.com/python/cpython/blob/main/Lib/asyncio/tasks.py"
click node_managers "https://github.com/python/cpython/blob/main/Lib/multiprocessing/managers.py"
click node_regex "https://github.com/python/cpython/blob/main/Lib/re/__init__.py"
click node_email "https://github.com/python/cpython/blob/main/Lib/email/message.py"
click node_emailcharset "https://github.com/python/cpython/blob/main/Lib/email/charset.py"
click node_inspect "https://github.com/python/cpython/blob/main/Lib/inspect.py"
click node_traceback "https://github.com/python/cpython/blob/main/Lib/traceback.py"
click node_functools "https://github.com/python/cpython/blob/main/Lib/functools.py"
click node_unittest "https://github.com/python/cpython/blob/main/Lib/unittest/main.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_repl,node_user toneBlue
class node_os,node_io,node_warnings,node_types,node_argparse toneAmber
class node_httpclient,node_httpserver,node_xmlrpc toneMint
class node_asyncio,node_managers toneRose
class node_regex,node_email,node_emailcharset,node_inspect,node_traceback,node_functools,node_unittest toneIndigo
```

## Components

### Interpreter runtime

- [Interpreter entry](https://github.com/python/cpython/blob/main/Modules/main.c): `Modules/main.c`
- [Interactive REPL](https://github.com/python/cpython/blob/main/Lib/_pyrepl/main.py): `Lib/_pyrepl/main.py`

### Core libraries

- [OS interface](https://github.com/python/cpython/blob/main/Lib/os.py): `Lib/os.py`
- [Stream I/O](https://github.com/python/cpython/blob/main/Lib/io.py): `Lib/io.py`
- [Warnings](https://github.com/python/cpython/blob/main/Lib/warnings.py): `Lib/warnings.py`
- [Type utilities](https://github.com/python/cpython/blob/main/Lib/types.py): `Lib/types.py`
- [CLI parsing](https://github.com/python/cpython/blob/main/Lib/argparse.py): `Lib/argparse.py`

### Networking

- [HTTP client](https://github.com/python/cpython/blob/main/Lib/http/client.py): `Lib/http/client.py`
- [HTTP server](https://github.com/python/cpython/blob/main/Lib/http/server.py): `Lib/http/server.py`
- [XML-RPC server](https://github.com/python/cpython/blob/main/Lib/xmlrpc/server.py): `Lib/xmlrpc/server.py`

### Concurrency

- [Async tasks](https://github.com/python/cpython/blob/main/Lib/asyncio/tasks.py): `Lib/asyncio/tasks.py`
- [Shared-object managers](https://github.com/python/cpython/blob/main/Lib/multiprocessing/managers.py): `Lib/multiprocessing/managers.py`

### Data and utilities

- [Regular expressions](https://github.com/python/cpython/blob/main/Lib/re/__init__.py): `Lib/re/__init__.py`
- [Email messages](https://github.com/python/cpython/blob/main/Lib/email/message.py): `Lib/email/message.py`
- [Email charsets](https://github.com/python/cpython/blob/main/Lib/email/charset.py): `Lib/email/charset.py`
- [Object introspection](https://github.com/python/cpython/blob/main/Lib/inspect.py): `Lib/inspect.py`
- [Traceback formatting](https://github.com/python/cpython/blob/main/Lib/traceback.py): `Lib/traceback.py`
- [Function utilities](https://github.com/python/cpython/blob/main/Lib/functools.py): `Lib/functools.py`
- [Test runner](https://github.com/python/cpython/blob/main/Lib/unittest/main.py): `Lib/unittest/main.py`

### Other components

- **Python user**

## Connections

- Python user → Interpreter entry: invokes (evidence: `README.rst`)
- Interpreter entry → Interactive REPL: starts interactive (evidence: `Modules/main.c`)
- Interpreter entry → OS interface: imports (evidence: `Modules/main.c`)
- Interactive REPL → OS interface: imports (evidence: `Lib/_pyrepl/main.py`)
- HTTP server → HTTP client: imports (evidence: `Lib/http/server.py`)
- HTTP server → OS interface: imports (evidence: `Lib/http/server.py`)
- HTTP server → CLI parsing: imports (evidence: `Lib/http/server.py`)
- XML-RPC server → HTTP server: imports (evidence: `Lib/xmlrpc/server.py`)
- XML-RPC server → Object introspection: imports (evidence: `Lib/xmlrpc/server.py`)
- XML-RPC server → Traceback formatting: imports (evidence: `Lib/xmlrpc/server.py`)
- Async tasks → Type utilities: imports (evidence: `Lib/asyncio/tasks.py`)
- Shared-object managers → OS interface: imports (evidence: `Lib/multiprocessing/managers.py`)
- Email messages → Stream I/O: imports (evidence: `Lib/email/message.py`)
- Email messages → Email charsets: imports (evidence: `Lib/email/message.py`)
- Email messages → Regular expressions: imports (evidence: `Lib/email/message.py`)
- Email messages → Function utilities: imports
- Test runner → CLI parsing: imports (evidence: `Lib/unittest/main.py`)
- Test runner → OS interface: imports (evidence: `Lib/unittest/main.py`)
- Warnings → OS interface: used by (evidence: `Lib/os.py`)
