Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

AMQP Client Python

A Python client providing a high-level abstraction for interacting with RabbitMQ, simplifying message publishing, subscribing, and RPC patterns.


License Package version Supported Python versions Downloads Vulnerabilities Releases


Documentation: https://nutes-uepb.github.io/amqp-client-python

Source Code: https://github.com/nutes-uepb/amqp-client-python

Discord Server: https://discord.gg/RkXNeZpNZk


Features:

  • Automatic creation and management of queues, exchanges and channels;
  • Connection persistence and auto reconnect;
  • Support for direct, topic and fanout exchanges;
  • Publish;
  • Subscribe;
  • Support for a Remote procedure call (RPC).

Table of Compatibility

version compatible with
0.2.1 ~0.2.0
0.2.0 0.2.0
0.1.14 ~0.1.12

Installation

You can install amqp-client-python using uv or pip:

uv add amqp-client-python
# or
pip install amqp-client-python

Prerequisites

  • Python 3.9+
  • A running RabbitMQ instance.

Examples:

you can use sync , async eventbus and sync wrapper of async eventbus

async usage
# basic configuration
from amqp_client_python import (
    AsyncEventbusRabbitMQ,
    Config, Options
)
config = Config(Options("queue", "rpc_queue", "rpc_exchange"))
eventbus = AsyncEventbusRabbitMQ(config)
# publish (supports dict/str with auto-JSON, or raw bytes/bytearray without overhead)
await eventbus.publish("rpc_exchange", "routing.key", {"message": "content"})
await eventbus.publish("rpc_exchange", "routing.key", b"raw_binary_payload")

# subscribe (auto_decode=True delivers parsed JSON dict; auto_decode=False delivers raw bytes)
async def subscribe_handler(body) -> None:
    print(body, type(body), flush=True) # handle messages
await eventbus.subscribe("rpc_exchange", "routing.key", subscribe_handler)

# rpc_publish
response = await eventbus.rpc_client("rpc_exchange", "user.find", {"name": "alice"})

# provider
async def rpc_provider_handler(body) -> bytes:
    print(f"body: {body}")
    return b"content"
await eventbus.provide_resource("user.find", rpc_provider_handler)
sync usage(deprecated)
from amqp_client_python import (
    EventbusRabbitMQ,
    Config, Options
)
from amqp_client_python.event import IntegrationEvent, IntegrationEventHandler
from examples.default import queue, rpc_queue, rpc_exchange, rpc_routing_key


class ExampleEvent(IntegrationEvent):
    EVENT_NAME: str = "ExampleEvent"
    ROUTING_KEY: str = rpc_routing_key

    def __init__(self, event_type: str, message = []) -> None:
        super().__init__(self.EVENT_NAME, event_type)
        self.message = message
        self.routing_key = self.ROUTING_KEY


class ExampleEventHandler(IntegrationEventHandler):
    def handle(self, body) -> None:
        print(body,"subscribe")


config = Config(Options(queue, rpc_queue, rpc_exchange))
eventbus = EventbusRabbitMQ(config=config)

class ExampleEvent(IntegrationEvent):
    EVENT_NAME: str = "ExampleEvent"
    def __init__(self, event_type: str, message = []) -> None:
        super().__init__(self.EVENT_NAME, event_type)
        self.message = message

from time import sleep
from random import randint
def handle(*body):
    print(body[0], "rpc_provider")
    return f"{body[0]}".encode("utf-8")

subscribe_event = ExampleEvent(rpc_exchange)
publish_event = ExampleEvent(rpc_exchange, ["message"])
subscribe_event_handle = ExampleEventHandler()
eventbus.subscribe(subscribe_event, subscribe_event_handle, rpc_routing_key)
eventbus.provide_resource(rpc_routing_key+"2", handle)
count = 0
running = True
from concurrent.futures import TimeoutError
while running:
    try:
        count += 1
        if str(count) != eventbus.rpc_client(rpc_exchange, rpc_routing_key+"2", [f"{count}"]).decode("utf-8"):
            running = False
        #eventbus.publish(publish_event, rpc_routing_key, "message_content")
        #running = False
    except TimeoutError as err:
        print("timeout!!!: ", str(err))
    except KeyboardInterrupt:
        running=False
    except BaseException as err:
        print("Err:", err)
sync wrapper usage
from amqp_client_python import EventbusWrapperRabbitMQ, Config, Options

config = Config(Options("queue", "rpc_queue", "rpc_exchange"))
eventbus = EventbusWrapperRabbitMQ(config=config)

async def subscribe_handler(body) -> None:
    print(f"{body}", type(body), flush=True)

async def rpc_provider_handler(body) -> bytes:
    print(f"handle - {body}", type(body), flush=True)
    return f"{body}".encode("utf-8")

# rpc_provider
eventbus.provide_resource("user.find", rpc_provider_handler).result()
# subscribe
eventbus.subscribe("rpc_exchange", "routing.key", subscribe_handler).result()
count = 0
running = True
while running:
    try:
        count += 1
        # rpc_client call
        eventbus.rpc_client("rpc_exchange", "user.find", count).result().decode("utf-8")
        # publish
        eventbus.publish("rpc_exchange", "routing.key", "message_content").result()
        #running = False
    except KeyboardInterrupt:
        running=False
    except BaseException as err:
        print("Err:", err)

Sponsors

The library is provided by NUTES-UEPB.

Know Limitations:

basic eventbus

When using EventbusRabbitMQ Should not use rpc call inside of rpc provider or subscribe handlers, it may block the ioloop
#/obs: fixed on other kinds of eventbus, will be removed on nexts releases

Metadata

Release files for amqp-client-python 0.2.2.dev1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for amqp-client-python 0.2.2.dev1
File Size Uploaded Provenance Actions
amqp_client_python-0.2.2.dev1.tar.gz 154.7 kB Without provenance Details for amqp_client_python-0.2.2.dev1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for amqp-client-python 0.2.2.dev1
File Interpreter ABI Platform Actions
amqp_client_python-0.2.2.dev1-py3-none-any.whl Python 3 none any Details for amqp_client_python-0.2.2.dev1-py3-none-any.whl

Total release size: 199.7 kB

Release files / amqp_client_python-0.2.2.dev1.tar.gz

Download URL amqp_client_python-0.2.2.dev1.tar.gz
Size 154.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7e6f3d63370b7808a9e3510c53a2b65774ba27dab6038efdd6f4f6a491d174fb
BLAKE2b-256 checksum
How to use checksums
5ebbe6b43a8fda12ead48ce69bc644c3d4ac9f9b874d25b67c66eb58b2e3a5c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Pop!_OS","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / amqp_client_python-0.2.2.dev1-py3-none-any.whl

Download URL amqp_client_python-0.2.2.dev1-py3-none-any.whl
Size 44.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
059e1de166c5346ca70bb1984d7ceb716e9b289e40876caed938a581aa6b2ea9
BLAKE2b-256 checksum
How to use checksums
0443203e4f38c6a4ace446c14cb0630efc99e0a80511c103bf421deb67f1b1e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Pop!_OS","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for amqp-client-python 0.2.2.dev1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page