New
High Performance Python
Practical Performant Programming for Humans
by Ian Ozsvald, Micha Gorelick
Pages
422
Published
2020
Write maintainable, idiomatic Python using best practices, design patterns, and clean-code principles
Learn to write Python code that your teammates can read, extend, and trust in production.
Clean Code in Python, Second Edition teaches you to write Python that is readable, maintainable, and built to last. Covering everything from SOLID principles and design patterns to testing strategies and type annotations, this book gives you a concrete, opinionated framework for raising the quality of any Python codebase. Whether you are refactoring legacy work or starting fresh, you will leave with habits that make every line you write easier for the next person to understand.
Most Python developers learn to make their code work. Fewer learn to make it last. Clean Code in Python, Second Edition is for the second group: developers who want their codebases to remain readable, extensible, and trustworthy as requirements change and teams grow.
The book starts from first principles. You will revisit what clean code actually means in Python specifically, not as an abstract ideal but as a set of concrete, actionable practices rooted in the language's own idioms. From there, Mariano Anaya builds a structured curriculum that covers the full lifecycle of professional Python development.
Design comes first. You will work through SOLID principles applied to Python, learning why single-responsibility matters in a dynamically typed language and how the open/closed principle shapes the way you write classes and modules. You will study design patterns not as a catalog to memorize but as tools to reach for when a problem calls for them.
Quality comes next. The book gives serious attention to automated testing: unit tests, integration tests, and the discipline of writing tests that actually catch bugs rather than just adding coverage numbers. You will learn how to structure test suites that run fast, stay green, and tell you exactly what broke when they fail.
Throughout, Python's own features are treated as first-class citizens. Decorators, context managers, descriptors, generators, and the data model all appear in the context of real design decisions, not as isolated syntax exercises. Type annotations and the role of static analysis tools round out the modern Python workflow the book describes.
If you are writing Python professionally and want the code you produce to hold up under scrutiny, review, and time, this book gives you the vocabulary, the patterns, and the habits to do it.
Establishes what clean code means in the context of Python, covering formatting conventions, naming, and the tools that enforce style automatically. You will set up a baseline quality workflow using linters and formatters.
Explores Python-specific idioms including comprehensions, context managers, properties, and magic methods. You will learn to write code that feels native to the language rather than imported from another paradigm.
Introduces design by contract, defensive programming, and the principle of least surprise. You will apply these ideas to write functions and classes whose behaviour is predictable and easy to reason about.
Works through each SOLID principle with concrete Python examples, showing how they apply in a dynamically typed language. You will refactor a series of flawed designs into cleaner, more extensible alternatives.
Covers how decorators work at a deep level and shows patterns for using them to separate concerns cleanly. You will build reusable decorators that add behaviour without cluttering the functions they wrap.
Explains the descriptor protocol and shows how it underpins attributes, properties, and many framework features. You will write custom descriptors to eliminate repetitive validation logic across a class hierarchy.
Covers Python's iteration model and coroutine-based concurrency, showing how generators and async patterns improve both performance and readability. You will refactor blocking code into clean async equivalents.
Teaches a practical approach to unit testing with pytest, including fixtures, mocking, and test structure. You will refactor a messy codebase test-first, learning to keep coverage meaningful rather than cosmetic.
Surveys the design patterns most applicable to Python, showing idiomatic implementations and the trade-offs of each. You will recognise when a pattern fits a problem and when simpler alternatives are preferable.
Brings the book's concepts together in a discussion of component boundaries, dependency inversion, and sustainable architecture. You will map these ideas onto real project structures that stay clean as they scale.
The second edition targets Python 3 throughout. Examples use modern syntax including f-strings, type annotations, and dataclasses that require Python 3.7 or later.
No prior knowledge of patterns or architecture is assumed. The book builds those concepts from scratch in a Python context, so intermediate Python experience is sufficient.
No. The principles are framework-agnostic. You will benefit most if you already have some framework experience, because you will recognise where the clean-code habits apply in code you are already writing.
Yes. The book includes code examples throughout. Check the publisher's page for any companion repository or downloadable files associated with this edition.
The book assumes you are comfortable writing Python and understand the basics of object-oriented programming. Complete beginners would benefit from a foundations book first.
The second edition expands coverage of type annotations, static analysis tooling, and async patterns to reflect how professional Python development has evolved since the first edition was published.
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