explaingit

fluentpython/example-code

5,579PythonAudience · developerComplexity · 1/5Setup · easy

TLDR

Code examples from the first edition of Fluent Python, an O'Reilly book on idiomatic Python for developers who already know the basics. Archived, second-edition code lives in example-code-2e.

Mindmap

mindmap
  root((Fluent Python 1e))
    What It Does
      Book examples
      Idiomatic Python
      Runnable snippets
    Topics Covered
      Data structures
      Generators
      Decorators
      Metaprogramming
    Audience
      Python developers
      Intermediate level
    Status
      1st edition only
      Archived
      Use example-code-2e
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Follow along with the first edition of Fluent Python by running example code chapter by chapter

USE CASE 2

Study Python idioms like generators, decorators, and data model methods through working code

USE CASE 3

Explore how Python treats functions as first-class objects with concrete runnable examples

USE CASE 4

Use as a companion when reading the first edition to test and modify examples hands-on

Tech stack

Python

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

This repository contains the example code that accompanied the first edition of the book Fluent Python by Luciano Ramalho, published by O Reilly in 2015. The book is a deep guide to idiomatic Python, covering how to write code that takes full advantage of what the language offers rather than just translating habits from other programming languages. It is aimed at developers who already know the basics of Python and want to understand it more thoroughly. The repository is archived and no longer updated. The code it contains corresponds to the first edition only. A second edition of the book was later published, and its example code lives in a separate repository at github.com/fluentpython/example-code-2e, which is the current maintained version. Anyone working through the second edition should use that repository instead. The README includes a note that during the original writing process, code may have changed or disappeared without warning, and that some pieces not yet in the published ebook at any given time might have been broken. It was a working scratch space during book production, not a polished permanent reference. For readers of the first edition today, the code here may still be a useful companion, but the archived status means issues and inconsistencies are not being fixed. The code itself is organized to match the book chapters, which cover topics like Python data structures, functions treated as objects, object-oriented design idioms, iterators and generators, concurrency, and metaprogramming. No setup beyond a standard Python installation is required to run most examples.

Copy-paste prompts

Prompt 1
I'm reading Fluent Python 1st edition and want to understand Python generators. Show me a simple generator function and explain how it differs from a function that returns a list.
Prompt 2
Explain Python's data model using __len__ and __getitem__ to make a custom class behave like a built-in sequence, the way Fluent Python chapter 1 introduces it.
Prompt 3
Walk me through how Python decorators work with a real-world example, logging or timing a function, in the style Fluent Python uses.
Prompt 4
Show me how Python closures and the nonlocal keyword work with a simple counter example from the Fluent Python style of teaching.
Open on GitHub → Explain another repo

← fluentpython on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.