Architecture Patterns in Python
280 pages
English
PDF
4.5

Architecture Patterns in Python

Architecture Patterns in Python

Author:

Year:

Summary:

Introduction

The book «Architecture Patterns with Python» by Harry Percival and Bob Gregory was published in 2020 and immediately attracted the attention of the Python developer community. This is not another reference guide on syntax or libraries — it is a deep dive into the principles of building complex, maintainable, and testable applications in Python. Unlike many architecture books written for Java or C#, this work adapts the ideas of Domain-Driven Design (DDD), CQRS, and Event Sourcing to the realities of the Python ecosystem.

The book, about 280 pages long, is aimed at experienced developers who have already encountered the problems of a "big ball of mud" and want to learn how to build systems that are resilient to change. The authors are recognized experts: Harry Percival is known for his work on Test-Driven Web Development with Python, and Bob Gregory is an architect with many years of experience in the financial sector.

What This Book Is About

The book consistently reveals architectural concepts, starting from basic principles and ending with advanced patterns. The main focus is on Domain-Driven Design (DDD) and its implementation in Python. The authors don't just list patterns; they show how they solve real problems: how to separate business logic from infrastructure, how to make code testable, and how to manage complexity.

Key topics of the book:

  • Layered Architecture — separation of responsibilities between the domain, services, and infrastructure.
  • Repository Pattern — an abstraction over the data store to isolate business logic.
  • Unit of Work — managing transactions and consistency.
  • Aggregate — consistency boundaries in DDD.
  • Domain Events — reactive architecture and loose coupling.
  • CQRS (Command Query Responsibility Segregation) — separating commands and queries.
  • Event Sourcing — storing state as a sequence of events.
  • Dependency Injection — managing dependencies without frameworks.

Each pattern is illustrated using a fictional but realistic project — a warehouse inventory management system. This allows the reader to see how decisions are made in context, rather than in abstraction.

Who This Book Is For

The book is intended for intermediate and advanced Python developers who already have experience building web applications (e.g., with Django or Flask) and want to move to the next level — architectural design. It will be useful for:

  • Developers who encounter hard-to-maintain code and want to learn how to refactor it.
  • Team leads and architects looking for practical examples of applying DDD in Python.
  • Those who want to understand CQRS and Event Sourcing without being tied to Java or .NET.
  • Developers who value testing and want to build systems where tests are a tool, not a burden.

Beginners may find the book challenging: it assumes confident knowledge of Python, OOP, and basic design patterns (e.g., from GoF).

What the Reader Will Learn

After reading the book, the reader will be able to:

  • Design a system where business logic does not depend on frameworks or databases.
  • Apply the Repository and Unit of Work patterns to isolate the domain.
  • Build an architecture based on Domain Events.
  • Implement CQRS and Event Sourcing in Python using simple tools.
  • Write tests that verify business rules, not implementation details.
  • Refactor legacy code, gradually introducing architectural patterns.
  • Understand when and why complex architectural solutions are needed, and when a simple approach is sufficient.

Each chapter cont

Recommendations