Skip to main content

FluentIter

Nicer iterator patterns for Python! Chain map, filter, zip, unzip, cycle, skip and scan like there is no tomorrow.

Install with

pip install fluentiter

Straight to the API docs 👉

TLDR:

With fluentiter you can do this

lines = iterator(haystack_csv.split("\n"))
header = [x for x in lines.next().split(",") if x.strip(" ")]
needle = (
    lines.map(lambda line: line.split(","))
    .map(lambda values: {k: v for k, v in zip(header, values)})
    .filter(lambda value_dct: value_dct["material"] != "hay")
    .find(lambda value_dct: value_dct["type"] == "needle")
)

instead of this

lines = iter(some_csv.split("\n"))
header = [x for x in next(lines).split(",") if x.strip()]
needle = next(
    filter(
        lambda value_dct: value_dct["material"] != "hay",
        filter(
            lambda value_dct: value_dct["type"] == "needle",
            map(
                lambda values: {k: v for k, v in zip(header, values)},
                map(lambda line: line.split(","), lines),
            ),
        ),
    )
)

See the this example for a more complete version.

Motivation

To me Pythons iterator functions (i.e. map, filter, zip, etc.) always seemed backward. While generator expressions and list/dict/set comprehensions give you nice left-to-right readability, map and filter force you to read "inside-out":

[func(x) for x in something if x == y]
map(func, filter(lambda x: x == y, something))

This is not an issue for short an simple statements, as they can be written concisely using expressions, but chaining multiple operations, will result in either many intermediate variable assignements or serious spaghettification.

How to use

Any Iterable can be turned into a FluentIterator by just passing it to the iterator function:

from fluentiter import iterator
bugs = ["john", "paul", "ringo", "george"]

fluent = iterator(bugs)
# you can now do
# fluent.map(...).filter(...).cycle(...).scan(...) and so on

The FluentIterator provides a rich set of methods you can call and chain together to your liking:

Of course there are the classic map, filter, and reduce functions, but also some more really useful features like cycle to repeat an iterator forever, find to find an element, into to collect into containers, or apply to transform and continue chaining. There's even partition to turn your iterator into two.

In total FluentIterator provides 38 methods to compose beautiful and easy to follow iteration patterns. Check the API docs to see them all.

Features

  • 38 cool fresh iterator methods
  • 100% Type annotated e.g. iterator(["foo", "bar"]).map(len).to_list() gets correctly inferred as list[int]
  • 100% Test coverage
  • 0 dependencies outside the Python standard library1

Contributing

The simplest way to contribute is to open an issue. If you would like to see some feature implemented or found a bug, head over to the issues section.

Developing

  1. Clone the repository
  2. Install uv
  3. Install development dependencies with uv sync --all-extras

Guidelines

Your PR should include relevant tests for the changes you are contributing and be fully type annotated. If you are unsure or stuck, please open the PR anyway and we can work it out together.

By opening a PR you agree to your code becoming part of the fluentiter package and being published under fluentiters license.

Running formatting, tests, and linting

  • Formatting: uv run poe format
  • Linting: uv run poe lint
  • Tests: uv run poe test

All of the above: uv run poe all

Viewing the coverage report

Running uv run coverage html will create a file htmlcov/index.html you can open to view the test coverage report

Changelog

  • 1.0.0
    • initial release
  • 1.0.1
    • fixed errors int readme
  • 1.1.0
    • add into(...) method
  • 1.1.1
    • add py.typed marker file
  • 1.2.0
    • add tumbling_window function
    • fix mypy inference on .flatten() and .flat_map
    • fix more_itertools being installed automatically
  • 1.2.1
    • fix parameter key not being respected in .min and .max
  • 1.3.0
    • add apply(...) method
    • drop support for Python 3.9

Special Thanks

Thank you to all Rust maintainers for creating the Iterator trait, which served as the main source of inspiration.

  1. Some functions may require the more extra which has more-itertools as a dependency ↩

Metadata

Release files for fluentiter 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fluentiter 1.3.0
File Size Uploaded
fluentiter-1.3.0.tar.gz 12.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fluentiter 1.3.0
File Interpreter ABI Platform
fluentiter-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.1 kB

Release files / fluentiter-1.3.0.tar.gz

Download URL fluentiter-1.3.0.tar.gz
Size 12.9 kB
Tags Source
SHA-256 checksum
How to use checksums
579b3a58bc3736a31f1f85406b72c9bee80f2fcdc5584a069f9c7355d58adfc2
BLAKE2b-256 checksum
How to use checksums
092db227769700c64c6e431abfb559baa9ff630f02c5556a955771302de32a8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 20, 2026.

Transparency log

Release files / fluentiter-1.3.0-py3-none-any.whl

Download URL fluentiter-1.3.0-py3-none-any.whl
Size 14.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7d3aa07f3c4c182feb4c73c734653b60d3d9cfb09257c2d0557776fda290c70e
BLAKE2b-256 checksum
How to use checksums
613dd2b8337f9053006e099117c1ee1f85199d3193091a1c4d88fce126b78c54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 20, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page