A high-signal reference for Python 3 — language model, data types, OOP, async, performance patterns, standard library, and packaging. From syntax fundamentals to production-grade idioms.
Dynamically typed, garbage-collected, interpreted language with a vast standard library and ecosystem. Philosophy: readability counts, explicit is better than implicit.
type(x) always valid.py → CPython compiles to .pyc bytecode → executed by PVM (Python Virtual Machine). No AOT compile step; JIT available via PyPy.How CPython transforms source code to execution — and the role of the GIL, memory manager, and import system.
.py file → tokenizer → AST (Abstract Syntax Tree) → ast.parse() → inspectable at runtime.pyc in __pycache__) → inspectable with dis.dis()int pool, float pool) → refcount + gc for cycle detectionimport → checks sys.modules cache first → searches sys.path → built-ins → frozen → .pth → site-packages.so/.pyd) loaded via ctypes / cffi / CPython C API. NumPy, pandas, cryptography etc. bypass PVM for hot loops — GIL released during I/O & C codethreading for I/O-bound; multiprocessing for CPU-bound (separate GIL per process).await suspends coroutine, loop runs next ready task. Best for high-concurrency I/O (network, DB).Fundamental constructs — control flow, functions, comprehensions, generators, decorators, and type annotations.
Python's object model — every value is an object with identity, type, and value. Dunder methods wire user classes into the language's core protocols.
super() · @classmethod · @staticmethod · @property · ABC via abc.abstractmethod · slots (__slots__) reduce memory ~40%
CPython overhead, data structure complexities, and profiling targets. Know these before optimising.
cProfile — call counts + cumtime · line_profiler — line-level · memory_profiler — RAM per line · timeit — micro-benchmarks · py-spy — sampling profiler (production-safe)
__slots__ → switch to Cython/Numba for hot loops
Package setup with modern tooling and a production error-handling / logging pattern.
python -m venv .venv or uv venv. Activate: source .venv/bin/activate. Pin deps with uv pip compile.pyproject.toml (PEP 517/518). Use hatchling, flit, or setuptools as build backend. Add [project.scripts] for CLI entry points.ruff (replaces flake8+isort+pyupgrade), black for formatting, mypy or pyright for type checking. Pre-commit hooks enforce on commit.pytest with coverage.py. Target ≥ 80% coverage. Publish: python -m build → twine upload → PyPI.ValueError, KeyError). Never bare except:. Use except Exception as e + raise ... from e for chaining.logging.basicConfig(level=INFO) in __main__. Modules use logger = logging.getLogger(__name__). Never print() in library code.with open(...), DB sessions, locks. Implement __enter__/__exit__ or use @contextlib.contextmanager.dataclass / Pydantic model). Use sys.exit(1) on fatal CLI errors after logging the cause.The "batteries included" stdlib — reach for these before installing third-party packages.
Quick-reference cards — data type sizes, built-in functions, operator precedence, f-string formats, pytest patterns, and packaging commands.