An open book of practical, example-driven recipes for the Python standard library and the idioms that come up again and again in real work — text wrangling, data structures, files and processes, debugging, profiling, testing, and packaging.
This book grew out of a personal cheat sheet. Every section leads with the why, then shows the how with runnable snippets, and calls out the gotchas that bite people in practice. It targets Python 3.8+, and notes version specifics where they matter.
This is based on the python cheat sheet that I have been honing since many years and still refer to it daily. I then used Claude to convert it to more readable prose, that is hopefully more enjoyable to read. If you prefer the raw/dense cheat sheet you can find it here.
The full cookbook is in content/, organized into four parts:
-
Part I: Language Core - strings and text, formatting, numbers, regex, lists, tuples, sets, dictionaries, comprehensions/itertools, functions, classes, dates and times.
-
Part II: Runtime and Environment - modules and imports, files/paths/IO, environment and arguments, subprocess, serialization, concurrency, networking.
-
Part III: Debugging, Profiling and Testing - output and logging, debugging, introspection, profiling, exceptions, testing.
-
Part IV: Packaging and Tooling - versions and dependencies, packaging, code quality, scaling pointers, and an appendix of one-liners.
I announce any significant updates on my twitter channel https://twitter.com/StasBekman.
You can download various ebook formats of this book:
I will try to rebuild these once in a few weeks or so, but if you want the latest ebook versions, the instructions for building are here.
I maintain a SKILL.md file that you can use to teach your AI agent everyday Python and standard-library idioms better.
See also the companion skills: Machine Learning Engineering and The Art of Debugging.
- Machine Learning Engineering Open Book — training and operating large-scale ML models.
- The Art of Debugging Open Book — methodologies and recipes for debugging Unix, Python and PyTorch programs.
If you found a bug, typo or would like to propose an improvement please don't hesitate to open an Issue or contribute a PR.
The content of this site is distributed under Attribution-ShareAlike 4.0 International.
✔ Books: Machine Learning Engineering | The Art of Debugging | Stas' Python Cookbook
✔ Applications: ipyexperiments
✔ Tools and Cheatsheets: bash | conda | git | jupyter-notebook | make | python | tensorboard | unix