Introduction
Python Collect is a fluent collection pipeline for Python, modeled after collect.js (itself a port of Laravel’s Collection). It wraps a list or dict and gives you chainable, expressive methods for transforming, filtering, and aggregating data instead of writing loops and comprehensions by hand.
from python_collect import collect
result = ( collect([1, 2, 3, 4, 5, 6]) .filter(lambda n, i: n % 2 == 0) .map(lambda n, i: n * n) .sum())# 56Why Python Collect?
Section titled “Why Python Collect?”Loops and list comprehensions get hard to read once you’re chaining more than one or two operations. Python Collect lets each step read top to bottom, named for what it does, instead of nesting for loops or stacking comprehensions.
Features
Section titled “Features”- Over 100 chainable methods covering filtering, mapping, grouping, sorting, and aggregation
- Works with both
listanddictdata, passing indices or keys to your callbacks automatically - Returns a new
Collectionby default; a handful of explicit methods (push,put,pop, …) mutate in place - Extendable with your own methods via
Collection.macro() - Zero runtime dependencies, Python 3.13+