Skip to main content

Method chaining for iterables and dictionaries in Python.

Project description

pyochain ⛓️

Fluent method chaining for Python.

Inspired by Rust's Iterator, Result, Option, and DataFrame libraries like Polars, pyochain provide a set of classes with a fluent and declarative API, to work with collections, handle optional values, or manage errors.

Key Features

  • ⛓️ Declarative & fluent chaining — Replace for loops with chainable methods (map, filter, group, etc.).
  • 🦥 Lazy-first designIter[T] for lazy processing; Seq, Vec, Set for materialized collections.
  • 🔒 Explicit mutabilitySeq and Set for immutable data; Vec and SetMut when you need to mutate.
  • 🛡️ 100% type-safe — Full generic support and autocompletion in your IDE.
  • 📚 Documentation-first — Every method is documented and tested with runnable examples.
  • Performance-conscious — Built on cytoolz (Cython), more-itertools, and stdlib itertools for efficiency.
  • 🔄 Interoperable — Seamlessly convert to/from types with .into(), .collect()

Quick Start

>>> import pyochain as pc
>>> # Lazy processing with Iter
>>> res: pc.Seq[int] = (
...     pc.Iter.from_count(1)
...     .filter(lambda x: x % 2 != 0)
...     .map(lambda x: x**2)
...     .take(5)
...     .collect()
... )
>>> res
Seq(1, 9, 25, 49, 81)
>>> # Type-safe error handling with Result
>>> def divide(a: int, b: int) -> pc.Result[float, str]:
...     return pc.Err("Division by zero") if b == 0 else pc.Ok(a / b)
>>> divide(10, 0).unwrap_or(0.0)
0.0

Installation

uv add pyochain # or pip install pyochain

See the package page on Pypi

Documentation

For comprehensive guides and examples:

Notice on Stability ⚠️

pyochain is currently in early development (< 1.0), and the API may undergo significant changes multiple times before reaching a stable 1.0 release.

Contributing

Want to contribute? Read our contributing guide

Key Dependencies and credits

Most of the computations are done with implementations from the cytoolz and more-itertools libraries.

An extensive use of the itertools stdlib module is also to be noted.

pyochain acts as a unifying API layer over these powerful tools.

https://github.com/pytoolz/cytoolz

https://github.com/more-itertools/more-itertools

The stubs used for the developpement, made by the maintainer of pyochain, can be found here:

https://github.com/OutSquareCapital/cytoolz-stubs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyochain-0.6.1.70.tar.gz (41.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyochain-0.6.1.70-py3-none-any.whl (45.4 kB view details)

Uploaded Python 3

File details

Details for the file pyochain-0.6.1.70.tar.gz.

File metadata

  • Download URL: pyochain-0.6.1.70.tar.gz
  • Upload date:
  • Size: 41.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyochain-0.6.1.70.tar.gz
Algorithm Hash digest
SHA256 c1ff547facf2a940a7076bb2e8f19b78bccf92cd8bdde67eb4e400a17282c90d
MD5 c05354b147c12281a4be80941d3c51a0
BLAKE2b-256 0e3496cea687528f93bb296af1df47db2fbc869a40c606795d31f3b29bc14f58

See more details on using hashes here.

File details

Details for the file pyochain-0.6.1.70-py3-none-any.whl.

File metadata

  • Download URL: pyochain-0.6.1.70-py3-none-any.whl
  • Upload date:
  • Size: 45.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyochain-0.6.1.70-py3-none-any.whl
Algorithm Hash digest
SHA256 618865a3d0d29fc33529a5dc91807f0dec6ef997ded0de67a8283aba3d176100
MD5 7fdbcdf8458b5dcd0964a011a1723c22
BLAKE2b-256 e1546884ff5f65e0919fa289ff5a8784d05552eb2fbd6818a4df12d94bafae1d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page