Modern Python: From Basics to FastAPI in Production
Python 3.14 + uv + Type Hints First — One Book Cover to Cover
All 34 chapters, including Appendix A, are available to read on the site right now. Start from any chapter — the “Where to start” section below points you to an entry point that fits your background.
What this book covers #
- The current Python standard workflow — one tool, uv, unifies environments, packages, and execution in place of pip + venv + pyenv. Everything is organized around
pyproject.toml. - Type hints first — every example carries type hints alongside the code. You get the help of mypy / pyright from the start as a default habit.
- A connected path from fundamentals to production — variables, FastAPI, SQLAlchemy, JWT auth, and deployment are introduced as parts of one practical service-building flow.
- The operational work is included — logging, observability, testing, CI, and library publishing are covered in the later chapters as part of real project work.
What this book does not cover #
- Domain applications such as data analysis / ML / games / GUI — separate books cover those.
- A complete tour of the standard library — only the top 30 in the appendix.
- 2017-style code (Python 2 compatibility,
%strings,dict.has_key, etc.) — the old Python Basics tutorial (21 parts) is still up.
Who this book is for #
- People learning Python for the first time — beginners who want to learn with current tools and syntax. You start on the modern stack from the very beginning.
- People who know old Python but not the modern workflow — those who learned during the 2.7 ~ 3.5 era and stopped there. The appendix’s migration guide for old code is the entry point.
- People coming to Python from another language — you can skim Part 1 and absorb the core from Parts 2 ~ 5. The type-hints-first approach lowers the entry barrier.
Where to start #
All 34 chapters are free to read in any order, but if you are not sure where to begin, here are three recommended entry points.
- Chapter 1: Getting Started and uv Setup — the starting line of the book. Instead of the 2017-era pip + venv, you unify environments, packages, and execution with a single tool, uv. The first chapter most beginners should open.
- Chapter 2: Variables, Basic Types, and Type Hints — the chapter where you build the “type-hints-first” identity of this book from the very start. The most direct entry point for anyone curious about the modern Python flow.
- Appendix A: Migrating Old Python Code — a guide to moving Python 2-compatible code,
%strings, and pip + venv over to the 3.14 + uv + type-hints style. The chapter where readers coming from old Python get the most value.
Each of these three serves as an entry point in its own right. Open whichever appeals to you first.
The series this book is built from #
This book is built from the four series below (27 parts total) + 7 new chapters + a full revision pass. The source series are still up on the site for free.
- Modern Python Basics (7 parts)
- Modern Python Intermediate (7 parts)
- Modern Python Advanced (7 parts)
- Modern Python in Practice — FastAPI (6 parts)
The book reorganizes the series above into a path from fundamentals to production, then adds chapters on operations, testing, and a capstone project to make it work as one complete book.
How this book is funded #
This book is funded by site ads (AdSense) and reader support. There is no purchase flow, and all 34 chapters are open to read on the site.
If a chapter helps you, you can support the book on Ko-fi. Reader support is what makes the time for the next minor revisions and the next book.
Frequently asked questions #
What do I need for the learning environment #
Python 3.14 or later, uv, and one code editor are enough. The Part 4 FastAPI chapters use only SQLite and deployment services that fit within free tiers. No step in the book requires a payment.
Where can I get the book’s code #
Each chapter’s example code is written directly in the body as code blocks, so we recommend typing it out by hand as you learn. The finished version of the Part 4 capstone TODO API will be provided separately as a GitHub repository. We will add the link to this book page once it is ready.
Will the book be obsolete when the next Python version ships #
The core model (the uv workflow, type-hints-first, dataclass · Protocol, asyncio, FastAPI + Pydantic v2) should hold for at least the next 2 ~ 3 years of releases. Changed syntax and library APIs are folded into minor revisions (e.g., v1.1), and once larger changes accumulate, a v2 book line can start separately.
Can I read this in languages other than English #
Korean, Japanese, and English are all published with the same 34-chapter structure. You can read each from its own book page.
Isn’t a chapter more than 70 % the same as a post on the site #
Some chapters share a topic with the source series posts. But each book chapter is rewritten — (1) re-narrated to fit the book’s flow, (2) unified to the Python 3.14 + uv + type-hints baseline, (3) cross-linked with other chapters in the book, and (4) given exercises and a one-line summary — so even on the same topic the result reads as different material. The 7 new chapters and Appendix A are not in the source series.
How do I send support or feedback #
Feedback is welcome through blog comments or email. Typos, improvement suggestions, and code error reports per chapter are folded quickly into the next minor revision. Support runs through the Ko-fi channel, from $1 and up.
What’s next #
All 34 chapters in ko · ja · en are published. Updates will proceed as follows.
- Stabilizing the v1 text — over the 4 ~ 8 weeks after release, reader feedback folds typos, code errors, and thin explanations into minor revisions (v1.x). The same revisions are applied to all three languages together.
- Part 4 capstone GitHub repository — the finished TODO API will be organized into a separate repository, with the link added to this book page.
- Regular Python updates — new minor versions and library changes are reviewed and reflected on a six-month cadence. Once larger changes accumulate, a v2 book line can begin.
You can subscribe to new-chapter and major-revision notices via the RSS feed.
Contents
Python · uv · the first project. Variables and type hints, control flow, collections, functions, exceptions, modules — all on the latest standard workflow.
- 1. Getting started and uv setup Build your first project with modern Python and uv, with type hints and the latest Python workflow from the start.
- 2. 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.
- 3. Control flow — if, while, for, match-case Flow control where blocks come from indentation, range/enumerate/zip, and match-case pattern matching that differs in feel from switch.
- 4. Collections and comprehensions The four collections — list/tuple/dict/set — and the comprehensions and generator expressions that build new collections in one line.
- 5. Functions — argument patterns Every tool for writing function signatures expressively — defaults, *args/**kwargs, positional-only (/), and keyword-only (*).
- 6. Errors and exception handling The roles of try/except/else/finally, raise and user-defined exceptions, and the ExceptionGroup and except* introduced in 3.11.
- 7. 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.
dataclass · Protocol · context managers · decorators · pattern matching · asyncio intro. From small scripts to maintainable code.
- 8. dataclass and __slots__ Every option of @dataclass for short, safe data classes — frozen, kw_only, field() — plus __slots__ for memory savings, all in one place.
- 9. 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.
- 10. Context managers (with, contextlib) with that turns try/finally into one line, building your own with __enter__/__exit__, @contextmanager for constructor-short forms, and practical tools like ExitStack/suppress.
- 11. Iterables, generators, yield from How for actually works. The iterable protocol, generator functions and expressions, delegation with yield from, and send/throw — all in one place.
- 12. Decorator patterns Every shape of decorator that wraps a function — the basic form, decorators with arguments, functools.wraps, class decorators, and ParamSpec.
- 13. 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.
- 14. Asyncio intro What async/await means, the event loop, asyncio.gather and TaskGroup, and mixing with sync code — your first steps into asyncio in one place.
Magic methods · descriptors · metaclasses · asyncio in depth · GIL · advanced typing · performance profiling.
- 15. Magic methods in depth and protocols Every hook where Python objects integrate with language features. __call__, __getitem__, __hash__, __format__, __getattr__ — gathered in one place.
- 16. Descriptors and __set_name__ How property works — the __get__/__set__ protocol and data/non-data descriptors, and clean validation fields with __set_name__.
- 17. 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.
- 18. Async in depth — event loop, gather/wait, async generator The next step from the intermediate intro — how the event loop actually works, the difference between Future and Task, gather vs wait, async generators and async iteration.
- 19. GIL and concurrency — threading vs multiprocessing vs asyncio The identity of the GIL, the division between threading/multiprocessing/asyncio, and the free-threaded builds of Python 3.13~3.14 (PEP 703/779) — all in one place.
- 20. Advanced typing — Variance, ParamSpec, Self, overload The next step from intermediate typing — covariance/contravariance, ParamSpec and Concatenate, Self, TypeGuard/TypeIs, and @overload.
- 21. 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.
FastAPI · Pydantic v2 · SQLAlchemy 2.x · JWT auth · background jobs · testing and deploy. Closes with the full TODO API capstone.
- 22. FastAPI setup and getting started Why FastAPI, first project setup with uv, Hello FastAPI, automatic OpenAPI/Swagger UI generation — all in one place.
- 23. Routing, Pydantic models, and dependency injection Splitting routes with APIRouter, defining input/output schemas with Pydantic v2, and factoring shared logic out with Depends.
- 24. 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.
- 25. Connecting a DB — SQLAlchemy 2.x + Alembic SQLAlchemy 2.x's new style — Mapped/mapped_column, async sessions, integration with FastAPI's dependency injection, and Alembic migrations.
- 26. Authentication — OAuth2 password flow + JWT Password hashing (argon2/bcrypt), the OAuth2 password flow, JWT issuance/verification, and the current_user dependency that wraps it all into a clean auth pattern.
- 27. Async and background jobs When to use async routes, BackgroundTasks for post-response work, the boundary where external queues (Celery, ARQ) start to be needed, and how to safely mix in sync libraries.
- 28. 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.
- 29. Capstone — finishing the TODO API Tie the patterns from Chapters 1 ~ 28 into a single working service. Authenticated per-user TODO CRUD, tag filtering, pagination, background notifications, tests, and deploy.
Type checkers · CI · structured logging · observability · publishing libraries with uv · Typer CLIs. The areas you actually need on the job.
- 30. 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.
- 31. Logging and observability Pitfalls of the standard logging module, structured logging with structlog, distributed tracing with OpenTelemetry, and error tracking with Sentry.
- 32. 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.
- 33. Building CLI tools (Typer) How to build a type-hints-first CLI with Typer instead of argparse. Subcommands, autocompletion, and Rich-powered output.
Guide for moving old Python code over to the modern style.