Skip to main content

DefStream

Synchronous event/message processing with pluggable broker adapters

DefStream processes broker messages with ordinary Python task methods and can run them in thread or process pools. It requires Python 3.9 or later.

Installation

Install the client extra for the broker you use. A broker server must be available separately.

python -m pip install "DefStream[RabbitMQ]"

For Redis Streams, install DefStream[Redis]. To install both clients, use DefStream[RabbitMQ,Redis]. The plain DefStream installation includes neither broker client.

Quick start

The following worker listens to a local RabbitMQ server at 127.0.0.1:5672. The example credentials are for local development only.

from signal import SIGINT, signal

from DefStream.Broker.Implements.RabbitMQ import Configuration, Connection, Reject, Subscription
from DefStream.Worker import Run, ThreadPool, Worker, WorkerSetup, declare


class Add(
  Run,
  parameters=Subscription(queue='example.add', error='example.add.error'),
  on_error=Reject(),
):
  def run(self, a: int, b: int):
    print(a + b)
    return a + b


class Prepare(WorkerSetup):
  def __call__(self, worker: Worker) -> None:
    for task in worker.tasks:
      declare(task=task, broker=worker.broker)


if __name__ == '__main__':
  worker = Worker(
    Connection(Configuration(host='127.0.0.1', port=5672, username='guest', password='guest')),
    ThreadPool(4),
    setups=Prepare(),
  )
  worker.add(Add)
  signal(SIGINT, lambda *_: worker.stop())
  worker.run()

Run the script after starting RabbitMQ. The worker declares its task queue and waits for messages. Store production credentials outside source code.

License

See the LICENSE file included with the source distribution for the license terms.

Metadata

Release files for DefStream 0.1.22

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

Source distribution (sdist)

Source distribution for DefStream 0.1.22
File Size Uploaded Provenance Actions
defstream-0.1.22.tar.gz 323.3 kB Without provenance Details for defstream-0.1.22.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for DefStream 0.1.22
File Interpreter ABI Platform Actions
defstream-0.1.22-100-py3-none-any.whl Python 3 none any Details for defstream-0.1.22-100-py3-none-any.whl
defstream-0.1.22-93-py3-none-any.whl Python 3 none any Details for defstream-0.1.22-93-py3-none-any.whl
defstream-0.1.22-90-py3-none-any.whl Python 3 none any Details for defstream-0.1.22-90-py3-none-any.whl

Total release size: 633.6 kB

Release files / defstream-0.1.22.tar.gz

Download URL defstream-0.1.22.tar.gz
Size 323.3 kB
Tags Source
SHA-256 checksum
How to use checksums
94be00744cc8155970a5dde7a24bce231bbc9e575d7a00c42abb83fbff1444b9
BLAKE2b-256 checksum
How to use checksums
9cc7b63f22b5f1da057040447b46a5527a15fa8a59211060399901e783a17a9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.17

Release files / defstream-0.1.22-100-py3-none-any.whl

Download URL defstream-0.1.22-100-py3-none-any.whl
Size 103.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
34054b3f9ac0cd875796dac90e0c748526b791a1a946309a4520e920285fbe8f
BLAKE2b-256 checksum
How to use checksums
ddfdaec6d2fb63bce4eea44eda9ee4927e9d85ad9cf00c97ff003c78947e7dfc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.17

Release files / defstream-0.1.22-93-py3-none-any.whl

Download URL defstream-0.1.22-93-py3-none-any.whl
Size 103.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
25dc02aba7119fd81a2805bb566a696c800c67fa6d579f0c9b66e5c936b95a95
BLAKE2b-256 checksum
How to use checksums
9a9d834fd211bdafb49f987bd1c5ea46b3ed5fad4c4c6f21ca36ae020f37385b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.17

Release files / defstream-0.1.22-90-py3-none-any.whl

Download URL defstream-0.1.22-90-py3-none-any.whl
Size 103.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9af0ae8d7dd3d387a4d3143e27a3d5e4aa3c9c3d6cb64ac3636c1df075821eae
BLAKE2b-256 checksum
How to use checksums
e725c6544072de6478659848f13ab1cd1347afdb4437ec3c3dd90c04e4b5678a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.17

Security for DefStream 0.1.22

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.1.22 This release

4 release files No provenance

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