Skip to main content

Synchronous wrapper around the native nats async library

Project description

nats-py-sync

Synchronous wrapper around native nats-py async library

This is not a comprehensive, feature complete wrapper. It has the main features described in the nats-py readme


[!TIP] Who is this library for? This library if mainly useful for people who need nats functionality in their non-async based python code. If you can use async in your codebase, use nats-py directly


[!TIP] How does this library work? The NATSContext object maintains its own event loop and queries nats.NATSConnection tasks to complete and return. NATSContext calls are blocking until the nats.NATSConnection futures finish

Installation

pip install nats-py-sync

Publisher/Subscriber

# subscriber
import nats_sync


nc = nats_sync.connect("nats://localhost:4222")
sub = nc.subscribe("hello")
while True:
    msg = sub.recv()
    print(f"Received {msg.data.decode()} on topic {msg.subject}")
# publisher
import time
import nats_sync


NATS_TOPIC = "hello"

nc = nats_sync.connect("nats://localhost:4222")
while True:
    nc.publish(NATS_TOPIC, b"hello world")
    print(f"Published message on {NATS_TOPIC}")
    time.sleep(0.1)

Request/Response

# request
import time
import nats_sync


client = nats_sync.connect("nats://localhost:4222")
while True:
    msg = client.request("request", "hello world".encode())
    print(f"Received Reply {msg.data.decode()} on topic {msg.subject}")
    time.sleep(1.0)
# response
import nats_sync


nc = nats_sync.connect("nats://localhost:4222")
sub = nc.subscribe("request")
while True:
    msg = sub.recv()
    print(f"Received {msg.data.decode()} on topic {msg.subject}")
    sub.respond(msg, "Reply".encode())

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_sync-0.1.1.tar.gz (29.4 kB view details)

Uploaded Source

Built Distribution

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

nats_py_sync-0.1.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nats_py_sync-0.1.1.tar.gz
  • Upload date:
  • Size: 29.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.13

File hashes

Hashes for nats_py_sync-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d6ea46440321f1b1a97ea0b08bff25c5f4e7b53c747847ccf65f1c309079e4ad
MD5 c43f559b13ab7fc903d2cdb45dbafe9e
BLAKE2b-256 86bf728f4569a7d2c86c676341cd7dc5bb5a97ba64be08c8d53b9b3836ad9d3d

See more details on using hashes here.

File details

Details for the file nats_py_sync-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for nats_py_sync-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ca2531293a55e28ee38bd8035d967c91099e85ed0641ce2301c4ad11aa95ed48
MD5 fa713869b612174f787cd0ea56a6345c
BLAKE2b-256 c9e7449faf50176db7201c10f9b8935227d05e90466c59c989ecf25dcd077d9f

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