Python Pipe Library

2.2 · active · verified Fri Apr 17

The `pipe` library enables a shell-like infix syntax in Python, allowing users to chain operations on iterables using the pipe (`|`) operator. It provides a functional programming style for data processing, similar to LINQ in C# or shell pipes. The current stable version is 2.2, and it follows a slow but steady release cadence, focusing on stability given its utility nature.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates chaining `where` (filter), `select` (map), and `take` (limit) operations on a list using the pipe syntax. It highlights that `pipe` operations are lazy and return generators, which must be explicitly consumed (e.g., by `list()`) to obtain concrete results.

from pipe import select, where, take

l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# Chain operations: filter even numbers, double them, take the first 3
result = l | where(lambda x: x % 2 == 0) | select(lambda x: x * 2) | take(3)

# The result is a generator; convert to list to see concrete values
final_list = list(result)

print(final_list)

view raw JSON →