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.goor 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bq_nats_client-0.1.1.tar.gz.
File metadata
- Download URL: bq_nats_client-0.1.1.tar.gz
- Upload date:
- Size: 37.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b2c8fbca98ad93044540e18afa3bee966474f3247ed22679d67e078f09e7aa1
|
|
| MD5 |
1c6eecd607f3efff490988c3a42cefe4
|
|
| BLAKE2b-256 |
c10f67d2685af4fd0e7fbb8534b39a3d9f6636bba914bba3266d55e35546b896
|
File details
Details for the file bq_nats_client-0.1.1-py3-none-any.whl.
File metadata
- Download URL: bq_nats_client-0.1.1-py3-none-any.whl
- Upload date:
- Size: 37.7 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cba138cbb32d473d55a462f0dfc4686f169fede96c6320a183439d243b57757
|
|
| MD5 |
5dd748094d72edaeca0462dd398fbe07
|
|
| BLAKE2b-256 |
0384963bc7a1bd2b44bce99988e47742116ff61242700c622708fb480c2601d7
|