An AMQP 1.0 client library for Python
npx @tessl/cli install tessl/pypi-uamqp@1.6.0An AMQP 1.0 client library for Python that provides comprehensive messaging capabilities for building applications using the Advanced Message Queuing Protocol. It offers both synchronous and asynchronous APIs for sending and receiving messages, supports various authentication methods, and provides extensive configuration options for connections, sessions, and message handling.
pip install uamqpimport uamqpCommon imports for basic messaging:
from uamqp import send_message, receive_message, receive_messages
from uamqp import Message, Source, Target
from uamqp import SendClient, ReceiveClientAuthentication imports:
from uamqp.authentication import SASLPlain, SASLAnonymous, SASTokenAuthimport uamqp
from uamqp.authentication import SASLPlain
# Send a single message
target = "amqps://example.com/queue"
message = "Hello, AMQP!"
auth = SASLPlain("username", "password")
uamqp.send_message(target, message, auth=auth)
# Receive messages
source = "amqps://example.com/queue"
messages = uamqp.receive_messages(source, auth=auth, max_batch_size=10)
for message in messages:
print(message.get_data())
message.accept()The uAMQP library follows the AMQP 1.0 protocol architecture:
The library provides both high-level client APIs (SendClient, ReceiveClient) for ease of use and low-level protocol access for advanced scenarios.
Simple functions for common messaging operations including sending single messages, receiving single messages, and batch message operations.
def send_message(target, data, auth=None, debug=False):
"""Send a single message to AMQP endpoint."""
def receive_message(source, auth=None, timeout=0, debug=False):
"""Receive a single message from an AMQP endpoint."""
def receive_messages(source, auth=None, max_batch_size=None, timeout=0, debug=False, **kwargs):
"""Receive a batch of messages from an AMQP endpoint."""
def get_platform_info():
"""
Get current platform information.
Returns:
str: Platform information string
"""Core message classes for creating, manipulating, and processing AMQP messages including support for different body types, properties, and batch operations.
class Message:
def __init__(self, body=None, properties=None, application_properties=None,
annotations=None, header=None, msg_format=None, encoding='UTF-8',
body_type=None, footer=None, delivery_annotations=None): ...
class BatchMessage:
def __init__(self, data=None, properties=None, application_properties=None,
annotations=None, header=None, multi_messages=False, encoding='UTF-8'): ...High-level client classes for sending and receiving messages with built-in connection management, error handling, and batching capabilities.
class SendClient:
def __init__(self, target, auth=None, client_name=None, debug=False, **kwargs): ...
class ReceiveClient:
def __init__(self, source, auth=None, client_name=None, debug=False, **kwargs): ...Comprehensive authentication support including SASL mechanisms, token-based authentication, and Claims-Based Security (CBS) for Azure services.
class SASLPlain:
def __init__(self, hostname, username, password, port=5671, **kwargs): ...
class SASTokenAuth:
def __init__(self, hostname, port, token, token_type="servicebus.windows.net:sastoken", **kwargs): ...Low-level AMQP protocol management including connection establishment, session management, and link creation for advanced messaging scenarios.
class Connection:
def __init__(self, hostname, sasl=None, container_id=None, max_frame_size=None, **kwargs): ...
class Session:
def __init__(self, connection, incoming_window=None, outgoing_window=None, handle_max=None): ...Connection and Session Management
AMQP endpoint addressing including source and target configuration with support for filters, dynamic addresses, and link properties.
class Source:
def __init__(self, address=None, **kwargs): ...
class Target:
def __init__(self, address=None, **kwargs): ...Direct access to AMQP protocol elements including message senders, receivers, and protocol-level message handling for advanced use cases.
class MessageSender:
def __init__(self, session, source, target, name=None, **kwargs): ...
class MessageReceiver:
def __init__(self, session, source, target, name=None, **kwargs): ...Type system for AMQP values and comprehensive constants for protocol states, error codes, and configuration options.
class AMQPType:
def __init__(self, value): ...
class MessageState:
WaitingToBeSent = 0
WaitingForSendAck = 1
SendComplete = 2
# ...Comprehensive error handling with custom exceptions, error policies, and retry mechanisms for robust messaging applications.
class ErrorPolicy:
def __init__(self, max_retries=3, on_error=None): ...
class AMQPError(Exception): ...
class AMQPConnectionError(AMQPError): ...Asynchronous AMQP operations for Python 3.4+ with async/await support for high-performance messaging applications.
class SendClientAsync:
def __init__(self, target, auth=None, client_name=None, debug=False, **kwargs): ...
class ReceiveClientAsync:
def __init__(self, source, auth=None, client_name=None, debug=False, **kwargs): ...