New
High Performance Python
Practical Performant Programming for Humans
by Ian Ozsvald, Micha Gorelick
Pages
304
Published
2020
Enabling Test-Driven Development, Domain-Driven Design, and the Clean Architecture in Python
Learn to build large-scale Python applications using proven architectural patterns that keep your codebase maintainable as complexity grows.
Most Python tutorials stop at getting code to work. Architecture Patterns with Python picks up where they leave off, showing you how to structure applications that stay manageable as they grow. Harry Percival and Bob Gregory walk through test-driven development, domain-driven design, and clean architecture using concrete Python examples, giving you patterns used by experienced engineers to tame real-world complexity.
Writing Python that works is one skill. Writing Python that a team can maintain, extend, and test confidently over years is another. Most developers hit a wall when their codebase grows beyond a handful of modules and the quick fixes stop working. This book is the practical guide to breaking through that wall.
Harry Percival and Bob Gregory draw on hard-won production experience to show you how professional engineers structure complex Python applications. Rather than presenting abstract theory, they build a real e-commerce system step by step, introducing each pattern at the moment you actually need it. You see the problem before you see the solution, which means the patterns stick.
The book covers three interlocking ideas. Test-driven development gives you a harness that makes refactoring safe. Domain-driven design keeps your business logic clean and independent of frameworks and databases. The clean architecture — built around ports, adapters, and dependency inversion — lets you swap infrastructure without rewriting your core. Together, these make large codebases feel manageable rather than frightening.
Along the way you will work through:
The authors are honest about costs. Every pattern adds indirection, and the book helps you decide when that indirection pays off. There are no silver bullets here, just clear reasoning and code you can read and run.
If you are comfortable with Python but want to write software that behaves like it was designed rather than assembled, this book gives you the vocabulary, the patterns, and the practice to do it.
You write your first domain model in plain Python, completely free of frameworks and databases, and learn why keeping business logic isolated makes it easier to test and reason about.
You wrap your data access behind an abstract repository interface, so your domain model never needs to know whether data lives in Postgres, a file, or a fake in-memory store.
You examine what coupling actually means in code and see how introducing the right abstractions reduces the cost of change without adding unnecessary indirection.
You extract a service layer that orchestrates domain logic and handles use cases, keeping your domain model free of application concerns and your tests fast.
You learn when to test at the unit level and when to test through the service layer, developing a practical instinct for writing tests that survive refactoring.
You implement the Unit of Work pattern to manage database transactions in one place, giving your service layer a clean way to commit or roll back a set of operations atomically.
You model business invariants using Aggregates, learning how to define consistency boundaries that protect your data integrity without locking too much of your database.
You introduce domain events and a message bus that routes them to handlers, decoupling the side effects of business operations from the operations themselves.
You separate commands from events to clarify intent in your message bus, and refactor your application so every operation is initiated by an explicit, named command.
You wire your application together using dependency injection without a heavy framework, and build a bootstrap script that assembles all the components for production and for tests.
You should be comfortable writing Python — functions, classes, list comprehensions, and basic testing. The book does not teach Python syntax and moves quickly through code. Prior experience with a web framework like Flask or Django is helpful but not required.
No. The book introduces every concept from scratch in a Python context. Familiarity with the terms helps you move faster, but the authors explain each idea before applying it.
The book was published by O'Reilly and the authors have made the accompanying code available on GitHub. Check the book's preface or the O'Reilly product page for the exact repository link.
Yes. The architectural patterns covered — domain modelling, repositories, unit of work, message bus — are language-agnostic ideas that do not expire. The Python code targets Python 3 and the concepts apply to any modern Python project.
SQLAlchemy is used throughout as the persistence layer to illustrate the Repository and Unit of Work patterns. Django is not the focus, but the architectural lessons apply directly to Django projects.
If you are still learning Python fundamentals or are building a small personal project that will never grow, the patterns here will feel like overkill. The book earns its complexity when you are working on a codebase that multiple people maintain over time.
New
Practical Performant Programming for Humans
by Ian Ozsvald, Micha Gorelick
New
A thorough reference to Python language fundamentals, from syntax and data types to classes and advanced tools
by Mark Lutz
New
A Hands-On, Project-Based Introduction to Programming in Python
by Eric Matthes
New
A Concise Desktop Reference for Python 3 — Language, Libraries, and Best Practices
by Alex Martelli, Anna Martelli Ravenscroft, Paul McGuire, Steve Holden