Skip to content

pyochain ⛓️

Functional-style method chaining for Python data structures.

Welcome to the pyochain documentation! This library brings a fluent, declarative API inspired by Rust and DataFrame libraries to your Python iterables and dictionaries.

Quick Start

uv add pyochain
import pyochain as pc

# Lazy processing with Iter
pc.Iter.from_count(1).filter(lambda x: x % 2 != 0).map(lambda x: x ** 2).take(5).collect()
# → 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

Documentation Navigation

Guides

API Reference

Collections

  • Iter[T] — Lazy processing of iterators
  • Seq[T] — Immutable collections (tuple-backed)
  • Vec[T] — Mutable collections (list-backed)
  • Dict[K, V] — Chainable dictionaries

Error Handling & Optionals

Each reference page includes detailed examples and complete type signatures.

Philosophy in Brief

  • Declarative → Replace loops with high-level operations
  • Type-safe → Generics and overloads for optimal developer experience
  • Lazy & EagerIter for efficiency, Seq/Vec for materialization
  • Fluent chaining → Compose simple, reusable transformations

For more details on philosophy, inspirations, and dependencies, see the README.