Skip to content

stas00/python-cookbook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stas' Python Cookbook

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.

Table of Contents

The full cookbook is in content/, organized into four parts:

  1. Part I: Language Core - strings and text, formatting, numbers, regex, lists, tuples, sets, dictionaries, comprehensions/itertools, functions, classes, dates and times.

  2. Part II: Runtime and Environment - modules and imports, files/paths/IO, environment and arguments, subprocess, serialization, concurrency, networking.

  3. Part III: Debugging, Profiling and Testing - output and logging, debugging, introspection, profiling, exceptions, testing.

  4. Part IV: Packaging and Tooling - versions and dependencies, packaging, code quality, scaling pointers, and an appendix of one-liners.

Updates

I announce any significant updates on my twitter channel https://twitter.com/StasBekman.

Ebook versions of the book

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.

SKILL.md for AI agents

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.

Related Open Books

Contributing

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.

License

The content of this site is distributed under Attribution-ShareAlike 4.0 International.

My repositories map

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

Other Machine Learning: ML ways | Porting

About

Stas' Python Cookbook - Python recipes that I use daily

Topics

Resources

License

Stars

52 stars

Watchers

0 watching

Forks

Contributors