Skip to main content

No project description provided

Project description

nest-rpc-client

Async Python client for RPC transport interoperability with NestJS microservices. Supports RabbitMQ, Redis, NATS (and planned support for Kafka, MQTT).

Features

  • Fully async transports
  • Pluggable transport architecture
  • Compatible with NestJS microservices patterns (send, emit)
  • Extras-based installation

Installation

Install with a specific transport:

pip install "nest-rpc-client[rabbitmq]"
pip install "nest-rpc-client[redis]"
pip install "nest-rpc-client[nats]"

Usage

from nest_rpc_client.client import Client
from nest_rpc_client.transports.rabbitmq import RabbitMQTransport
from nest_rpc_client.config.rabbitmq import RabbitMQConfig

transport = RabbitMQTransport(RabbitMQConfig(url="amqp://guest:guest@localhost/", queue="rpc_queue"))

async with Client(transport) as client:
    result = await client.send("get_user", {"id": 123})
    await client.emit("user_created", {"id": 123})

You can also use only transport:

from nest_rpc_client.transports.rabbitmq import RabbitMQTransport
from nest_rpc_client.config.rabbitmq import RabbitMQConfig

transport = RabbitMQTransport(RabbitMQConfig(url="amqp://guest:guest@localhost/", queue="rpc_queue"))

await transport.connect()

result = await transport.send("get_user", {"id": 123})
await transport.emit("user_created", {"id": 123})

await transport.close()

Custom Transport

nest-rpc-client allows you to use your own custom transports. To do this, inherit from the Transport base class and implement its abstract methods:

from nest_rpc_client.transport import Transport

class MyCustomTransport(Transport):
    async def connect(self) -> None:
        # Initialize any connections or resources
        ...

    async def close(self) -> None:
        # Clean up resources or close connections
        ...

    async def send(self, pattern: str, data: dict) -> dict:
        # Implement the RPC request (expects a response)
        ...

    async def emit(self, pattern: str, data: dict) -> None:
        # Implement the fire-and-forget event
        ...

You can then use your custom transport exactly like the built-in ones:

transport = MyCustomTransport()
async with Client(transport) as client:
    result = await client.send("my_pattern", {"foo": "bar"})

Tests:

This project includes both unit tests and full integration tests.

  • Unit tests are included in this repository and can be run with: pytest
  • Full integration tests are available in a separate repository: nest-rpc-client-tests

TODO:

  • Implement tcp transport
  • Implement kafka transport
  • Implement mqtt transport

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

nest_rpc_client-1.0.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

nest_rpc_client-1.0.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file nest_rpc_client-1.0.0.tar.gz.

File metadata

  • Download URL: nest_rpc_client-1.0.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.2 Linux/6.1.0-31-amd64

File hashes

Hashes for nest_rpc_client-1.0.0.tar.gz
Algorithm Hash digest
SHA256 939bec479b6832c84dc755e18ab0512c00588bb4ec45c6d698197f76a0b169d2
MD5 010f276e70ffbf36a76b5784bd70c22b
BLAKE2b-256 e18fb243d43d0d1899fed42fd663ffa2e7d57af952b9799ae3e0989f20c79686

See more details on using hashes here.

File details

Details for the file nest_rpc_client-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: nest_rpc_client-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.2 Linux/6.1.0-31-amd64

File hashes

Hashes for nest_rpc_client-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0043b2edd97d2c5835c96bcefd9d9159b097c9eadcf6a91f91115339c4576ac8
MD5 430e5c754eb77d81731e268988bf1acd
BLAKE2b-256 90b024185aca53a6c0bd8d121006a38c6028c2bee8445c252cc1f283a62c6b60

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