Skip to main content

NATS Worker

pypi Versions License MIT

An opinionated utility for using NATS as a worker queue with NATS.py.

Example

# pip install nats-py-worker

from nats_worker import Worker
from nats.js.api import StreamConfig, KeyValueConfig

worker = Worker(name="demo")

async def init_nats(connection):
    connection.jetstream().add_stream(new StreamConfig(name="events", subjects=["inbox.*", "outbox.*"]))
    connection.jetstream().create_key_value(config=KeyValueConfig(bucket="state"))

@worker.background_consumer(subject="inbox.*")
async def watch_incoming(msg):
    ...

@worker.background_state_machine(subject="inbox.*", bucket="state")
async def next_state(kv, msg):
    ...
    await worker.publish_msg(subject=outbox, payload=side_effect)
    ...
    return new_state

if __name__ == '__main__':
    worker.start_as_app()

Installing

pip install nats-py-worker

Development

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

The gitlab-ci.yml is currently setup to push to PyPi when merged to main. Make sure you have updated the version other wise it will fail.

License

Unless otherwise noted, the NATS Worker source files are distributed under the MIT license found in the LICENSE file.

Release files for nats-py-worker 0.0.9

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

Source distribution (sdist)

Source distribution for nats-py-worker 0.0.9
File Size Uploaded
nats-py-worker-0.0.9.tar.gz 9.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nats-py-worker 0.0.9
File Interpreter ABI Platform
nats_py_worker-0.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 18.0 kB

Release files / nats-py-worker-0.0.9.tar.gz

Download URL nats-py-worker-0.0.9.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
88634d268cf362e11368acd147c69b93ce3e84b71e313c5c9c77a722f5753152
BLAKE2b-256 checksum
How to use checksums
e54cb584b48a9a5f1e3fd0fc0ce6e8e956a80867a62409d673227bca000cfd41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / nats_py_worker-0.0.9-py3-none-any.whl

Download URL nats_py_worker-0.0.9-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b55b6db99b2abfad10820a55043999b85b9c7beb2248e5a3a9cd6ef158fce09c
BLAKE2b-256 checksum
How to use checksums
16f89cecdf0533033fcb542f6c7d97a9577be268956a1d8be28a9b7eb6b65f65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.0.9 This release

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release 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