More than 20 years have passed since I authored the Python Essential Reference. At that time, Python was a much smaller language and it came with a useful set of batteries in its standard library. It was something that could mostly fit in your brain. The Essential Reference reflected that era. It was a small book that you could take with you to write some Python code on a desert island or inside a secret vault. Over the three subsequent revisions, the Essential Reference stuck with this vision of being a compact but complete language reference—because if you’re going to code in Python on vacation, why not use all of it?
Today, more than a decade since the publication of the last edition, the Python world is much different. No longer a niche language, Python has become one of the most popular programming languages in the world. Python programmers also have a wealth of information at their fingertips in the form of advanced editors, IDEs, notebooks, web pages, and more. In fact, there’s probably little need to consult a reference book when almost any reference material you might want can be conjured to appear before your eyes with the touch of a few keys.
If anything, the ease of information retrieval and the scale of the Python universe presents a different kind of challenge. If you’re just starting to learn or need to solve a new problem, it can be overwhelming to know where to begin. It can also be difficult to separate the features of various tools from the core language itself. These kinds of problems are the rationale for this book.
Python Distilled is a book about programming in Python. It’s not trying to document everything that’s possible or has been done in Python. Its focus is on presenting a modern yet curated (or distilled) core of the language. It has been informed by my years of teaching Python to scientists, engineers, and software professionals. However, it’s also a product of writing software libraries, pushing the edges of what makes Python tick, and finding out what’s most useful.
For the most part, the book focuses on Python programming itself. This includes abstraction techniques, program structure, data, functions, objects, modules, and so forth—topics that will well serve programmers working on Python projects of any size. Pure reference material that can be easily obtained via an IDE (such as lists of functions, names of commands, arguments, etc.) is generally omitted. I’ve also made a conscious choice to not describe the fast-changing world of Python tooling—editors, IDEs, deployment, and related matters.
Perhaps controversially, I don’t generally focus on language features related to large-scale software project management. Python is sometimes used for big and serious things— comprised of millions upon millions of lines of code. Such applications require specialized tooling, design, and features. They also involve committees, and meetings, and decisions to be made about very important matters. All this is too much for this small book. But perhaps the honest answer is that I don’t use Python to write such applications—and neither should you. At least not as a hobby.
In writing a book, there is always a cut-off for the ever-evolving language features. This book was written during the era of Python 3.9. As such, it does not include some of the major additions planned for later releases—for example, structural pattern matching. That’s a topic for a different time and place.
Last, but not least, I think it’s important that programming remains fun. I hope that my book will not only help you become a productive Python programmer but also capture some of the magic that has inspired people to use Python for exploring the stars, flying helicopters on Mars, and spraying squirrels with a water cannon in the backyard.
I’d like to thank the technical reviewers, Shawn Brown, Sophie Tabac, and Pete Fein, for their helpful comments. I’d also like to thank my long-time editor Debra Williams Cauley for her work on this and past projects. The many students who have taken my classes have had a major if indirect impact on the topics covered in this book. Last, but not least, I’d like to thank Paula, Thomas, and Lewis for their support and love.
David Beazley is the author of the Python Essential Reference, Fourth Edition (Addison-Wesley, 2010) and Python Cookbook, Third Edition (O’Reilly, 2013). He currently teaches advanced computer science courses through his company Dabeaz LLC ( www.dabeaz.com ). He’s been using, writing, speaking, and teaching about Python since 1996.