Pro Python 3
Pro Python 3
Summary:
Introduction
The book «Pro Python 3» (authors: Marty Alchin and J. Burton Browning, 2019, 360 pages) is not another introduction to Python syntax. It is a comprehensive guide for those who already write Python confidently and want to understand how the language works "under the hood." Unlike many books aimed at beginners, this edition focuses on advanced concepts: metaprogramming, decorators, context managers, iterators, generators, working with bytecode, and performance optimization. The book was published in 2019, making it relevant for Python versions 3.6–3.8, though most of the techniques described are applicable in newer versions as well.
What is this book about?
«Pro Python 3» is structured as a gradual deep dive into the language's internals. The authors do not waste time explaining basic data types or loops — the reader is assumed to already be familiar with the fundamentals. Instead, the book covers topics such as:
- Metaclasses — how to create your own metaclasses and control class creation.
- Decorators — from simple function decorators to class decorators and built-in Python decorators.
- Context Managers — writing your own context managers using
__enter__and__exit__, as well as usingcontextlib. - Iterators and Generators — creating lazy sequences, infinite iterators, using
yield from. - Descriptors — how properties, methods, and static methods work at the descriptor protocol level.
- Working with Bytecode — a brief introduction to how Python compiles code and how this can be used for optimization.
- Performance Optimization — profiling, using built-in functions, caching, memory management.
- Testing and Debugging — advanced techniques for writing tests, using
unittest.mock, debugging withpdb, and logging.
Each chapter contains numerous code examples that can be tried out immediately in the interpreter. The authors explain not only the "how" but also the "why" — which is especially valuable for understanding the philosophy of Python.
Who is the book for?
The book is aimed at experienced developers who already have at least one Python project under their belt and want to reach the next level. It will be useful for:
- Developers who want to write more efficient and cleaner code.
- Those interested in Python's internal workings and who want to understand how the language's abstractions function.
- Programmers transitioning from other languages (Java, C++, C#) who want to master idiomatic Python.
- Automation, testing, and DevOps specialists who want to use advanced Python features to create flexible tools.
Important: the book is not suitable for beginners — it assumes confident knowledge of the basics (functions, classes, exceptions, file handling).
What will the reader learn?
After reading the book, you will be able to:
- Create your own metaclasses and understand when it is truly necessary (and when it is not).
- Write complex decorators with arguments and decorators for classes.
- Use context managers to manage resources (files, connections, locks).
- Build efficient iterators and generators that save memory.
- Understand how properties, static methods, and class methods work at the descriptor level.
- Profile code and find bottlenecks.
- Apply advanced testing techniques, including mocks and fixtures.
- Use bytecode for low-level optimization (though this is more of an introductory overview).
Strengths of the book
- Depth of coverage.