New
High Performance Python
Practical Performant Programming for Humans
by Ian Ozsvald, Micha Gorelick
Published
2013
Recipes for Mastering Python 3
Stop guessing how Python works and start writing code that is fast, idiomatic, and production-worthy — one concrete recipe at a time.
Python Cookbook, 3rd Edition by David Beazley and Brian K. Jones is a recipe-driven reference for Python 3 that covers the full breadth of the language: data structures, iterators, files, functions, classes, metaprogramming, concurrency, and more. Each recipe isolates a real problem, explains the idiomatic solution, and discusses why it works. If you already know basic Python and want to write code the way experienced practitioners do, this is the book you reach for.
There is a gap between knowing Python syntax and writing Python well. You fill that gap by studying real problems solved with real code. That is exactly what this book delivers: hundreds of self-contained recipes drawn from the day-to-day experience of two Python veterans, covering Python 3 from first principles to the dark corners most developers never visit.
Each recipe follows a disciplined format. The problem statement tells you precisely what situation you are in. The solution shows working, runnable Python 3 code. The discussion explains the mechanics — what the interpreter is actually doing, which alternative approaches exist, and where the trade-offs lie. You can read the book cover to cover or jump straight to the chapter that solves your immediate problem.
The recipes span a wide range of practical territory:
The 3rd edition is written entirely for Python 3. Recipes lean on the standard library first, so you spend time understanding the language rather than chasing third-party dependencies. Where a package genuinely earns its place, the authors say so and explain why.
If you already know how to write a for loop and a class, this book is the next step. It will make you faster, make your code cleaner, and give you the vocabulary to have informed conversations about Python design decisions. Keep it open in a tab alongside your editor — you will reach for it every week.
Work through recipes for sorting, searching, filtering, and grouping data using Python's built-in structures and the collections and heapq modules. You will see when to use a deque versus a list, and how to implement priority queues and ordered dictionaries correctly.
Handle string manipulation, pattern matching, and text parsing with the re module and standard library tools. You will learn to deal with Unicode, tokenise input, and build simple parsers without reaching for a heavy framework.
Perform precise numeric calculations, work with fractions and decimals, and manipulate dates and time zones using the datetime module. Recipes cover common pitfalls around floating-point arithmetic and calendar arithmetic.
Build lazy data pipelines using generators, generator expressions, and the itertools module. You will learn to implement the iterator protocol from scratch and compose generators into reusable processing chains.
Read and write text files, binary files, and compressed archives while handling encoding correctly. Recipes cover memory-mapped files, file locking, and cross-platform path manipulation with the os and pathlib modules.
Parse and emit CSV, JSON, XML, and binary data formats using the standard library. You will work through recipes for streaming large files and handling missing or malformed data gracefully.
Write functions that accept flexible argument lists, use keyword-only arguments, and attach metadata. Recipes cover closures, partial functions, and the functools module in depth.
Implement Python classes that behave correctly under comparison, hashing, and representation. You will learn to write descriptors, use __slots__ for memory efficiency, and override attribute access with __getattr__ and __setattr__.
Use decorators, class decorators, and metaclasses to modify and generate code at definition time. Recipes explain how each mechanism works under the hood so you can debug them when they misbehave.
Compare threads, multiprocessing, and asyncio for CPU-bound and I/O-bound workloads. You will implement thread-safe queues, process pools, and basic async coroutines and understand where each approach breaks down.
The 3rd edition is written entirely for Python 3. Code examples were tested against Python 3.3, which was current at the time of publication. The vast majority of recipes remain directly applicable to modern Python 3 versions, though a few APIs have since been updated.
You should be comfortable with basic Python: functions, classes, loops, and modules. Complete beginners will find the recipes move too fast. Intermediate developers who want to write more idiomatic Python are the primary audience.
It works well as both. Each recipe is self-contained, so you can jump to the chapter that solves your current problem. Reading it cover to cover also works if you want a structured tour of Python 3's capabilities.
O'Reilly published companion code for this title. Check the publisher's website or the authors' own pages for access to the example code repository.
The core language recipes — data structures, iterators, functions, classes, and metaprogramming — remain accurate and idiomatic. Some concurrency and I/O chapters predate asyncio's modern form, so treat those sections as foundational background rather than the final word.
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