Skip to main content

dust-riven

A fast, thread-safe Signal (observer/pub-sub) primitive for Python, implemented in Rust with PyO3 (https://pyo3.rs/).

Inspired by blinker (https://github.com/pallets-eco/blinker), dust-riven aims to be a drop-in-style, lightweight alternative with significantly faster connect/emit performance.

Install

pip install dust-riven

Usage

from dust_riven import Signal

signal = Signal()

def on_event(*args):
    print("received:", args)

handle = signal.connect(on_event)
signal.emit(1, 2, 3)
# prints: received: (1, 2, 3)

signal.disconnect(handle)

One-time listeners

Use once() to register a listener that automatically disconnects itself after it runs a single time.

signal = Signal()
signal.once(lambda: print("only runs once"))

signal.emit()
signal.emit()
# prints "only runs once" a single time

Async listeners

Sync listeners are called with emit(). Async listeners must be called with emit_async(), which awaits all coroutine listeners concurrently.

import asyncio
from dust_riven import Signal

signal = Signal()

async def on_event(x):
    await asyncio.sleep(0.1)
    print("handled:", x)

signal.connect(on_event)

async def main():
    await signal.emit_async(42)

asyncio.run(main())

Calling emit() with an async listener registered raises a TypeError explaining that emit_async() should be used instead.

Error handling strategy

Both emit() and emit_async() accept an on_error keyword argument:

  • on_error="collect" (default): every listener runs, then the first error encountered is raised.
  • on_error="fail_fast": stops immediately at the first error, remaining listeners are not called.
signal.emit(1, 2, on_error="fail_fast")
await signal.emit_async(1, 2, on_error="collect")

API

  • Signal() - create a new signal.
  • signal.connect(callback) -> int - register a callback, returns a handle.
  • signal.once(callback) -> int - register a callback that auto-disconnects after it runs once, returns a handle.
  • signal.disconnect(handle) - remove a previously connected callback.
  • signal.emit(*args, on_error="collect") - call all connected sync listeners with *args.
  • signal.emit_async(*args, on_error="collect") - await all connected listeners (sync and async) with *args, running coroutines concurrently.

Benchmark

A comparison script against blinker is available in bench/benchmark.py:

pip install blinker
python bench/benchmark.py

Development

Built with maturin (https://www.maturin.rs/):

maturin develop

Run tests:

pip install -e ".[dev]"
pytest

License

MIT

Download files

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

Source Distribution

dust_riven-0.1.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

dust_riven-0.1.1-cp310-cp310-win_amd64.whl (283.0 kB view details)

Uploaded CPython 3.10Windows x86-64

File details

Details for the file dust_riven-0.1.1.tar.gz.

File metadata

  • Download URL: dust_riven-0.1.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.14.1

File hashes

Hashes for dust_riven-0.1.1.tar.gz
Algorithm Hash digest
SHA256 54565259a5e51c427842e433ad6b59b974e24e6d75a763a24d25e552c5080d7d
MD5 b886707eef45b775898d9983aebbed2c
BLAKE2b-256 87a20073d3ae4e55a08132c9a8a903f358777394c94dfef666ba7b8e3d617867

See more details on using hashes here.

File details

Details for the file dust_riven-0.1.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for dust_riven-0.1.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f47bf7fb02ea1c9a7484e5d14c55ffb239644d431b1b887c878c5c42b4e1375d
MD5 b81a8fdc88247edb07ac041e13110b9d
BLAKE2b-256 16852ecca3a7bec08a35dc392b388cb41c2b327ee7f2475123e185159d6dedd8

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.1

110 files

0.2.0

110 files

0.1.11

110 files

0.1.10

110 files

0.1.9

110 files

0.1.8

110 files

0.1.7

110 files

0.1.6

110 files

0.1.5

110 files

0.1.4

110 files

0.1.3

110 files

0.1.2

110 files

This release

0.1.1 This release

2 files

0.1.0

2 files

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