Skip to main content

fpstreams

Build Status License: MIT

A robust, type-safe functional programming library for Python.

fpstreams brings the power of Java Streams, Rust Results, and JavaScript Array methods to Python. It provides a fluent interface for data processing, null safety, and error handling without the boilerplate, all while remaining fully typed for IDE autocompletion.

Features

  • Fluent Streams: Lazy evaluation chains (map, filter, reduce, zip)
  • Null Safety: Option monad to eliminate None checks.
  • Error Handling: Result monad (Success/Failure) to replace ugly try/except blocks.
  • Powerful Collectors: Grouping, partitioning, and joining made simple.
  • Functional Tools: Utilities like pipe and curry for cleaner composition.

Installation

pip install fpstreams

Usage Example

Streams (using name from Java)

from fpstreams import Stream

data = [
    {"name": "Alice", "role": "admin", "age": 30},
    {"name": "Bob", "role": "dev", "age": 25},
    {"name": "Charlie", "role": "admin", "age": 45}
]

# Get names of admins whose age is over 25, sorted alphabetically
names = (
    Stream(data)
    .filter(lambda u: u["role"] == "admin")
    .filter(lambda u: u["age"] > 25)
    .map(lambda u: u["name"].upper())
    .sorted()
    .to_list()
)
# Output: ['ALICE', 'CHARLIE']

Null Safety with Option

from fpstreams import Stream

# Find the first user named "Steven" (who doesn't exist)
email = (
    Stream(data)
    .filter(lambda u: u["name"] == "Steven")
    .find_first()               # Returns Option[User]
    .map(lambda u: u["email"])  # Skipped because Option is empty
    .or_else("default@example.com")
)

Error handling with Result

from fpstreams import Result

def risky_parsing(value):
    return int(value) # Might crash if value is not a number

# Safe execution
result = (
    Result.of(lambda: risky_parsing("invalid"))
    .map(lambda x: x * 2)
    .on_failure(lambda e: print(f"Parsing failed: {e}")) # Logs error
    .get_or_else(0) # Returns 0 instead of crashing
)

Collectors

grouping data using collectors

from fpstreams import Stream, Collectors

fruits = ["apple", "avocado", "banana", "blueberry", "cherry"]

# Group fruits by their first letter
grouped = (
    Stream(fruits)
    .collect(Collectors.grouping_by(lambda s: s[0]))
)
# Output: {'a': ['apple', 'avocado'], 'b': ['banana', 'blueberry'], 'c': ['cherry']}

Infinite Streams & Lazy Evaluation

Process massive datasets efficiently. Operations are only executed when needed.

def infinite_counter():
    n = 0
    while True:
        yield n
        n += 1

# Take only the first 10 even numbers
evens = (
    Stream(infinite_counter())
    .filter(lambda x: x % 2 == 0)
    .limit(10)
    .to_list()
)

Project Structure

1.Stream: The core wrapper for iterables.
2.Option: A container for optional values.
3.Result: A container for operations that may fail.
4.Collectors: Helper functions for aggregation.
5.functional: Utilities like pipe and curry

Metadata

Release files for fpstreams 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fpstreams 0.1.3
File Size Uploaded Provenance Actions
fpstreams-0.1.3.tar.gz 10.2 kB With provenance Details for fpstreams-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fpstreams 0.1.3
File Interpreter ABI Platform Actions
fpstreams-0.1.3-py3-none-any.whl Python 3 none any Details for fpstreams-0.1.3-py3-none-any.whl

Total release size: 19.0 kB

Release files / fpstreams-0.1.3.tar.gz

Download URL fpstreams-0.1.3.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
24e97997eb6162c6f39b178caac96964e47490b8bd9a665bf4174410fc4f774e
BLAKE2b-256 checksum
How to use checksums
f382b398b60c3235b29019d074a34b4bdc7794965dac7f3f131053f805808bc1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 14, 2025.

Transparency log

Release files / fpstreams-0.1.3-py3-none-any.whl

Download URL fpstreams-0.1.3-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
564f06e369abf78f0102b305a9a43a4d12b08a4f7c374e47569ca939e68b65bd
BLAKE2b-256 checksum
How to use checksums
4bb4986b1b77706a87b9af3724275a867b8335167bb03d6ed7e7dcd59704a343
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 14, 2025.

Transparency log

Security for fpstreams 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fpstreams-0.1.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 14, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page