Skip to main content

No project description provided

Project description

ReNATS

Elegant, modern and asynchronous NATS Client API library written in pure Python

import asyncio
from renats.client import NATSClient, Message

servers = (
    ("127.0.0.1", 4222),
)

client = await NATSClient().connect(servers)

# Publish message to subject 'my.subject' with payload 'My payload =)'
await client.publish("my.subject", b"My payload =)")

# Publish message to subject 'my.subject' with payload 'My payload =)',
# reply subject 'my.reply.subject' and header 'MyHeader' with value 'MyValue'
await client.publish(
    subject="my.subject",
    payload=b"My payload =)",
    reply_subject="my.reply.subject",
    headers={
        "MyHeader": "MyValue"
    }
)


# Callbacks can be sync or async (def or async def)
def callback(message: Message):
    print(f"Received message in sync callback from {message.subject}: {message.payload}")


async def async_callback(message: Message):
    await asyncio.sleep(3)
    print(f"Received message in async callback from {message.subject}: {message.payload}")


subscription = await client.subscribe("foo.bar", callback)
another_subscription = await client.subscribe("foo.baz", async_callback)

await client.publish("foo.bar", b"Hello world! (to subscription with sync callback)")
await client.publish("foo.baz", b"Hello world! (to subscription with async callback)")

await subscription.unsubscribe()
await another_subscription.unsubscribe()

# Closing client
await client.close()

Installation

pip install renats

TODO

  • Request-Reply
  • JetStream
  • ObjectStorage
  • Request-Reply API Framework for microservices
  • And more, maybe...

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

renats-0.2.3a0.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

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

renats-0.2.3a0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file renats-0.2.3a0.tar.gz.

File metadata

  • Download URL: renats-0.2.3a0.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.19.0-43-generic

File hashes

Hashes for renats-0.2.3a0.tar.gz
Algorithm Hash digest
SHA256 4ebb944343a071438de5c996dc2c291a08a84d43db13a28ebb695d7485f759dd
MD5 c623240da114d0b59175236b03bc380a
BLAKE2b-256 ce7254fc717323299e508aaa99d0c178b687cd02162ab36fa5be1caa5baf1f79

See more details on using hashes here.

File details

Details for the file renats-0.2.3a0-py3-none-any.whl.

File metadata

  • Download URL: renats-0.2.3a0-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.19.0-43-generic

File hashes

Hashes for renats-0.2.3a0-py3-none-any.whl
Algorithm Hash digest
SHA256 5baebe5dd0062c104a81fac49a78ff7f6cffa488ad39814c406b4de17093d1de
MD5 5f09d56bca01bb0c8fc99c15eab22ceb
BLAKE2b-256 f283419b0173a63310f8bd5ed67d55ea73e923100d030b2eedf04c51082016e7

See more details on using hashes here.

Supported by

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