Cover of Serious Python by Julien Danjou, showing an abstract editorial design representing structured, professional Python development

Pages

242

Published

2018

Python ✨ New

Serious Python

Best Practices for Writing Maintainable, Scalable Python

Move beyond beginner Python and ship code that holds up in production — structured, fast, and built to last.

Serious Python bridges the gap between knowing Python syntax and writing code that works in real teams and real projects. Julien Danjou, a longtime Python core contributor, walks you through project structure, packaging, testing, performance profiling, and advanced language features. At 242 pages, it stays focused and actionable — no filler, no toy examples, just the practices that distinguish a competent Python developer from a careful one.

About this book

Most Python tutorials stop at the syntax. They show you how to write a loop, define a class, or open a file. What they skip is everything that happens when your code has to live in a repository, survive a code review, run in production, and get maintained by someone else six months from now.

Serious Python fills that gap. Written by Julien Danjou, a Python core contributor and veteran open-source developer, the book covers the judgment calls that intermediate developers need to make every day: how to structure a project, how to package and distribute code properly, how to test without writing brittle tests, how to profile before optimizing, and how to use the language features that most tutorials never reach.

The material is direct and concrete. Each chapter addresses a specific area where Python developers most commonly plateau: module organization, documentation, type handling, functional programming tools, context managers, decorators, and the internals of how Python runs your code. You will come away understanding not just what to do, but why a given approach holds up under real conditions.

  • Project layout and packaging that follows modern Python conventions
  • Testing strategies with pytest, including fixtures and mocking
  • Performance profiling with cProfile and line_profiler before you guess at bottlenecks
  • Decorators and context managers written to be reusable and readable
  • Functional programming tools from itertools and functools
  • Abstract base classes, method resolution order, and how Python's object model actually works
  • Documentation practices that stay in sync with your code

This is not a reference manual. It does not cover every module in the standard library or attempt to be exhaustive. It is a focused, 242-page argument for writing Python more carefully — and it gives you the tools to do exactly that.

🎯 What you'll learn

  • Structure a Python project so it can be packaged, distributed, and maintained by a team
  • Write tests with pytest that are reliable, readable, and easy to extend
  • Profile Python code to identify real bottlenecks before writing any optimization
  • Build decorators and context managers that are reusable and handle edge cases correctly
  • Apply functional programming tools like itertools and functools to simplify complex data transformations
  • Understand Python's object model, including method resolution order and abstract base classes
  • Document code in a way that stays accurate and generates usable reference output

👤 Who is this book for?

  • Python developers who can write working scripts but want their code to be production-quality and maintainable
  • Self-taught developers who skipped formal software engineering practices and want to fill the gaps
  • Engineers moving to Python from another language who want to learn idiomatic Python patterns quickly
  • Data scientists or analysts whose Python work is outgrowing notebooks and needs real project structure
  • Junior developers preparing for code reviews and wanting to understand the reasoning behind best practices

Table of contents

  1. 01

    Project Structure and Packaging

    Learn how to lay out a Python project from the start, configure setup.py and pyproject.toml, and publish a package that others can install reliably.

  2. 02

    Modules, Libraries, and Frameworks

    Understand how Python's import system works, how to organize code across modules, and when to reach for a framework versus a library.

  3. 03

    Documentation

    Set up Sphinx to generate reference documentation from docstrings and write documentation that stays in sync with the code as it evolves.

  4. 04

    Timestamps and Time Zones

    Handle dates and times correctly by understanding naive versus aware datetime objects and avoiding the common bugs that come from ignoring time zone context.

  5. 05

    Testing

    Write a practical test suite with pytest, use fixtures to manage shared state, and apply mocking to isolate the code you actually want to test.

  6. 06

    Methods and Decorators

    Master Python's method types — instance, class, and static — and write your own decorators that compose cleanly without swallowing stack traces.

  7. 07

    Functional Programming

    Use itertools, functools, and generator expressions to write data-processing code that is shorter, faster, and easier to reason about than equivalent imperative loops.

  8. 08

    Abstract Base Classes and Duck Typing

    Learn when to use ABCs to enforce interfaces, how Python's MRO determines method lookup, and how to use duck typing without sacrificing clarity.

  9. 09

    Performance and Profiling

    Profile a real Python program with cProfile and line_profiler, interpret the output, and apply targeted optimizations rather than guessing at bottlenecks.

  10. 10

    Python Internals and the CPython Runtime

    Explore how CPython executes your code, what the GIL means for concurrency, and how understanding the runtime helps you write more efficient programs.

Frequently asked questions

What Python version does this book target?

The book was published in late 2018 and targets Python 3. Most of the practices and language features covered are stable and still current, though some packaging tooling details have evolved since publication.

Do I need to be an experienced developer to read this?

You should already be comfortable writing basic Python — functions, classes, file I/O. This book is aimed at developers who know the syntax but want to write better-structured, more maintainable code. It is not for absolute beginners.

Is this a reference book or a cover-to-cover read?

It works both ways. The chapters are largely independent, so you can jump to the topic most relevant to you. Reading cover to cover also makes sense because the chapters build a consistent picture of professional Python practice.

Does the book include code examples?

Yes, concrete code examples are central to every chapter. The examples are short and focused — they illustrate one idea at a time rather than building a large application across the book.

Is this book still relevant given it was published in 2018?

The core topics — project structure, testing, decorators, profiling, the object model — have not changed significantly. Some tooling recommendations around packaging and type hints reflect 2018 conventions, so you may want to cross-reference current docs for those specifics.

You might also like

📬 Weekly Newsletter

Stay ahead of the curve

Get the best programming tutorials, data analytics tips, and tool reviews delivered to your inbox every week.

No spam. Unsubscribe anytime.