#Python

117 posts

Metaclasses — when do you really need them?
7 min read

Metaclasses — when do you really need them?

Covers classes that build classes. The identity of type, the division with __init_subclass__, cases that class decorators solve, and the narrow areas where you really need a metaclass.

Modules, packages, and pyproject.toml
8 min read

Modules, packages, and pyproject.toml

The import system, the difference between modules and packages, __init__.py and __main__, and pyproject.toml as the single home for dependencies, tool settings, and publishing.

Pattern matching in depth
8 min read

Pattern matching in depth

The next step from basics match-case — class patterns and __match_args__, sequence/mapping patterns, captures and guards, and the antipatterns to avoid.

Performance — cProfile, py-spy, memory profiling
9 min read

Performance — cProfile, py-spy, memory profiling

The toolbox for finding and fixing slow Python code — timeit, cProfile, py-spy, line_profiler, memray, and common optimization patterns.

Publishing a library with uv — pyproject.toml and shipping to PyPI
9 min read

Publishing a library with uv — pyproject.toml and shipping to PyPI

Pin down what pyproject.toml means in one pass, then publish your first library to PyPI with uv build · uv publish.

Pydantic v2 in depth — validation, serialization, custom validators
13 min read

Pydantic v2 in depth — validation, serialization, custom validators

A dedicated deep dive on Pydantic, the core of FastAPI. v2's performance and API changes, the right places to use model_validator/field_validator, serialization control, and JSON Schema generation.

Python Automation #4: Web Scraping Part 2 — Dynamic Pages with Playwright
5 min read

Python Automation #4: Web Scraping Part 2 — Dynamic Pages with Playwright

Handle JavaScript-rendered pages that return empty HTML to requests by driving a real browser with Playwright. From install and a first script to wait_for_selector, login automation, infinite scroll, and saving to CSV — all in one pass.

Routing, Pydantic models, and dependency injection
8 min read

Routing, Pydantic models, and dependency injection

Splitting routes with APIRouter, defining input/output schemas with Pydantic v2, and factoring shared logic out with Depends.

Testing and deploy — pytest, Docker, Railway/Fly
9 min read

Testing and deploy — pytest, Docker, Railway/Fly

FastAPI integration tests with pytest + httpx, isolation via dependency overrides, multi-stage Docker builds, and cloud deployment on Railway/Fly.

Type checker setup and CI integration
9 min read

Type checker setup and CI integration

mypy/pyright/ruff configuration and how to avoid conflicts, blocking issues locally with pre-commit, then blocking them at the PR stage with GitHub Actions.

typing in earnest — Generic, Protocol, TypedDict, Literal
9 min read

typing in earnest — Generic, Protocol, TypedDict, Literal

The next step from basics type hints — Generic for parameterizing types, Protocol for precise duck typing, TypedDict for dict shapes, and Literal for narrow unions.

Variables, basic types, and type hints
9 min read

Variables, basic types, and type hints

Python is a dynamic language, but modern Python writes types from the start. int/str/bool/None and built-in generics, the int | None shortcut, and mypy/pyright.