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¶
- Chaining Guide — Master the art of chaining with pyochain
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¶
- Result[T, E] — Explicit error handling (
Ok/Err) - Option[T] — Optional values (
Some/NONE)
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 & Eager →
Iterfor efficiency,Seq/Vecfor materialization - Fluent chaining → Compose simple, reusable transformations
For more details on philosophy, inspirations, and dependencies, see the README.