python-fp-flow
A minimal FP-oriented library for composing function pipelines in Python.
This project provides two utilities:
Flow: a value wrapper that lets you pipe transformations with the>>operator.chain(...): a function composer that combines multiple unary callables into one callable.
Why this library?
Python already lets you compose transformations, but once a pipeline has many steps, nested calls become harder to parse.
Assume we want to:
- trim and lowercase text
- remove punctuation
- split into words
- remove common stopwords
- sort unique words
- format as a summary string
Shared setup (used by all examples)
import re
STOPWORDS = {"the", "and", "is", "a", "of", "to"}
def strip_punctuation(s: str) -> str:
return re.sub(r"[^a-z0-9\s]", "", s)
def to_words(s: str) -> list[str]:
return s.split()
def remove_stopwords(words: list[str]) -> list[str]:
return [w for w in words if w not in STOPWORDS]
def unique_sorted(words: list[str]) -> list[str]:
return sorted(set(words))
def summarize(words: list[str]) -> str:
return f"keywords({len(words)}): {', '.join(words)}"
input_text = " The Quick, brown fox jumps over the lazy dog! "
Without this library (nested calls)
result = summarize(
unique_sorted(
remove_stopwords(
to_words(
strip_punctuation(
input_text.strip().lower()
)
)
)
)
)
With Flow (left-to-right data pipeline)
from flow import Flow
result = (
Flow(input_text)
>> str.strip
>> str.lower
>> strip_punctuation
>> to_words
>> remove_stopwords
>> unique_sorted
>> summarize
).value()
With chain (reusable transformation function)
from chain import chain
text_pipeline = chain(
str.strip,
str.lower,
strip_punctuation,
to_words,
remove_stopwords,
unique_sorted,
summarize,
)
result = text_pipeline(input_text)
Flow and chain reduce cognitive load by making each step explicit and ordered from top-to-bottom / left-to-right, rather than inside-out.
Requirements
- Python
>= 3.14
Installation (local development)
This repository is configured for uv.
uv sync
API overview
Flow
Flow(value): wraps any value..value(): returns the current wrapped value.flow >> fn: appliesfnto the wrapped value and returns a newFlow.
chain
chain(fn1, fn2, ..., fnN): returns a new callable that applies each function in sequence.- Designed for unary callables (
Callable[[T], U]). - Includes typing overloads for better inference across multi-step pipelines.
Running tests
uv run pytest
Current tests cover:
- basic
Flowbehavior (value, chaining,repr,str) chaincomposition order and exception propagation
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_fp_flow-0.1.0.post1.tar.gz.
File metadata
- Download URL: python_fp_flow-0.1.0.post1.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba64fc501fc6fa62d90455bbb25db57cf44e4ff8ef8ca1ee3d2c8185f36263c4
|
|
| MD5 |
81e267246e33ab1318ea19f91e474f72
|
|
| BLAKE2b-256 |
ab163fec7a02fc98e2590ba88e2bf0daeb972dfdd3c454a0bee7827780dd1436
|
File details
Details for the file python_fp_flow-0.1.0.post1-py3-none-any.whl.
File metadata
- Download URL: python_fp_flow-0.1.0.post1-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6635af36ccee3c32a53113f25a36a19e316f331905555aef5e22abfa3a5943a
|
|
| MD5 |
b2e67d902fc7796fa3de9fda2de25f5d
|
|
| BLAKE2b-256 |
ab1614f9217af448c22ff43cb79f17383886aaf092268b9ab3ad6634b4ba20ff
|