Effective Python is Brett Slatkin's book of Python best practices, published by Addison-Wesley and organized as a catalog of short, self-contained Items, each a concrete rule with rationale and trade-offs. The Items cover Pythonic style, comprehensions and generators, function arguments, class design with properties, metaclasses, concurrency under the GIL, robustness and testing. The current 3rd edition of 20 November 2024 expands the 2nd edition's 90 Items to 125.

Effective Python

Details

Core Concepts:

Items format

A catalog of ~125 short, self-contained "Items", each a concrete best-practice rule with rationale and trade-offs (grouped into chapters)

Pythonic thinking

Follow PEP 8 style and the Zen of Python; prefer f-strings over % and str.format; know the difference between bytes and str; prefer helper functions to complex expressions

Lists and dictionaries

Prefer comprehensions to map/filter; use enumerate instead of range; use zip to iterate in parallel; use catch-all unpacking over indexing; avoid else blocks after for/while

Functions

Prefer raising exceptions to returning None; enforce clarity with keyword-only and positional-only arguments; return generators instead of building lists; never modify default argument values (use None and docstrings)

Comprehensions and generators

Use generator expressions for large comprehensions; compose generators with yield from; reach for itertools before hand-rolling iteration

Classes and interfaces

Compose classes rather than nesting dicts/tuples deeply; use @classmethod polymorphism; prefer public attributes and @property over getters/setters; use functions instead of classes for simple interfaces

Metaclasses and attributes

Use @property and descriptors for reusable attribute behaviour; prefer getattr/getattribute sparingly; validate subclasses with init_subclass

Concurrency and parallelism

Use threads for blocking I/O, not parallelism (the GIL); use Queue to coordinate pipelines; use coroutines and asyncio for many concurrent functions; use concurrent.futures and processes for true parallelism

Robustness, testing, and collaboration

Make programs robust and performant (new chapters in the 3rd edition); test with unittest/Mock; document with docstrings; isolate dependencies with virtual environments (venv)

Key Proponent

Brett Slatkin ("Effective Python", Addison-Wesley) — principal software engineer at Google and creator of the book’s runnable example suite

When to Use:

  • Onboarding Python developers to idiomatic, robust ("Pythonic") code

  • Code review discussions grounded in a shared, citable rule set ("Item 30: consider generators instead of returning lists")

  • Establishing team-wide Python coding standards and conventions

  • Explaining Python-specific idioms and pitfalls (comprehensions, generators, the GIL, @property, keyword-only arguments)

  • Prompting an LLM to produce idiomatic, production-quality Python code

Current Status:

  • The 3rd edition (Pearson Addison-Wesley, published 20 November 2024, ISBN 978-0-13-817218-3) is the current edition. It expands from the 2nd edition’s 90 Items to 125 Items — 35 new Items plus two new chapters on robustness and performance

  • The 1st edition (2015) targeted Python 2 as well as 3; the 2nd edition (2019) was Python-3-only through ~3.8; the 3rd edition covers modern Python 3, including features such as the walrus operator, structural pattern matching, and updated typing and asyncio guidance

  • The book’s core advice (prefer comprehensions and generators, respect the GIL, compose classes, use @property) remains stable across editions; only specific Items track the language. A training-data prior keyed on "Effective Python" most plausibly reflects the 2nd edition (90 Items) and is therefore silent on the 35 Items added in the 3rd edition