freeprogrammingbooks.com

Clean Architectures in Python

By Leonardo Giordani (2019)

Clean Architectures in Python book cover

Software architecture decisions shape how teams build, maintain, and evolve applications over time. As Python projects grow from small scripts into production systems spanning microservices, the need for deliberate structural design becomes critical.

Clean architecture, originally popularized by Robert C. Martin, offers a set of principles that keep business logic independent of frameworks, databases, and external tools.

With AI-assisted development accelerating code output, the challenge is no longer writing code fast — it’s organizing it well. Teams that invest in clear architectural boundaries consistently onboard developers faster, ship fewer bugs, and avoid painful rewrites.

About the book

Clean Architectures in Python is a practical guide to applying clean architecture principles in real Python projects. Written by Leonardo Giordani, the book walks through the entire process — from setting up a project with TDD to building a layered system with web applications and multiple database backends. It does not preach a single rigid structure; instead, it explains the reasoning behind each architectural decision and encourages readers to adapt the methodology to their specific needs.

The book is aimed at Python developers who already know the language and have some experience with unit testing. It is not an introduction to programming, but a hands-on guide for those who want to move beyond “spaghetti code” and build systems that remain maintainable as they grow.

What you will learn

You will learn how to separate your code into layers with clear responsibilities, keeping domain models pure and infrastructure details at the edges. The book covers Test-Driven Development (TDD) with pytest, the repository pattern, dependency inversion, error management, and how to plug different databases (PostgreSQL, MongoDB) into the same clean architecture without rewriting business logic. You will also build a complete example: a web application with Flask, HTTP APIs, and production-ready configuration.

Table of contents

  • Introduction
  • Part 1 – Tools
    • Chapter 1: Introduction to TDD
    • Chapter 2: On unit testing
    • Chapter 3: Mocks
  • Part 2 – The clean architecture
    • Chapter 1: Components of a clean architecture
    • Chapter 2: A basic example
    • Chapter 3: Error management
    • Chapter 4: Database repositories (PostgreSQL, MongoDB)
  • Part 3 – Appendices
    • Changelog

Book details

  • Title: Clean Architectures in Python
  • Author(s): Leonardo Giordani
  • Publication year: 2019
  • Publisher: Self-published (Leanpub)
  • Pages: 174
  • PDF size: 1.77 MB
  • Estimated reading time: ~4 h 21 min
  • Level: Intermediate
  • Main category: Programming
  • Subcategory: Python
  • Language: English
  • License: CC BY-SA 4.0

More books in: Programming, Python


Legal notice: This book is shared for educational purposes only. The content is distributed under Creative Commons licenses or with explicit permission from the author. FreeProgrammingBooks may host files that comply with their respective licenses.

Want more free books?

Join our channels and receive free books, courses and tech news.