Initial release of nats-service, a Python service framework for NATS
implementing ADR-32, built on nats-core.
Features
- Services - Register a service with a name, version, and description
- Endpoints - Add request handlers on subjects, with queue groups
- Groups - Nest endpoints under shared subject prefixes
- Discovery - Respond to
PING,INFO, andSTATSrequests - Statistics - Per-endpoint request, error, and processing time counters, with reset
- Error responses - Reply with service error code and description headers
Requirements
- Python 3.13+
Installation
pip install nats-serviceQuick Start
import asyncio
import nats.client
import nats.service
async def main() -> None:
client = await nats.client.connect()
async with nats.service.add_service(
client,
name="echo",
version="0.1.0",
description="Echoes the request payload back to the caller",
) as service:
async def echo(request: nats.service.Request) -> None:
await request.respond(request.data)
await service.add_endpoint("echo", echo)
await service.wait_stopped()
asyncio.run(main())