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.

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

This repository is configured for uv.

uv add python-fp-flow
uv sync

If you prefer pip: pip install python-fp-flow.

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.post2.tar.gz (3.5 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.post2-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

Hashes for python_fp_flow-0.1.0.post2.tar.gz
Algorithm Hash digest
SHA256 9591d1413b7a8b227d12e530ea777b79cd5a9f263fa4f00c2893cc8492500924
MD5 79942c615bb00f15b34e68597a8f1af5
BLAKE2b-256 44a3830a4cdc7ef47678e2dd4f0cd29ebc5222d0f6c27bb63b6aa41f316e708a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_fp_flow-0.1.0.post2-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.post2-py3-none-any.whl
Algorithm Hash digest
SHA256 2c89dcb49d1104d6c47f4d1c3f13706d3d6528f06e62c8aaad050909a61477f0
MD5 7583e0faa24d8f08441357fa02748b3f
BLAKE2b-256 e37af3a084b95d82a3c99deb1da516d64bc6e07025179a64913c6887eff27866

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