Skip to main content

Python gRPC client for NATS Go sidecar

Project description

bq-nats-client

Python gRPC client for a NATS Go sidecar. Exposes publish, subscribe, and JetStream operations via a thin async API that mirrors nats.py.

Architecture

Python app  ──gRPC──►  Go sidecar  ──NATS──►  NATS server

The Go sidecar handles the NATS connection; this library talks to it over gRPC on localhost:50052 (or any address you configure).

Install

pip install bq-nats-client

Usage

import asyncio
from nats_client import NATSClient, Msg

async def main():
    nc = NATSClient("localhost:50052")

    # plain publish
    await nc.publish("orders.new", b'{"id": 1}')

    # JetStream
    await nc.jetstream()
    ack = await nc.js_publish("orders.new", b'{"id": 2}')
    print(f"ack: stream={ack.stream} seq={ack.seq}")

    # subscribe
    async def on_msg(msg: Msg):
        print(f"[{msg.subject}] {msg.data}")

    await nc.subscribe("orders.>", cb=on_msg)
    await asyncio.sleep(10)
    await nc.close()

asyncio.run(main())

API

NATSClient(grpc_addr="localhost:50052")

Method Description
publish(subject, payload, reply, headers) Core NATS publish
jetstream(prefix, domain, timeout) Configure JetStream context (call once)
js_publish(subject, payload, ...)PubAck JetStream publish
subscribe(subject, cb, queue, ...)Task Subscribe; cb fires per message
close() Cancel subscribers and close gRPC channel

Requirements

  • Go sidecar running (go run ./go/main.go or compiled binary)
  • NATS server reachable from the sidecar

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

bq_nats_client-0.1.0.tar.gz (37.6 MB view details)

Uploaded Source

Built Distribution

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

bq_nats_client-0.1.0-py3-none-any.whl (37.7 MB view details)

Uploaded Python 3

File details

Details for the file bq_nats_client-0.1.0.tar.gz.

File metadata

  • Download URL: bq_nats_client-0.1.0.tar.gz
  • Upload date:
  • Size: 37.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for bq_nats_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2b2bdc9ea8c633d9b1cb72fcb7f29fe30912f47e7457cb1674df555822ab5a66
MD5 5899ded45aea754deeaaafcdf8cccea0
BLAKE2b-256 2fddbfae3a3d57e8878fcb6853b4178891d7a507d830de387ad89edf8b26363b

See more details on using hashes here.

File details

Details for the file bq_nats_client-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for bq_nats_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fe1ff87230d4162a9a7ccc099808f01b1792da3f2fe7ba6c97f8f84d42b5a7cc
MD5 01fabd6b0443a9f06b5977fa3b3ec9e4
BLAKE2b-256 e7ab168f706d3dca57a0ae222e0f65748c85f3af0d1a92f18104655d06ca7b16

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