fluentpython/example-code-2e: the companion repository for Fluent Python, Second Edition
Example code for Fluent Python, 2nd edition (O'Reilly 2022)
At a glance
- What is it?
- The repository holds one directory per chapter of Fluent Python 2e, from the data model to class metaprogramming, plus pytest.ini and ruff.toml at the root. It is a reading companion, not a library, and the README still warns that the table of contents can change before the book goes to the printer.
- Who is it for?
- Adopt this repository if you are working through Fluent Python, Second Edition and want to run the chapter snippets yourself, or if you teach from the book and need a canonical copy of the examples. Skip it if you want an installable library or a maintained API surface: it has no release history, the README states the table of contents is subject to change until the book goes to the printer, and the last push was on 2026-06-17.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 161 days ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 24, 2026, and from our analysis. They are not legal advice.
Star history
- fluentpython/example-code-2e4,176 ★ · +34
| Repository | 2026-09-23 | 2026-11-24 |
|---|---|---|
| fluentpython/example-code-2e | 4.1k | 4.2k |
34 Stars in the last 62 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
What problem the Fluent Python 2e example code solves
Books about Python internals are hard to read without a terminal open. The repository exists so that every numbered chapter of Fluent Python, Second Edition has a directory of runnable files next to it. The README's table of contents maps each chapter number to a directory name: chapter 1 is 01-data-model, chapter 12 is 12-seq-hacking, chapter 24 is 24-class-metaprog. That mapping is the main thing the repository provides. Without it you would be retyping snippets from paper and guessing which imports the author left implicit.
The audience is narrow and specific. You are expected to be reading the book. The topics listed for the repository are concurrency, iterators, metaprogramming, python3 and special methods, which is a fair summary of the second half of the table of contents. Someone looking for a general-purpose utility package will not find one here. There is no setup.py, no pyproject.toml in the top-level listing, and no release history. The repository is a set of teaching artifacts, and it behaves like one.
How the chapter directories are organised
Every top-level entry except LICENSE, README.md, links/, pytest.ini and ruff.toml is a numbered chapter directory, from 01-data-model through 24-class-metaprog. The numbering follows the second edition, and the README keeps a fourth column that records the equivalent chapter number in the first edition. That column matters because the second edition merged the old Part I prologue into a new Part I on data structures and renumbered the parts, while keeping chapter numbers unchanged. If you are cross-referencing a first-edition copy, the column is the only reliable bridge.
The README marks new chapters with a symbol: Data Class Builders, Type Hints in Functions, More About Type Hints, and Concurrency Models in Python. Those four, plus the rewritten concurrency material in Part V, are where the second edition diverges most from the first. The README says the chapters about concurrency are undergoing significant rewrites. Treat the concurrency directories as the ones most likely to move under you.
Two configuration files sit at the root rather than inside a chapter. pytest.ini and ruff.toml mean the repository is set up to run tests and lint across all chapters from one place. That is a deliberate choice: the examples are meant to be checked, not just read.
Installing the example code and running a first chapter
The README does not give install instructions, so the practical route is to clone the repository and work inside a single chapter directory. The commands below assume git and a Python 3 interpreter are already on your machine.
git clone https://github.com/fluentpython/example-code-2e.git
cd example-code-2e
lsThe listing should show the chapter directories alongside LICENSE, README.md, links/, pytest.ini and ruff.toml. Pick the directory that matches the chapter you are reading; for chapter 1 that is 01-data-model.
cd 01-data-model
python3 -m pytestRunning pytest from inside a chapter directory picks up the root pytest.ini, because pytest searches upward for its configuration file. What you see depends on the chapter: some directories hold scripts meant to be read rather than asserted against, so a chapter with no test functions will report that no tests were collected. That is expected, not a broken checkout.
If you want the lint configuration applied the same way, ruff reads ruff.toml from the root when invoked at the repository top level.
cd ..
ruff check .Both configuration files are the only shared tooling in the repository. There is no virtual environment definition and no dependency lockfile in the top-level listing.
Where the repository stops being useful
The README carries a warning that the table of contents is subject to change at any time until the book goes to the printer. That sentence is a limitation, not boilerplate. Directory names are tied to chapter numbers, and the README records that Part I was merged and the parts renumbered. Anything you build on top of a directory path is building on a name the author reserved the right to change.
The concurrency chapters are the sharpest edge. The README states that all chapters are undergoing review and updates, with significant rewrites in the chapters about concurrency in Part V. Part V in the second edition covers chapters 19 through 24, and the concurrency material sits in 19-concurrency, 20-executors and 21-async. If you are reading those chapters, the code you clone may not match the printed page, and the README does not document which revision of the book a given directory corresponds to.
There is also no versioning to fall back on. The repository has no published GitHub releases, so you cannot pin a tag that matches your printing. Your only reference points are the commit you cloned and the chapter number in the README table. If you need to cite a specific snippet in a review or a course, record the commit hash yourself, because the repository will not do it for you.
How this differs from Effective Python and other example repositories
The nearest comparison people search for is Effective Python, 3rd Edition. Both books ship companion code, but they organise it differently. Effective Python is built around short, self-contained items, so its examples tend to be isolated recipes you can lift one at a time. Fluent Python 2e is built around chapters that build on each other: the data model in chapter 1 underpins special methods in chapter 12, which underpins the descriptor material in chapter 23. The directory structure here reflects that, with 24 numbered directories rather than a flat item list.
That difference has a practical consequence. In an item-based repository you can jump to the one recipe you need. Here, skipping ahead to 24-class-metaprog without the earlier chapters leaves you reading code whose idioms were introduced twenty directories ago. The repository is a linear companion by design, and the README's table of contents is the reading order.
The second difference is tooling. This repository ships pytest.ini and ruff.toml at the root, which signals that the examples are meant to be executed and linted as a set. A book that only wants you to read snippets would not need either file.
Licence and the cost of keeping up
The repository is MIT licensed. That is permissive: you can copy snippets into your own projects, modify them, and redistribute them, provided you keep the licence notice. Note the distinction between the code and the book. The MIT licence covers the repository contents, not the prose of Fluent Python, Second Edition, which is published by O'Reilly. Copying a chapter's explanation into your own writing is a different question from copying a function, and the repository's licence does not address it. This is a description of what the licence file states, not legal advice.
On maintenance: the repository is not archived, and the last push was on 2026-06-17. The README's own warning about the table of contents changing until the book goes to the printer is the honest signal about upgrade cost. There is no release channel, so there is nothing to upgrade between. If you fork the repository for a course or an internal training, you inherit the whole maintenance burden yourself, including the chapter renumbering risk. The two root configuration files, pytest.ini and ruff.toml, are the parts most likely to need adjustment as the Python tooling around them moves, since they pin the test and lint behaviour for every chapter at once.
Editorial conclusion
Adopt this repository if you are working through Fluent Python, Second Edition and want to run the chapter snippets yourself, or if you teach from the book and need a canonical copy of the examples. Skip it if you want an installable library or a maintained API surface: it has no release history, the README states the table of contents is subject to change until the book goes to the printer, and the last push was on 2026-06-17. Before relying on it, check the directory that matches your chapter number, because Part I was renumbered and the README maps old chapter numbers in the right-hand column.
Frequently asked questions
What is fluentpython/example-code-2e?
It is the example code repository for Fluent Python, Second Edition by Luciano Ramalho, published by O'Reilly in 2022. Each numbered chapter of the book has a matching directory, from 01-data-model to 24-class-metaprog.
How do I run the examples in fluentpython/example-code-2e?
Clone the repository, change into the chapter directory you are reading, and run pytest there. The root pytest.ini is picked up automatically because pytest searches upward for its configuration file, and ruff.toml applies when you run ruff from the repository top level.
Does fluentpython/example-code-2e have releases I can pin?
The repository has no published GitHub releases. Without a release channel, the only reference point is the commit you cloned plus the chapter number in the README table of contents.
Which fluentpython/example-code-2e directories cover concurrency?
The concurrency material sits in 19-concurrency, 20-executors and 21-async, under Part V of the table of contents. The README states that the chapters about concurrency are undergoing significant rewrites.
What licence does fluentpython/example-code-2e use?
The repository is MIT licensed, which covers the code in the repository. The book text itself is published by O'Reilly and is a separate matter from the repository's licence.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/fluentpython-example-code-2e)Star history chart for your README
[](https://hysenlabs.com/projects/fluentpython-example-code-2e)Was this useful?