Skip to main content

bq-nats-client

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

Architecture

Python app  ──gRPC (Bearer JWT)──►  Go daemon  ──NATS──►  NATS server

The Go daemon runs as its own deployment and owns the NATS connection. This library only connects to it over gRPC — it does not start or bundle the daemon. On the first call the client authenticates with its api-key, gets a short-lived JWT, and attaches it to every request automatically.

Install

pip install bq-nats-client

Configuration

The client reads these env vars (explicit constructor args take precedence):

Env Meaning Default
BQ_NATS_GRPC_ADDR address of the running daemon localhost:50052
BQ_NATS_API_KEY api-key the daemon verifies (→ JWT)
BQ_NATS_TLS_CA CA cert to verify the daemon's TLS cert — (plaintext)

Usage

import asyncio
from nats_client import NATSClient, Msg

async def main():
    # grpc_addr + api_key come from env, or pass explicitly:
    nc = NATSClient(grpc_addr="localhost:50052", api_key="<prime-api-key>")

    # 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=None, api_key=None, tls_ca=None)

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 daemon running as a separate process/deployment (just run, or a compiled go/dist binary)
  • NATS server reachable from the daemon
  • A valid api-key for the daemon to verify

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.5.tar.gz (62.0 kB 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.5-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for bq_nats_client-0.1.5.tar.gz
Algorithm Hash digest
SHA256 a3da3e7608e37a9697e2fc500b5f5132662d3884a1be8ef552d574024a9b6a0e
MD5 e7af527ce1024534691a8fe5978576b7
BLAKE2b-256 6c65787d2a13025564e100ac906c233fe988c897fdd6a91d59d38de93b5f4459

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bq_nats_client-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 99955b46b6cb99a4bcec60aedb63ebf90ba05f913eee5557a847996ea3b91368
MD5 82f5241e81e07aa8d5162731dd58894b
BLAKE2b-256 ad465e734e6735c01c047649770eef42253846d9b17fc030186ccd7ae0e43349

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 Sentry Error logging StatusPage Status page