Install & Compatibility
Where this runs
tested against v1.6.11 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
build_error
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.8s · import 0.272s · 35MB
33MB installed
● package 33MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Connection
✓ from uamqp import Connection
Message
✓ from uamqp import Message
SenderLink
✓ from uamqp import SenderLink
ReceiverLink
✓ from uamqp import ReceiverLink
authentication
✓ from uamqp import authentication
This quickstart demonstrates how to establish an AMQP connection, authenticate using SASLPlain, and send a message to a target entity (e.g., an Azure Service Bus queue or Event Hub). It assumes authentication details are provided via environment variables.
import os
import time
import uamqp
from uamqp import authentication, Message, SenderLink, Connection
# Set these environment variables for a runnable example:
# AMQP_ADDRESS: e.g., "amqps://<namespace>.servicebus.windows.net/<entity_name>"
# SAS_POLICY: e.g., "RootManageSharedAccessKey"
# SAS_KEY: The shared access key for the policy
AMQP_ADDRESS = os.environ.get("AMQP_ADDRESS", "amqps://localhost:5672/my_queue")
SAS_POLICY = os.environ.get("SAS_POLICY", "your_sas_policy_name")
SAS_KEY = os.environ.get("SAS_KEY", "your_sas_key")
conn = None
sender = None
try:
if not all([AMQP_ADDRESS, SAS_POLICY, SAS_KEY]):
print("Please set AMQP_ADDRESS, SAS_POLICY, and SAS_KEY environment variables.")
exit(1)
# Extract hostname (e.g., <namespace>.servicebus.windows.net) from AMQP_ADDRESS
hostname = AMQP_ADDRESS.split('//', 1)[-1].split('/', 1)[0].split(':', 1)[0]
# Extract target address (e.g., <entity_name>) from AMQP_ADDRESS
target_address = AMQP_ADDRESS.split('/', 3)[-1]
# Create SASL authentication
sasl_auth = authentication.SASLPlain(
hostname=hostname,
username=SAS_POLICY,
password=SAS_KEY
)
# Create an AMQP connection
print(f"Connecting to {hostname}...")
conn = Connection(
hostname,
sasl_auth=sasl_auth,
idle_timeout=10000,
debug=False # Set to True for verbose AMQP tracing
)
# Create a SenderLink to send messages
sender = SenderLink(conn, target_address, debug=False)
sender.open()
print(f"SenderLink opened to {target_address}")
# Create and send a message
message_body = f"Hello from uAMQP at {time.time()}!"
message = Message(message_body.encode('utf-8'))
sender.send_messages([message])
print(f"Sent message: '{message_body}'")
time.sleep(1) # Give time for message to be sent
except Exception as e:
print(f"An error occurred: {e}")
print("Ensure your environment variables are correctly configured and the AMQP endpoint is accessible.")
finally:
if sender and sender.is_open:
sender.close()
print("SenderLink closed.")
if conn and conn.is_open:
conn.close()
print("Connection closed.")
Errors
Common errors & fixes
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
Installing `uamqp` on Windows requires the Microsoft C++ Build Tools to compile its C extension from source.
fixDownload and install "Build Tools for Visual Studio" from the provided URL, selecting the "Desktop development with C++" workload.
ImportError: DLL load failed while importing _c_uamqp: The specified module could not be found.
The `uamqp` C extension's dynamic link library (DLL) failed to load, often due to missing Visual C++ Redistributables or an incomplete build.
fixInstall the appropriate Visual C++ Redistributable for your system (e.g., from microsoft.com), or try reinstalling `uamqp` after verifying C++ build tools are present.
ModuleNotFoundError: No module named 'uamqp'
The `uamqp` package has not been installed in the current Python environment.
fixInstall the package using pip: `pip install uamqp`
uamqp.errors.AMQPConnectionError: AMQPConnectionError: Cannot connect to [hostname]:[port] because of a timeout or connection issue.
The AMQP client failed to establish a connection to the broker due to network problems, an incorrect address, or an unavailable service.
fixVerify the hostname, port, network connectivity, and firewall rules; ensure the AMQP broker is running and accessible.
Upgrade
Version history
1.6.11latest on PyPI · released Oct 28, 2024
Audit
Dependencies
No dependency data recorded yet.