Skip to main content

A stream library for Python inspired by Java Stream API

Project description

Header

PyStreamAPI

DeepSource Tests Pylint Quality Gate Coverage PyPI - Downloads PyPI

PyStreamAPI is a Python stream library inspired by the Java Stream API, adding Pythonic features for clean, declarative, and efficient data processing. It supports both sequential and parallel streams with lazy evaluation.

from pystreamapi import Stream

Stream.of([" ", '3', None, "2", 1, ""]) \
    .filter(lambda x: x is not None) \
    .map(str) \
    .map(lambda x: x.strip()) \
    .filter(lambda x: len(x) > 0) \
    .map(int) \
    .sorted() \
    .for_each(print) # Output: 1 2 3

Installation

pip install streams.py
from pystreamapi import Stream

:tada: PyStreamAPI is now ready to process your data

Why PyStreamAPI?

  • Sequential and parallel streams out of the box
  • Lazy execution for efficient processing of large datasets
  • 100% test coverage
  • Pythonic API — clean, readable, and expressive
  • 111+ built-in conditions for filtering and matching
  • Declarative error handling with configurable error levels
  • Built-in loaders for CSV, JSON, XML, YAML and TOML files

Building a Stream

PyStreamAPI provides two stream types — Stream (general-purpose) and NumericStream (for numerical data with statistics) — each available in sequential and parallel flavors.

Stream.of([1, 2, 3])               # auto-selects sequential or numeric
Stream.parallel_of([1, 2, 3])      # parallel stream
Stream.sequential_of([1, 2, 3])    # sequential stream
Stream.of_noneable(None)           # returns empty stream when source is None
Stream.iterate(0, lambda n: n + 2) # infinite stream (use .limit())
Stream.concat(Stream.of([1, 2]), Stream.of([3, 4]))  # merge streams

For the full API reference see the docs.

Conditions

Conditions

Over 111 ready-to-use conditions across strings, numbers, types, and dates — combine them freely with one_of():

from pystreamapi import Stream
from pystreamapi.conditions import prime, even, one_of

Stream.of([1, 2, 3, 4, 5]) \
    .filter(one_of(even(), prime())) \
    .for_each(print) # 2, 3, 4, 5

Error Handling

Control error behavior per-operation with error_level():

from pystreamapi import Stream, ErrorLevel

Stream.of([" ", '3', None, "2", 1, ""]) \
    .error_level(ErrorLevel.IGNORE) \
    .map_to_int() \
    .sorted() \
    .for_each(print) # Output: 1 2 3

Available levels: RAISE (default), IGNORE, WARN. See the error handling docs for details.

Data Loaders

Load data from files directly into a stream — no manual parsing needed:

Loader Extra required Description
csv CSV files with optional type casting and delimiter
json [json_loader] JSON files or strings (streaming via ijson)
xml [xml_loader] XML files or strings with node path access
yaml YAML files or strings
toml TOML files or strings
from pystreamapi import Stream
from pystreamapi.loaders import csv

Stream.of(csv("data.csv", delimiter=";")) \
    .map(lambda x: x.name) \
    .for_each(print)

Install all optional extras at once: pip install 'streams.py[all]'

See the data loaders docs for full usage.

Documentation

Full documentation: pystreamapi.pickwicksoft.org

Bug Reports

Bug reports can be submitted in GitHub's issue tracker.

Contributing

Contributions are welcome! Please submit a pull request or open an issue.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streams_py-1.4.1.tar.gz (34.9 kB view details)

Uploaded Source

Built Distribution

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

streams_py-1.4.1-py3-none-any.whl (46.8 kB view details)

Uploaded Python 3

File details

Details for the file streams_py-1.4.1.tar.gz.

File metadata

  • Download URL: streams_py-1.4.1.tar.gz
  • Upload date:
  • Size: 34.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.13.1 Linux/6.17.0-1011-azure

File hashes

Hashes for streams_py-1.4.1.tar.gz
Algorithm Hash digest
SHA256 06469f700a6dfda0e566dd183ebfbc6077feca01f948e8e30bee1e0fe64cff09
MD5 90832ed41dd07a2a15eac2d15f80e78a
BLAKE2b-256 dd48319e417de8b1d63a258570bc9efd3530b5cbaee2ac397793a8c6479f5ee7

See more details on using hashes here.

File details

Details for the file streams_py-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: streams_py-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 46.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.13.1 Linux/6.17.0-1011-azure

File hashes

Hashes for streams_py-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2d06e3503fa3f4a7d77d9dc48ccd8ec54b837df530bab5795680d2821c6e7bc0
MD5 9e316ca714e2269efba112b69aeb4422
BLAKE2b-256 aad235c7dcf42288da37ca5ade72121e5a475c9eef305e3c2fbc15607ddcded9

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 Pingdom Monitoring Sentry Error logging StatusPage Status page