Skip to main content

Distributed event processing for Python based on Redis Streams

Project description

Runnel

pyversions LGPLv3 version coverage tests

Distributed event processing for Python based on Redis Streams.

https://runnel.dev

Runnel allows you to easily create scalable stream processors, which operate on partitions of event streams in Redis. Runnel takes care of assigning partitions to workers and acknowledging events automatically, so you can focus on your application logic.

Whereas traditional job queues do not provide ordering guarantees, Runnel is designed to process partitions of your event stream strictly in the order events are created.

Installation

pip install runnel

Basic Usage

from datetime import datetime

from runnel import App, Record

app = App(name="myapp", redis_url="redis://127.0.0.1")


# Specify event types using the Record class.
class Order(Record):
    order_id: int
    created_at: datetime
    amount: float


orders = app.stream("orders", record=Order, partition_by="order_id")


# Every 4 seconds, send an example record to the stream.
@app.timer(interval=4)
async def sender():
    await orders.send(Order(order_id=1, created_at=datetime.utcnow(), amount=9.99))


# Iterate over a continuous stream of events in your processors.
@app.processor(orders)
async def printer(events):
    async for order in events.records():
        print(f"processed {order.amount}")

Meanwhile, run the worker (assuming code in example.py and PYTHONPATH is set):

$ runnel worker example:app

Features

Designed to support a similar paradigm to Kafka Streams, but on top of Redis.

  • At least once processing semantics
  • Automatic partitioning of events by key
  • Each partition maintains strict ordering
  • Dynamic rebalance algorithm distributes partitions among workers on-the-fly
  • Support for nested Record types with custom serialisation and compression
  • Background tasks, including timers and cron-style scheduling
  • User-defined middleware for exception handling, e.g. dead-letter-queueing
  • A builtin batching mechanism to efficiently process events in bulk
  • A runnel[fast] bundle for C or Rust extension dependencies (uvloop, xxhash, orjson, lz4)

Documentation

Full documenation is available at https://runnel.dev.

Blog posts

Essays about this project or the technology it's using:

Local development

To run the test suite locally, clone the repo and install the optional deps (e.g. via poetry install -E fast). Make sure Redis is running on localhost at port 6379, then run pytest.

See also

For a traditional task queue that doesn't provide ordering guarantees, see our sister project Fennel.

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

runnelpy-0.2.2.tar.gz (32.6 kB view details)

Uploaded Source

Built Distribution

runnelpy-0.2.2-py3-none-any.whl (41.8 kB view details)

Uploaded Python 3

File details

Details for the file runnelpy-0.2.2.tar.gz.

File metadata

  • Download URL: runnelpy-0.2.2.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.8.18 Linux/6.5.0-1025-azure

File hashes

Hashes for runnelpy-0.2.2.tar.gz
Algorithm Hash digest
SHA256 a486ad45f234a2eac599414a3e59dd5cab7767a4a05f858e2c65495768f33f39
MD5 e8144cd274e40f2d6bf4510f5424bf0e
BLAKE2b-256 bb9dc5cad2b5c1c3a3842b756d0d114663c9ebcf68eb94f6134053403238d3ff

See more details on using hashes here.

File details

Details for the file runnelpy-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: runnelpy-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 41.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.8.18 Linux/6.5.0-1025-azure

File hashes

Hashes for runnelpy-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4c1ff88fbd2d81dedabcf70b45e33c629392a271da45c86779dd34aff68059fe
MD5 35928a3a8a8a4b2299627195299b2e4e
BLAKE2b-256 364dab32e9a350287e9b6dca0abc7842cdecbc3cc75a6298adcd393bd203f22f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page