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.
  • 📚 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 .into(), .collect()
  • 🐍 Mixins traits — Extend your own classes with the methods in the mixins provided by the traits module.

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, 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.71.tar.gz (43.1 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.71-py3-none-any.whl (47.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyochain-0.6.1.71.tar.gz
  • Upload date:
  • Size: 43.1 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.71.tar.gz
Algorithm Hash digest
SHA256 57f1855baf33ecf0e12152266b878ab9f3819ed056d3de11f4ec9935ca192878
MD5 d751091cd9db5aa0e13bd8217609cf12
BLAKE2b-256 bec8da0d6ab031509983f3d2bca389cddf7cf4ef49b4c320ce191c7aed8469c1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyochain-0.6.1.71-py3-none-any.whl
  • Upload date:
  • Size: 47.1 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.71-py3-none-any.whl
Algorithm Hash digest
SHA256 2b3c3c3cf3847d15e9bf26ee8e5a81b7f72b69d80cc1d0def3c6707b82767eca
MD5 fb6f18c23413a7478818bdb91220f7da
BLAKE2b-256 14782cc1d717d86b5cdb61f447c474f8f6269990ac95395e41cb9c6a194e71cb

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