Skip to main content

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.

The library is intentionally small and focused: it helps make sequential data transformations explicit and readable.

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:

  1. trim and lowercase text
  2. remove punctuation
  3. split into words
  4. remove common stopwords
  5. sort unique words
  6. 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: applies fn to the wrapped value and returns a new Flow.

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 Flow behavior (value, chaining, repr, str)
  • chain composition 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

python_fp_flow-0.1.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_fp_flow-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file python_fp_flow-0.1.0.tar.gz.

File metadata

  • Download URL: python_fp_flow-0.1.0.tar.gz
  • Upload date:
  • Size: 3.6 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

Hashes for python_fp_flow-0.1.0.tar.gz
Algorithm Hash digest
SHA256 75a2a6f567ecf44ddae467ac965aadd1d495e97b62e373fe9570a3233459bde8
MD5 84dce643fc568858039206e41f84b0bc
BLAKE2b-256 a709af2e2ac10db2495532f036b847d74b1fd82ac47a22c47254397d1953409d

See more details on using hashes here.

File details

Details for the file python_fp_flow-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: python_fp_flow-0.1.0-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

Hashes for python_fp_flow-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4dfadf2f2b01bc4670ac080e470313103dd796d463df018f750bbe713d1b915d
MD5 4b7e2eab7992dcbe0600e3e16b143c56
BLAKE2b-256 ce96ae806dcbf24906e4c2dcd744af1bdf51e614b1114b7c582e25cfa21dfb00

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page