New
High Performance Python
Practical Performant Programming for Humans
by Ian Ozsvald, Micha Gorelick
Pages
381
Published
2021
Writing Clean, Type-Safe Python for Long-Term Maintainability
Learn to write Python code that stays correct, readable, and maintainable as your codebase grows beyond the prototype stage.
Robust Python by Patrick Viafore shows intermediate Python developers how to use type hints, data classes, and modern language features to write code that communicates intent and catches bugs before they reach production. You will move past "it works on my machine" Python and into practices that scale across teams and time. Published by O'Reilly Media in 2021, this 381-page guide is grounded in real-world engineering trade-offs, not academic abstractions.
Python's flexibility is its biggest strength and its biggest trap. A codebase that looks clean at 500 lines can become a maintenance nightmare at 5,000. Functions with no type information, data structures that mutate in unexpected ways, and implicit contracts between modules are the root cause of most Python bugs that survive code review.
Robust Python addresses these problems head-on. Patrick Viafore walks you through the tools and habits that separate a script that works today from a module that a colleague can confidently change six months from now. The book centers on Python's type system β not as a bureaucratic checkbox, but as a communication tool that makes your intentions machine-checkable.
You will learn how type hints, TypedDict, Protocol, and dataclasses let you encode constraints directly in the code rather than in a comment nobody reads. You will learn when to reach for Union types versus subclassing, how to design APIs that are hard to misuse, and how to run mypy on a real codebase without drowning in false positives.
The book does not stop at types. It covers:
Enum and constrained types to eliminate invalid statesProtocol to achieve duck-typing with static guaranteesThroughout, Viafore grounds every technique in the practical question: what will make this code easier for the next developer β or future you β to understand and modify? The result is a book that improves not just the code you write this week, but the engineering judgment you bring to every project afterward.
If you already know Python and want to write it better, this is the book that bridges the gap between working code and code worth maintaining.
dataclasses and TypedDict that prevent invalid states at the sourceProtocol to write flexible, duck-typed interfaces that still get static analysis coverageUnion types, subclassing, and composition for each specific design problemmypy into an existing codebase incrementally without disrupting ongoing developmentEstablishes what robustness means in a Python context and why dynamically typed, expressive code creates specific long-term maintenance risks. You will examine real failure modes that robust code prevents.
Covers what Python's type system actually is under the hood, including how the interpreter handles types at runtime versus what static checkers see. You will build a mental model that makes the rest of the book click.
Walks through the syntax and semantics of type annotations for variables, function signatures, and return values. You will annotate a working module and run mypy against it for the first time.
Introduces tools like <code>Literal</code>, <code>Final</code>, <code>NewType</code>, and <code>Enum</code> for narrowing what values a type can legally hold. You will replace stringly-typed interfaces with constrained alternatives that catch mistakes at check time.
Explores how to type lists, dicts, sets, tuples, and the standard-library generics correctly, including the difference between invariant, covariant, and contravariant containers. You will fix common annotation mistakes that silently break static analysis.
Shows how to give static structure to dictionary-heavy code using <code>TypedDict</code> and how to define structural interfaces with <code>Protocol</code>. You will refactor a loosely coupled module to gain type coverage without rewriting it.
Covers Python's <code>dataclass</code> decorator as a way to define data-centric classes with less boilerplate and more introspective power. You will convert a plain class to a dataclass and add validation using <code>__post_init__</code>.
Contrasts inheritance-based extension with composition and mixin patterns, explaining when each is appropriate in Python. You will redesign a class hierarchy that has grown brittle and make it open to new behaviors without modification.
Focuses on API surface design: argument ordering, keyword-only parameters, overloads, and making misuse difficult rather than merely documented. You will audit a public module interface and apply targeted improvements.
Brings together mypy configuration, incremental adoption strategies, and complementary tools like pylint and pyright. You will set up a practical static-analysis pipeline suitable for a team codebase.
You should already be comfortable writing Python: functions, classes, standard collections, and basic modules. The book does not teach Python from scratch; it teaches you to write it better.
The book was published in mid-2021 and focuses on Python 3.8 and 3.9 era features. Core concepts like type hints and dataclasses remain fully current, though some newer syntax introduced after publication is not covered.
It is firmly practical. Every concept is illustrated with concrete code examples, and the book consistently frames techniques around the question of what makes code easier to maintain and extend in practice.
Mypy is the primary static checker used throughout, but the design principles apply regardless of your toolchain. Familiarity with running command-line tools is sufficient to follow along.
Yes, if you are moving toward building shared libraries, pipelines, or services that others depend on. If you write one-off notebooks and rarely share code, the payoff may be smaller.
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