Python Reference
|
This section documents the current Python release line as published at the official Python documentation, which is the reference these pages are written and verified against. No specific patch version is pinned. This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. This section’s bibliography lists the reference material consulted while preparing these pages. |
Welcome to the Python reference. Python is a high-level, dynamically-typed, multi-paradigm language — it supports procedural, object-oriented, and functional styles, is interpreted (compiled to bytecode and run on the Python Virtual Machine), and favours readable, indentation-based syntax over explicit braces. This section documents the current Python release line, framework-agnostic, written and verified against the official Python documentation.
If you are new to Python, read Getting Started with Python first, then Lexical Structure and Style and Variables and Dynamic Typing, followed by Control Flow — from there the core-language pages build on each other through functions, iteration, modules, files, and exceptions, and the later pages cover object-oriented Python, modern standard-library features, and testing.
Where Python is used on this site: Python FastAPI builds HTTP APIs on top of this language reference, and the GraphQL section’s Python pages serve GraphQL from Python, and Django (in Web Development) builds full web applications and APIs with the batteries-included Python web framework. The Backend Development section also covers Python Flask (the WSGI micro-framework), Python Tornado (asynchronous networking and non-blocking web servers) and Python Pyramid (configurable WSGI applications with URL dispatch and traversal).
What’s covered
Building a command-line tool in Python that people, scripts and AI agents can all drive? See Python CLI Frameworks for argparse, Click, Typer, Rich and Textual.
Getting started
-
Getting Started with Python — installing Python, the interpreter (script mode vs. the interactive REPL), editors and IDEs, and the source-to-bytecode-to-PVM execution model.
-
Python IDEs & Tools — the IDEs, editors and notebook tools commonly used for Python.
Core language
-
Lexical Structure and Style — indentation-based blocks, comments and statement separators, PEP 8 naming and style, and the Zen of Python.
-
Variables and Dynamic Typing — names bound to objects, mutability, shared references and
isvs.==, and the built-in type hierarchy. -
Numbers —
int/float/complex, numeric operators,decimal/fractionsfor exact arithmetic, and the built-in numeric tools. -
Strings and Text — string literals and slicing, common string methods, f-strings and other formatting, and
strvs.bytes. -
Collections — lists, tuples, sets, and dictionaries, their comprehensions, and when to choose each.
-
Control Flow —
if/elif/elseand truthiness,while/forloops, and thematchstatement. -
Functions — parameters and return values,
args/*kwargsand positional-/keyword-only markers, the LEGB scope rule, andlambda. -
Iterators, Generators and Comprehensions — the iterator protocol, generator functions and expressions, and comprehensions revisited as sugar over iteration.
-
Modules and Packages —
importforms, thename == "main"pattern, packages, and the module search path. -
Files and Context Managers —
open()and thewithstatement, andpathlib.Pathas the modern alternative toos.path. -
Exceptions —
try/except/else/finally, exception chaining, custom exception hierarchies, and exception groups.
Object-oriented programming
-
Classes and Objects —
classbasics, instance vs. class attributes,@staticmethod/@classmethod, and inheritance withsuper(). -
Operator Overloading — the common dunder methods for display, comparison, container behaviour, calling, context management, and arithmetic.
-
Advanced OOP Design — composition vs. inheritance, mixins and multiple inheritance, the Method Resolution Order, and delegation.
-
Managed Attributes —
@property, the descriptor protocol, andgetattrvs.getattribute. -
Decorators and Metaclasses — function decorators, decorator factories and stacking, and a brief, cautious look at metaclasses.
Modern Python & standard library
-
Type Hints — basic annotations, generics and the modern
X | Nonesyntax,TypeVar/Protocol, and static checkers. -
Dataclasses and Enums —
@dataclassand its generated methods, andenum.Enum/IntEnum/Flag. -
Standard Library Tour — filesystem/OS, data, math and random, and CLI/observability modules.
-
Concurrency and Async —
threading,multiprocessingandconcurrent.futures, andasyncio. -
Virtual Environments and Packaging —
venv,pip, andpyproject.toml. -
Debugging and Tooling —
pdb,timeit/cProfile, and linters and formatters. -
Docstrings — what docstrings are, common style conventions (Google, NumPy, reST, Epytext), and generating static documentation sites with Sphinx, pdoc, and MkDocs.
Build automation, packaging and publishing
-
Build Automation Tools (pip & Poetry) — the shared concepts: packaging standards,
pyproject.toml, version specifiers, environments, lock files, supply-chain security, CI caching and containers, and choosing between pip and Poetry. -
pip — the standard installer from installation to resolution, indexes, configuration, hash-checked installs,
pip lockand troubleshooting. -
Poetry — dependency management and packaging with Poetry 2, from installation and
poetry.lockto plugins, configuration and the migration from 1.x. -
Publishing & Distributing Libraries — preparing, versioning, building, checking and publishing a library to PyPI and private indexes, with Trusted Publishing and attestations.
Testing & reference
-
Unit Testing with pytest & Mocking — test discovery, fixtures, parametrization, and mocking with
unittest.mockandmonkeypatch. -
Cheat Sheet (PDF) — a single-page, printable summary of everything in this section, with a downloadable PDF.
Bibliography
-
docs.python.org/3 — the official Python 3 documentation, the source every page in this section is written and verified against; see in particular the tutorial, the language reference, the library reference, and the HOWTOs.
-
python.org — downloads, community, and the documentation hub.
-
PEP 8 — the official style guide, for the lexical structure/style page.
-
pytest’s official documentation — the primary source for the unit-testing page.
-
Lee, Kent D. Python Programming Fundamentals, 2nd ed. Springer (Undergraduate Topics in Computer Science), 2015 (ISBN 978-1-4471-6641-2 print / 978-1-4471-6642-9 eBook). Consulted as part of the bibliography for this section (predates the current Python release line; not the primary or main reference) — see the publisher’s book page and springer.com.
-
Matthes, Eric. Python Crash Course, 3rd ed. No Starch Press, 2023. ISBN-13: 978-1-7185-0270-3 (print) / 978-1-7185-0271-0 (ebook). Consulted as part of the bibliography for this section (predates the current Python release line; not the primary or main reference) — see the publisher’s book page and nostarch.com.
-
Lutz, Mark. Learning Python, 4th ed. O’Reilly Media, 2009. ISBN 978-0-596-15806-4. Consulted as part of the bibliography for this section (predates Python 3.1; no coverage of f-strings, type hints,
pathlib,dataclasses,async/await, thematchstatement, orpytest/mocking) — see the publisher’s book page and oreilly.com.
Build automation, packaging and publishing
The sources of the Build Automation Tools sub-section. Each page lists
the subset it derives from under its own == References.
pip
-
pip documentation — getting started, installation, user guide, topic guides, reference and CLI pages; changelog and release process.
-
pip source code — for the exact error messages.
Poetry
-
Poetry documentation — every page; history; blog (the release posts for 1.2.0 to 2.5.0).
-
poetry-core; the installer install.python-poetry.org and its repository.
-
Plugins: poetry-plugin-export, poetry-plugin-shell, poetry-plugin-bundle.
-
Poetry source code — for the lock file format and exact error messages.
Python Packaging Authority standards
-
Python Packaging User Guide — tutorials, guides, discussions, specifications and key projects.
-
PEPs: 427 (wheel format), 440 (versions), 503 (simple repository API), 508 (dependency specifiers), 517 (build backends), 518 (build requirements), 592 (yanking), 610 (direct URL origin), 621 (project metadata), 625 (sdist file names), 639 (license metadata), 643 (sdist metadata), 658 (metadata in the simple API), 660 (editable installs), 668 (externally managed environments), 685 (extra names), 691 (JSON simple API), 723 (inline script metadata), 735 (dependency groups), 740 (attestations), 751 (
pylock.toml), 770 (SBOMs), 792 (project status markers), 794 (import name metadata), 808 (static values in dynamic metadata) and 833 (freezing the HTML simple API); also 561, 600 and 803 where pages use them.
PyPI
-
PyPI documentation — trusted publishers, attestations, publishing, project management, account and API pages; PyPI help; PyPI blog (the posts cited); TestPyPI.
Building and publishing tools
Specifications and standards
Third-party tools (not PyPA or Poetry projects)
-
uv, pip-tools, pipx, virtualenv, PDM, Pipenv, tox, nox, nox-poetry, pre-commit, pip-audit, check-wheel-contents, hynek/build-and-inspect-python-package.
-
Indexes and registries: pypiserver, devpi, Sonatype Nexus, JFrog Artifactory, AWS CodeArtifact, Azure Artifacts, Google Artifact Registry, conda-forge.
No books were used for this sub-section.