Getting started¶
FlpIt requires Python 3.12 or newer.
msgspec is installed automatically on CPython and speeds up JSON. On other interpreters (PyPy,
Pyodide) FlpIt installs without it and uses a pure-Python backend. Free-threaded CPython 3.13t is not supported by
msgspec: install there with --no-deps, or use 3.14t.
Your first query¶
from flpit import flp, FlpIt, FlpList
# A lazy, streaming pipeline: nothing has run yet.
query: FlpIt[int] = (
flp
.it(range(1, 11))
.where(lambda x: x % 2 == 0)
.select(lambda x: x * 10)
)
# Explicit materialization.
result: FlpList[int] = query.to_list()
assert result == [20, 40, 60, 80, 100]
flp.it(...) wraps any Iterable[T] in a lazy FlpIt[T]. Nothing runs until you enumerate it or
materialize it with to_list().
Flipping the pipeline¶
Native built-ins read inside-out. A FlpIt pipeline reads in the order things happen:
# Native built-ins read inside-out ...
native = list(map(lambda x: x * 10, filter(lambda x: x % 2 == 0, range(1, 11))))
# ... a FlpIt pipeline reads top to bottom.
piped = (
flp.it(range(1, 11))
.where(lambda x: x % 2 == 0)
.select(lambda x: x * 10)
.to_list()
)
assert piped == native
Typing¶
FlpIt is designed to be inferred precisely by pyrefly without plugins, so annotations like
FlpIt[int] above are optional. mypy and pyright work too, but may infer lambda-heavy pipelines differently.
LINQ operators and Python built-ins¶
A query is an ordinary Python iterable. LINQ-style operators carry LINQ's semantics, and built-ins such as list()
and any() work through the normal iterable protocol:
query = flp.range(1, 11).where(lambda x: x % 2 == 0)
assert query.first() == 2 # LINQ-style terminal operators ...
assert query.any()
assert list(query) == [2, 4, 6, 8, 10] # ... and plain Python built-ins both work
assert any(query)
Querying your own objects¶
select_many flattens one level, here from departments to their employees:
from dataclasses import dataclass
from flpit import flp
@dataclass
class Employee:
name: str
salary: int
@dataclass
class Department:
name: str
employees: list[Employee]
company = [
Department("Engineering", [Employee("Alice", 95_000), Employee("Bob", 70_000)]),
Department("Design", [Employee("Charlie", 82_000)]),
]
# Everyone earning at least 80,000, across all departments.
well_paid = (
flp.it(company)
.select_many(lambda dept: dept.employees)
.where(lambda emp: emp.salary >= 80_000)
.select(lambda emp: emp.name)
)
assert list(well_paid) == ["Alice", "Charlie"]
Where next¶
- Lazy and eager: when does work happen, and what is a
FlpList? - Ordering and grouping
- Joins and lookups
- JSON and CSV
- Async queries: the same operators over
async for. - Concurrency: tasks, channels and concurrent collections.
- Semantics: how closely FlpIt follows .NET LINQ, with running proof.