Learn how to separate business logic from database code in a Python app using the Repository and Service Layer patterns.
Refactor a Python codebase that has become hard to change by applying Domain Model, Aggregates, and Unit of Work concepts.
Build an event-driven Python system where parts of your app communicate through a message bus instead of direct calls.
Read the full O'Reilly book for free online and follow along with runnable chapter examples in the companion code repo.
This repo is the book text, read it online for free, runnable code examples live in the companion cosmicpython/code repo.
This repository holds the source files for a published book called "Architecture Patterns with Python," written for developers who want to build Python applications that stay manageable as they grow. The book was published by O'Reilly and is available to read online for free under a Creative Commons license. The repo contains the full text of each chapter as well as the scripts and tooling needed to build the book into readable HTML. The book is structured in two parts. The first part introduces foundational ideas: how to model the core logic of your application in plain Python classes (the Domain Model), how to separate data storage from business logic (the Repository pattern), how to organize your app's operations through a Service Layer, and how to handle related changes together safely (the Unit of Work and Aggregates concepts). Each chapter links to a companion code branch in a separate repository where you can see working Python examples. The second part moves into more advanced coordination patterns: how to let different parts of your system talk to each other through events and a message bus, how to separate read operations from write operations (CQRS), and how to wire dependencies together cleanly (Dependency Injection). There are also appendices covering practical topics like project structure, switching between storage backends, using the Django web framework, and input validation. The book's audience is Python programmers who have built something that works but find it getting harder to change without breaking things. The patterns it teaches come from a tradition sometimes called Domain-Driven Design, applied in a way that fits Python idioms rather than borrowing wholesale from Java or C# conventions where they originated. This repo is mainly the book text itself. The runnable code lives in a companion repo called cosmicpython/code, organized into branches that match each chapter. If you want to follow along with working examples, you would clone that companion repo and check out the branch for the chapter you are reading.
← cosmicpython on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.