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.

Installation

uv add pyochain # or pip install pyochain

See the package page on Pypi

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

Key Features

  • ⛓️ Declarative & fluent chaining — Replace for loops with chainable methods (map, filter, group_by, 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.
  • 📚 Accurate Documentation — Every method is documented and tested with runnable examples. Every code example in the website (or this README) is also tested, ensuring accuracy and reliability.
  • Performance-conscious — Built on cytoolz (Cython), more-itertools, and stdlib itertools for efficiency.
  • 🔄 Interoperable — Seamlessly convert to/from types with various methods like .into() and .collect()
  • 🐍 Mixins traits — Extend your own classes with the methods in the mixins provided by the traits module.

Documentation

For comprehensive guides and examples:

🔍 Core Types Overview — Type overview, comparisons and visual relationships 📚 Full API Reference — Complete API documentation 📖 Examples & Cookbook — Practical patterns and recipes

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, itertools, cytoolz and more-itertools.

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 development, 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.72.tar.gz (43.9 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.72-py3-none-any.whl (47.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyochain-0.6.1.72.tar.gz
  • Upload date:
  • Size: 43.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","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.72.tar.gz
Algorithm Hash digest
SHA256 c3a9a04e6ae0624adbffd1868f62c2982ddaa0919f4b49fd390532290ed67612
MD5 4b975a07ef483c190c348ff065773a6f
BLAKE2b-256 d2653f39c60130bade7b7a14c3c0340f5c179bb55f276eb41dbdd2218ff75595

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyochain-0.6.1.72-py3-none-any.whl
  • Upload date:
  • Size: 47.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","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.72-py3-none-any.whl
Algorithm Hash digest
SHA256 9a33f58ac8a33ea3f110f70390645f6f2f9998cbed7ade260a3ab34d8390c4a5
MD5 075f29fc05e5452f1ec46e7ca8304c58
BLAKE2b-256 877ab1f5f1ca2e0903a2264a30a85aa2e19d598128dfe02ad698da0b556a6612

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