# Fluent Python 2e Example Code: How the Repository Is Organized and How to Use It

> The fluentpython/example-code-2e repository contains the runnable Python source files for Fluent Python, Second Edition by Luciano Ramalho (O'Reilly, 2022). It is a companion to the book, not a standalone tutorial, and requires the book to make full use of its contents.

**fluentpython/example-code-2e** — Example code for Fluent Python, 2nd edition (O'Reilly 2022) 

- Repository: https://github.com/fluentpython/example-code-2e
- Website: https://amzn.to/3J48u2J
- Stars: 4,148 · Forks: 1,203
- Language: Python
- License: MIT
- Published: 2026-09-23 · Updated: 2026-09-23 · Language: en
- Canonical page: https://hysenlabs.com/projects/fluentpython-example-code-2e

## What This Repository Is and Who Should Clone It

Fluent Python, Second Edition is a book by Luciano Ramalho published by O'Reilly in 2022. The fluentpython/example-code-2e repository holds the Python source files that appear in the book's 24 chapters. Every directory in the repository corresponds to one chapter. The README provides a full table of contents linking each chapter title to its directory.

The repository is a code companion, not a self-contained tutorial. The source files are designed to be read alongside the book's prose. Running the files without the book's context will produce output but will not explain why that output matters or what language mechanism it demonstrates.

The primary audience is anyone working through Fluent Python, Second Edition who wants to run the examples rather than type them by hand, or who wants to modify them to test variations. It is also useful for readers of the first edition who want to see what changed in the second.

## How the Repository Is Structured: One Directory per Chapter

The repository contains 24 top-level directories, one for each chapter. The directory names encode the chapter number and a short topic slug, such as 01-data-model, 09-closure-deco, 17-it-generator, and 24-class-metaprog. This naming scheme makes it straightforward to navigate to the examples for a specific chapter without consulting a separate index.

The README table of contents maps each English chapter title to its directory and also lists the corresponding first-edition chapter number. Chapters that are new to the second edition are marked with a flag in the table. These new chapters are: chapter 5 (Data Class Builders, directory 05-data-classes), chapter 8 (Type Hints in Functions, directory 08-def-type-hints), chapter 15 (More About Type Hints, directory 15-more-types), and chapter 19 (Concurrency Models in Python, directory 19-concurrency).

Additional top-level entries include a links directory, a ruff.toml configuration file for the Ruff linter, and a pytest.ini file that configures pytest for running the example code as tests.

## Cloning and Running the Examples

The repository requires no special build step. Clone it with git and run individual files with Python 3, or run the test suite with pytest from the root directory.

```bash
git clone https://github.com/fluentpython/example-code-2e.git
cd example-code-2e
```

The repository does not include a requirements.txt or pyproject.toml listing runtime dependencies for the examples themselves. Most examples use only the Python standard library. The ruff.toml file at the root configures the Ruff linter, and the pytest.ini configures pytest, so both tools should be installed if you intend to check code style or run tests.

To run the examples for a specific chapter, navigate to the chapter directory and run the relevant file. For example, to explore the data model chapter:

```bash
cd 01-data-model
python frenchdeck.py
```

Many example files include doctest blocks. The pytest.ini configures pytest to collect and run doctests, so running pytest from the repository root will execute the doctests across all chapters. Chapters 4 through 21 cover topics such as Unicode text, decorators, descriptors, and async programming, all of which have runnable doctests in their directories.

## What the Second Edition Added and Changed

The README notes that all chapters in the second edition underwent review and updates, with significant rewrites in the concurrency chapters that form Part V. Four chapters are entirely new: Data Class Builders (chapter 5), Type Hints in Functions (chapter 8), More About Type Hints (chapter 15), and Concurrency Models in Python (chapter 19).

The type hints chapters (8 and 15) cover Python's typing module, which was introduced and expanded substantially between the first and second editions. The examples in 08-def-type-hints and 15-more-types contain code that uses PEP 484 annotations, TypedDict, Protocol, and other constructs that did not exist when the first edition was written.

The concurrency rewrite in Part V covers three chapters: chapter 19 on concurrency models, chapter 20 on concurrent executors, and chapter 21 on asynchronous programming. The async examples in 21-async use asyncio patterns that reflect developments in Python 3.9 and later.

The README includes a note that the table of contents is subject to change until the book went to print, and it records one structural change: the old Part I (Prologue) was merged into the new Part I (Data Structures), with parts renumbered but chapter numbers unchanged.

## Limitations: Not a Course, Requires the Book, No Dependency Management

The repository does not stand alone as a learning resource. The example files contain the code from the book but not the prose that explains each example. A reader who clones the repository without access to the book will find functional Python code but no explanation of why each design choice was made or what Python mechanism is being demonstrated.

There is no requirements file for the examples. If an example depends on a third-party package, you will need to install it manually. The README does not document which examples, if any, have external dependencies beyond the standard library.

The repository has no GitHub releases. It is updated by pushing directly to the master branch. The README note that the table of contents was subject to change applied to the pre-publication period; the book has been published, and the directory structure now reflects the final chapter layout. The last push to the repository was on 2026-06-17.

The repository covers only the second edition. If you are reading the first edition, the directory structure and example code will differ substantially from what you see in your copy of the book.

## Alternative: Fluent Python First Edition Code

The first edition of Fluent Python was published in 2015, and its example code is in a separate repository under the same fluentpython organization on GitHub. That repository covers the original 21 chapters and does not include the type hints or concurrency updates.

For readers who want a structured Python course rather than a book companion, the official Python documentation includes a tutorial at docs.python.org, and the Python Software Foundation maintains the official documentation for the standard library. Those resources are self-contained in a way that the example-code-2e repository is not: they provide explanations alongside the code rather than relying on an external book.

The difference in approach is clear: Fluent Python, Second Edition goes deeper into Python's data model, metaprogramming, and concurrency than an introductory tutorial does. The example-code-2e repository is valuable precisely because it accompanies that specific level of depth, not because it competes with introductory learning resources.

## License and Repository Maintenance

The repository is licensed under MIT. The homepage link in the repository metadata points to the book's page on Amazon, not to a project website.

The repository is not archived. The last push was on 2026-06-17. There are no GitHub releases. Maintenance appears to consist of occasional corrections to the example code as readers report errors or as Python itself changes.

The ruff.toml at the repository root indicates that the maintainers run Ruff for linting. The pytest.ini enables doctest collection. These are the only project tooling files in the repository.

## Conclusion

fluentpython/example-code-2e is useful only when read alongside Fluent Python, Second Edition. If you have the book, the repository gives you runnable code for all 24 chapters, organized by chapter directory and testable with pytest. If you do not have the book, the files lack the explanations that give them context. The repository covers Python type hints (chapters 8 and 15), async programming (chapter 21), and class metaprogramming (chapter 24), topics that were either new or significantly expanded for the second edition.

## FAQ

### What does the fluentpython/example-code-2e repository contain?

It contains the runnable Python source files for all 24 chapters of Fluent Python, Second Edition. Each chapter has its own directory, named with the chapter number and topic. The files are designed to be read alongside the book.

### Can I use this repository without buying the book?

The code runs, but the repository provides no explanations. Each example is meant to accompany a specific section of Fluent Python, Second Edition. Without the book, the purpose of each design choice is not documented in the repository.

### Which chapters are new in the second edition compared to the first?

Four chapters are new: chapter 5 (Data Class Builders), chapter 8 (Type Hints in Functions), chapter 15 (More About Type Hints), and chapter 19 (Concurrency Models in Python). The README marks these with a flag in its table of contents.

## Sources

- [fluentpython/example-code-2e on GitHub](https://github.com/fluentpython/example-code-2e)
- [Issues](https://github.com/fluentpython/example-code-2e/issues)
- [License: MIT](https://github.com/fluentpython/example-code-2e/blob/master/LICENSE)
- [Project website](https://amzn.to/3J48u2J)
- [README](https://github.com/fluentpython/example-code-2e/blob/master/README.md)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/fluentpython-example-code-2e
