Cheat sheets

Fast references

Thirty focused cheat sheets covering the language, the standard library and the production toolchain.

Python syntaxData typesString methodsList methodsDictionary methodsSet methodsComprehensionsFunctionsScope & LEGBOOPMagic methodsIteratorsGeneratorsDecoratorsContext managersExceptionsType hintsAsyncIOThreadingMultiprocessingTesting / PytestFastAPISQLAlchemyPydanticLoggingPerformanceSecurityProject structureInterview checklistProduction checklist

Featured

Comprehensions

python
squares = [x*x for x in range(10)]
evens   = [x for x in nums if x % 2 == 0]
pairs   = {k: v for k, v in items}
unique  = {x % 3 for x in nums}
gen     = (x*x for x in range(10))   # lazy generator

Dict essentials

python
d.get(key, default)         # safe lookup
d.setdefault(key, [])       # get-or-create
d |= other                  # merge (3.9+)
for k, v in d.items(): ...
from collections import Counter, defaultdict

Async basics

python
import asyncio

async def main():
    async with asyncio.TaskGroup() as tg:   # 3.11+
        tg.create_task(work(1))
        tg.create_task(work(2))

asyncio.run(main())

Pytest

python
import pytest

@pytest.fixture
def client(): ...

@pytest.mark.parametrize("a,b,exp", [(1,2,3),(2,2,4)])
def test_add(a, b, exp):
    assert add(a, b) == exp

def test_raises():
    with pytest.raises(ValueError):
        parse("nope")

Tooling & versions

Version-sensitive facts live in editable metadata (not hard-coded into lessons). Last verified against upstream release pages on the dates shown.

PackageStableMinPythonVerified
Python (CPython)Language3.13.x3.102026-07-21
FastAPIBackend0.115.x0.110>=3.82026-07-21
PydanticValidation2.x2.0>=3.82026-07-21
SQLAlchemyDatabase2.x2.0>=3.82026-07-21
AlembicDatabase1.14.x1.12>=3.82026-07-21
PostgreSQLDatabase17.x142026-07-21
RedisCache/Store7.x6.22026-07-21
pytestTesting8.x7.4>=3.82026-07-21
RuffTooling0.7.x0.5>=3.72026-07-21
mypyTooling1.13.x1.8>=3.82026-07-21
uvTooling0.5.x0.4>=3.82026-07-21
httpxHTTP0.28.x0.27>=3.82026-07-21
Docker EngineDevOps27.x242026-07-21
NumPyData Science2.x1.26>=3.102026-07-21
pandasData Science2.x2.1>=3.92026-07-21
scikit-learnMachine Learning1.5.x1.3>=3.92026-07-21
PyTorchMachine Learning2.x2.1>=3.92026-07-21