Skip to main content

DataCurrent

Python streaming, made simple.

DataCurrent is a production-ready asynchronous streaming library. It gives you one consistent API for lists, async generators, queues, WebSockets, Server-Sent Events and streaming HTTP responses.

Version 1.1.4 · Stable / Production

PyPI version Python versions CI Release GitHub

Install

pip install datacurrent

Python 3.11 or newer is required. httpx and websockets are installed with the package, so HTTP streaming, SSE and WebSocket clients work immediately. The examples/ directory contains 16 runnable scripts, from a hello-world stream to a WebSocket server.

Framework helpers are optional:

pip install "datacurrent[fastapi]"
pip install "datacurrent[starlette]"
pip install "datacurrent[all]"

Quick start

import asyncio
from datacurrent import Stream


async def main() -> None:
    result = await (
        Stream.from_iterable(range(10))
        .filter(lambda number: number % 2 == 0)
        .map(lambda number: number * number)
        .take(4)
        .collect()
    )
    print(result)  # [0, 4, 16, 36]


asyncio.run(main())

Streams are lazy and single-consumer:

stream = Stream.from_iterable([1, 2, 3])

async for item in stream:
    print(item)

# A second iteration raises StreamConsumedError.

Common terminals:

await Stream.from_iterable([1, 2, 3]).collect()  # [1, 2, 3]
await Stream.from_iterable([1, 2, 3]).count()  # 3
await Stream.from_iterable([3, 1, 2]).reduce(max)  # 3
await Stream.empty().first("fallback")  # "fallback"

Async callbacks work everywhere a callback is accepted:

users = await Stream.from_iterable(user_ids).map(fetch_user, concurrency=8).collect()

Operators

map, filter, flat_map, take, skip, batch, buffer, distinct, enumerate, window, debounce, throttle, timeout, retry, recover, tap, zip, merge and concat.

batches = Stream.from_iterable(range(1_000)).filter(lambda number: number % 3 == 0).batch(100)

async for batch in batches:
    print(len(batch))

Backpressure

Buffers are bounded and block the producer by default. Data is not silently dropped.

stream = Stream.from_iterable(range(100_000)).buffer(size=64)

Lossy behaviour must be explicit and is counted:

stream = Stream.from_iterable(range(10_000)).buffer(
    size=16,
    overflow="drop_oldest",
)
items = await stream.collect()
print(len(items), stream.stats["dropped"])

Policies: block, drop_newest, drop_oldest, error.

Real-time data

WebSocket

from datacurrent import WebSocketStream

async with WebSocketStream.connect("wss://example.com/events") as stream:
    await stream.send_json({"subscribe": "trades"})
    async for message in stream:
        print(message)

Server-Sent Events

from datacurrent import SSEStream

async with SSEStream.connect("https://example.com/events") as stream:
    async for event in stream:
        print(event.event, event.json())

Streaming HTTP

from datacurrent import HTTPStream

async with HTTPStream("https://example.com/feed.ndjson") as response:
    async for line in response.iter_lines():
        handle(line)

Fan-out and events

from datacurrent import Channel, EventBus

channel = Channel(buffer_size=64)
first = channel.subscribe()
second = channel.subscribe()
await channel.publish("deploy finished")

bus = EventBus()


@bus.subscribe("user.*")
async def on_user(event):
    print(event.topic, event.data)


await bus.publish("user.created", {"user_id": 123})

Retries

from datacurrent import RetryPolicy

stream = Stream.from_factory(connect_and_read).retry(
    RetryPolicy(max_attempts=3, base_delay=0.2, jitter=0.1)
)

Retries require a replayable source, such as a factory or a list. A consumed generator raises NonReplayableStreamError instead of silently restarting.

Examples

Sixteen runnable scripts live in examples/. Each one is self-contained and is executed by the test suite, so the output you see is the output the project verifies.

python examples/01_hello_stream.py
python -m pytest tests/unit/test_examples.py -q  # run them all
Script What it demonstrates
01_hello_stream.py Creating a stream, iterating it, tap and terminal operations
02_transformations.py filter, map, distinct, batch, window, reduce, enumerate
03_large_dataset.py 100,000 records streamed in batches with bounded memory
04_filter_events.py EventBus wildcard topics and multiple handlers
05_multi_subscriber.py Channel fan-out to three independent consumers
06_websocket_client.py WebSocketStream JSON send/receive against a local echo server
07_websocket_server.py Broadcasting a Channel to connected WebSocket clients
08_sse_client.py SSEStream event ids, event types and JSON payloads
09_http_streaming.py HTTPStream line iteration and raw body streaming
10_fastapi_integration.py Serving a DataCurrent stream as a FastAPI SSE endpoint
11_backpressure.py Bounded queues, producer suspension and counted drops
12_concurrent_processing.py Bounded concurrency with order preserved
13_retry_recovery.py RetryPolicy, recover and replayable sources
14_custom_transport.py Implementing StreamTransport for a custom protocol
15_realtime_notifications.py Routing one event to WebSocket and email consumers
16_event_pipeline.py End-to-end event filtering, mapping and batching

examples/_servers.py holds the local HTTP/SSE test servers the networking examples use; it is not an example itself.

Why DataCurrent

  • One model for iterables, queues, HTTP, SSE and WebSockets.
  • Backpressure by default, with explicit and counted drop policies.
  • Bounded concurrency and cancellation-safe cleanup.
  • No infrastructure: no broker, database or external account.
  • Explicit delivery semantics; no false durability claims.
  • Typed API and sync or async callbacks throughout.

HTTP clients such as httpx and aiohttp handle requests; DataCurrent adds the stream engine around them. Reactive libraries provide operator algebra, while broker frameworks require Kafka, Redis or RabbitMQ. DataCurrent is the in-process streaming layer that works without any of them.

Compatibility and limits

  • Python 3.11+ on asyncio; no Trio or AnyIO backend.
  • In-memory Channel and EventBus delivery is at most once.
  • No durable broker adapters or OpenTelemetry exporter in this release.
  • The project name is provisional pending trademark clearance.

License

MIT.

Metadata

Release files for datacurrent 1.1.4

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

Source distribution (sdist)

Source distribution for datacurrent 1.1.4
File Size Uploaded Provenance Actions
datacurrent-1.1.4.tar.gz 53.9 kB With provenance Details for datacurrent-1.1.4.tar.gz

Built distribution (wheel)

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

Total release size: 114.7 kB

Release files / datacurrent-1.1.4.tar.gz

Download URL datacurrent-1.1.4.tar.gz
Size 53.9 kB
Tags Source
SHA-256 checksum
How to use checksums
835b25ff98876054d35c3e2b17b7d0e62dd302f16ec69380ab25b81ebbdf8bd4
BLAKE2b-256 checksum
How to use checksums
636083113ce21715f053e43572143f415af18b6ecfc626187760e4216766819f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 14, 2026.

Transparency log

Release files / datacurrent-1.1.4-py3-none-any.whl

Download URL datacurrent-1.1.4-py3-none-any.whl
Size 60.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4dc05afbc9922301d6cd51ef471b6be1c145ea06538b05a03dd5ed7ae3defd07
BLAKE2b-256 checksum
How to use checksums
30561500909e3c0c8afd1442aab75418a33c5d68b79efe42e076fe169a135b2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 14, 2026.

Transparency log

Security for datacurrent 1.1.4

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 datacurrent-1.1.4.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 Nov 14, 2026.

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