Skip to main content

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

Project description

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

import nats_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()

Supported platforms

Should be compatible with at least Python +3.7.

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.

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

nats-py-worker-0.0.6.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

nats_py_worker-0.0.6-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file nats-py-worker-0.0.6.tar.gz.

File metadata

  • Download URL: nats-py-worker-0.0.6.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for nats-py-worker-0.0.6.tar.gz
Algorithm Hash digest
SHA256 cabc71f5645d3fcc34e34b9b3d1236dc1fa1a272c48359c5bf3e4ee54e58b714
MD5 958a840a781e19417cbf4d3896def598
BLAKE2b-256 611ae743491267a8f543347878fe39270557c933c8965cb4aeb6e75f14a68d39

See more details on using hashes here.

File details

Details for the file nats_py_worker-0.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for nats_py_worker-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 d6415023e023608443bec84f26115a6fe7273c83c6f6d72fb47d4cb3085c8c5a
MD5 700dccba5d55d8fc0c170bb23e6b040a
BLAKE2b-256 43237ed0697855ea10814f58a9037ae63ad823facb249bf4909724f8176fa9c0

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