AMQP 1.0 Client Library for Python
.. image:: https://img.shields.io/pypi/v/uamqp.svg :target: https://pypi.python.org/pypi/uamqp/
.. image:: https://img.shields.io/pypi/pyversions/uamqp.svg :target: https://pypi.python.org/pypi/uamqp/
.. image:: https://dev.azure.com/azure-sdk/public/_apis/build/status/python/azure-uamqp-python%20-%20client?branchName=main :target: https://dev.azure.com/azure-sdk/public/_build?definitionId=89
An AMQP 1.0 client library for Python.
uAMQP for Python requires Python 3.6+ starting from v1.5, and Python 2.7 is no longer supported. If Python 2.7 is required, please install uAMQP v1.4.3:
.. code:: shell
$ pip install uamqp==1.4.3
Wheels are provided for most major operating systems, so you can install directly with pip:
.. code:: shell
$ pip install uamqp
If you are running a Linux distro that does not support ManyLinux1 <https://www.python.org/dev/peps/pep-0513>__ or you need to customize the build based on your system settings and packages, you can install from source:
.. code:: shell
$ apt-get update
$ apt-get install -y build-essential libssl-dev uuid-dev cmake libcurl4-openssl-dev pkg-config python3-dev python3-pip
$ pip3 install uamqp --no-binary :all:
If you are running Alpine, you can install from source:
.. code:: shell
$ apk add --update python3 py-pip python3-dev cmake gcc g++ openssl-dev build-base
$ pip3 install uamqp --no-binary :all:
If you are running Red Hat, you can install from source:
.. code:: shell
$ yum install cmake gcc gcc-c++ make openssl-devel python3-devel
$ pip3 install uamqp --no-binary :all:
Documentation
+++++++++++++
Reference documentation can be found here: docs.microsoft.com/python/api/uamqp/uamqp <https://docs.microsoft.com/python/api/uamqp/uamqp>__.
In order to run the code directly, the Cython extension will need to be build first.
Pre-requisites ++++++++++++++
build environment <https://packaging.python.org/guides/packaging-binary-extensions/#building-binary-extensions>__... code:: shell
$ brew install cmake
Building the extension ++++++++++++++++++++++
This project has two C library dependencies. They are vendored in this repository in these versions:
Azure uAMQP for C <https://github.com/Azure/azure-uamqp-c>__ @ 2021-11-16 <https://github.com/Azure/azure-uamqp-c/tree/259db533a66a8fa6e9ac61c39a9dae880224145f>__Azure C Shared Utility <https://github.com/Azure/azure-c-shared-utility>__ @ 2021-11-15 <https://github.com/Azure/azure-c-shared-utility/tree/735be16a943c2a9cbbddef0543f871f5bc0e27ab>__To build, start by creating a virtual environment and installing the required Python packages:
.. code:: shell
$ python -m venv env
$ env/Scripts/activate
(env)$ pip install -r dev_requirements.txt
Next, run the build command:
.. code:: shell
$ python setup.py build_ext --inplace
Tests +++++
The tests can be run from within the virtual environment. The extension must be built first using the instructions above.
.. code:: shell
(env)$ pytest
If you encounter any bugs or have suggestions, please file an issue in the
Issues <https://github.com/Azure/azure-uamqp-python/issues>__
section of the project.
This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.microsoft.com <https://cla.microsoft.com>__.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct <https://opensource.microsoft.com/codeofconduct/>.
For more information see the Code of Conduct FAQ <https://opensource.microsoft.com/codeofconduct/faq/> or
contact opencode@microsoft.com <mailto:opencode@microsoft.com>__ with any additional questions or comments.
.. :changelog:
1.6.6 (2023-11-16) +++++++++++++++++++
1.6.5 (2023-07-12) +++++++++++++++++++
1.6.4 (2023-02-09) +++++++++++++++++++
1.6.3 (2022-10-27) +++++++++++++++++++
1.6.2 (2022-10-27) +++++++++++++++++++
1.6.1 (2022-10-11) +++++++++++++++++++
azure-c-shared-utility dependency by using CERT_STORE_ADD_REPLACE_EXISTING parameter in the CertAddEncodedCertificateToStore function call. (azure-sdk-for-python issue #26034)1.6.0 (2022-08-18) +++++++++++++++++++
This version and all future versions will require Python 3.7+, Python 3.6 is no longer supported.
data, value, sequence properties to uamqp.Message, which return the body if the body type corresponds.message_annotations property to uamqp.Message, which is an alias for the annotations instance variable.data property to uamqp.BatchMessage, which returns the iterable body of the batch.ttl property to uamqp.MessageHeader, which is an alias for the time_to_live instance variable.1.5.3 (2022-03-23) +++++++++++++++++++
1.5.2 (2022-03-15) +++++++++++++++++++
1.5.1 (2022-01-12) +++++++++++++++++++
1.5.0 (2022-01-05) +++++++++++++++++++
This version and all future versions will require Python 3.7+, Python 2.7 and Python 3.6 are no longer supported.
SASTokenAuth, JWTTokenAuth, SASTokenAsync, and JWTTokenAsync now takes keyword argument refresh_window to override default token refresh timing in constructors.SendClientAsync might run into infinite loop while sending when it is shutdown unexpectedly.2021-11-16 <https://github.com/Azure/azure-uamqp-c/tree/259db533a66a8fa6e9ac61c39a9dae880224145f>__ and Azure C Shared Utility @ 2021-11-15 <https://github.com/Azure/azure-c-shared-utility/tree/735be16a943c2a9cbbddef0543f871f5bc0e27ab>__.keep_alive_thread of AMQPClient should not keep program from exiting in the case of AMQPClient not being closed properly.1.4.3 (2021-10-06) +++++++++++++++++++
1.4.2 (2021-09-21) +++++++++++++++++++
1.4.1 (2021-06-28) +++++++++++++++++++
creation_time, absolute_expiry_time and group_sequence on MessageProperties should be compatible with integer types on Python 2.7.1.4.0 (2021-05-03) +++++++++++++++++++
This version and all future versions will require Python 2.7 or Python 3.6+, Python 3.5 is no longer supported.
1.3.0 (2021-04-05) +++++++++++++++++++
This version will be the last version to officially support Python 3.5, future versions will require Python 2.7 or Python 3.6+.
Added support for AMQP Sequence as the body type of an amqp message.
Added new class uamqp.MessageBodyType to represent the body type of an amqp message, including:
Data: The body consists of one or more data sections and each section contains opaque binary data.Sequence: The body consists of one or more sequence sections and each section contains an arbitrary number of structured data elements.Value: The body consists of one amqp-value section and the section contains a single AMQP value.Added new parameters to the constructor of uamqp.Message:
body_type which takes uamqp.MessageBodyType to specify the body type of an amqp message.footer which takes a dict to set the footer of an amqp message.delivery_annotations which takes a dict to set the delivery annotations of an amqp message.Added support for pickling uamqp.Message.
Fixed bug that sending message of large size triggering segmentation fault when the underlying socket connection is lost.
Fixed bug in link flow control where link credit and delivery count should be calculated based on per message instead of per transfer frame.
1.2.15 (2021-03-02) +++++++++++++++++++
SendClient(Async) and MessageSender(Async) as part of the AMQP protocol.1.2.14 (2021-02-01) +++++++++++++++++++
1.2.13 (2021-01-06) +++++++++++++++++++
MessageProperties.user_id triggering segmentation fault when the underlying C bytes are NULL.MessageProperties.user_id being limited to 8 bytes.ReceiveClient and ReceiveClientAsync receive messages during connection establishment.1.2.12 (2020-10-09) +++++++++++++++++++
1.2.11 (2020-10-01) +++++++++++++++++++
Message.footer and Message.delivery_annotation were not encoded into the outgoing payload.1.2.10 (2020-08-05) +++++++++++++++++++
shutdown_after_timeout to ReceiveClient and ReceiveClientAsync which gives control over whether to shutdown receiver after timeout.1.2.9 (2020-07-06) ++++++++++++++++++
MessageReceiver.reset_link_credit which is responsible for resetting current available link credit on the receiver link and send update to the sender.1.2.8 (2020-05-19) ++++++++++++++++++
1.2.7 (2020-05-04) ++++++++++++++++++
1.2.6 (2020-02-13) ++++++++++++++++++
1.2.5 (2019-12-10) ++++++++++++++++++
1.2.4 (2019-12-02) ++++++++++++++++++
ThreadPoolExecutor in ConnectionAsync.1.2.3 (2019-10-07) ++++++++++++++++++
ReceiveClient(Async) and MessageReceiver(Async) as part of the AMQP protocol.Message (azure-sdk-for-python issue #7336).work to MessageReceiver and work_async to MessageReceiverAsync responsible for updating link status.1.2.2 (2019-07-02) ++++++++++++++++++
1.2.1 (2019-06-20) ++++++++++++++++++
update_token() in JWTTokenAuth and JWTTokenAsync (issue #80).1.2.0 (2019-04-16) ++++++++++++++++++
JWTTokenAuth and JWTTokenAsync to support OAuth.1.1.0 (2018-11-12) ++++++++++++++++++
Support for Python 2.7 (>_<)/
TimeoutError is raised in Python 3.x, this will be replaced with a new ~uamqp.errors.ClientTimeout exception in Python 2.7.str object will be treated as bytes in Python 3 and a Python 2 unicode object will be treated like a Python 3 str.AMQP encoding of an integer type will now automatically failover into a Long type or a double type if the value is too large.
Improved support for promptly detecting invalid ATTACH handles and raising the appropriate error.
Added types for AMQPDescribed, AMQPInt and AMQPuInt for explicit handling of int and unsigned int encoding.
Added new error errors.AMQPClientShutdown as a wrapper for KeyboardInterrupt to better handle interrupt handling.
Added better handling of keyboard interrupts during C callbacks to better facilitate clean client shutdown.
Added additional handling of keyboard interrupt at the C level to clean up annoying warnings.
Added classmethod Message.decode_from_bytes to create a message from AMQP wire-encoded data.
Added Message.encode_message method to retrieve the AMQP wire-encoded byte representation of the current message.
Fixed behaviour of Message.get_message_encoded_size() to return accurate size.
Added new optional callback argument to client.mgmt_request to allow for custom handling of different status codes.
Added new client methods auth_complete() and client_ready() to allow for more fine-tuned monitoring or the client opening stages.
Client message handler is now a public attribute client.message_handler (SendClient._message_sender and ReceiveClient._message_receiver are now deprecated).
Added automatic encoding of datetime.datetime objects into AMQP timestamp.
Better support for Source filters with optional descriptor argument in Source.set_filter() and new Source.get_filter() method.
Fixed Session settings not being passed to CBS session.
Added support for a callback on receipt on a Link ATTACH frame. Can be supplied to a client through the on_attach keyword argument.
Removed unsued message.SequenceBody class.
Exposed BatchMessage.size_offset property for batch size customization.
1.0.3 (2018-09-14) ++++++++++++++++++
1.0.2 (2018-09-05) ++++++++++++++++++
1.0.1 (2018-08-29) ++++++++++++++++++
uamqp.send_message now returns a list of uamqp.constants.MessageState to indicate the success of each message sent.1.0.0 (2018-08-20) ++++++++++++++++++
API settled.
Behaviour change When a SendClient or SendClientAsync is shutdown, any remaining pending messages (that is messages
in the states WaitingToBeSent and WaitingForSendAck) will no longer be cleared, but can be retrieved from a new
attribute SendClient.pending_messages in order to be re-processed as needed.
Behaviour change The function SendClient.queue_message now allows for queueing multiple messages at once by simply
passing in additional message instances:
send_client.queue_message(my_message)send_client.queue_message(message_1, message_2, message_3)send_client.queue_message(*my_message_list)An authentication object will now raise a ValueError if one attempts to use it for more than one connection.
Renamed internal _async module to non-private async_ops to allow for docs generation.
Reformatted logging for better performance.
Added additional logging.
0.2.1 (2018-08-06) ++++++++++++++++++
0.2.0 (2018-07-25) ++++++++++++++++++
Breaking change MessageSender.send_async has been renamed to MessageSender.send, and
MessageSenderAsync.send_async is now a coroutine.
Breaking change Removed detach_received callback argument from MessageSender, MessageReceiver,
MessageSenderAsync, and MessageReceiverAsync in favour of new error_policy argument.
Added ErrorPolicy class to determine how the client should respond to both generic AMQP errors
and custom or vendor-specific errors. A default policy will be used, but a custom policy can
be added to any client by using a new error_policy argument. Value must be either an instance
or subclass of ErrorPolicy.
error_policy argument has also been added to MessageSender, MessageReceiver, Connection, and their
async counterparts to allow for handling of link DETACH and connection CLOSE events.constants.MESSAGE_SEND_RETRIES value which is now
deprecated.retry (a boolean to determine whether the error is retryable), backoff
(an integer to determine how long the client should wait before retrying, default is 0) and
increment_retries (a boolean to determine whether the error should count against the maximum
retry attempts, default is True). Currently backoff and increment_retries are only
considered for message send failures.VendorConnectionClose and VendorLinkDetach exceptions for non-standard (unrecognized)
connection/link errors.Added support for HTTP proxy configuration.
Added support for running async clients synchronously.
Added keep-alive support for connection - this is a background thread for a synchronous
client, and a background async function for an async client. The keep-alive feature is
disabled by default, to enable, set the keep_alive_interval argument on the client to
an integer representing the number of seconds between connection pings.
Added support for catching a Connection CLOSE event.
Added support for Connection.sleep and ConnectionAsync.sleep_async to pause the connection.
Added support for surfacing message disposition delivery-state (with error information).
Added constants.ErrorCodes enum to map standard AMQP error conditions. This replaces the previous
constants.ERROR_CONNECTION_REDIRECT and constants.ERROR_LINK_REDIRECT which are now both
deprecated.
Added new super error AMQPError from which all exceptions inherit.
Added new MessageHandlerError exception, a subclass of AMQPConnectionError, for
Senders/Receivers that enter an indeterminate error state.
MessageException is now a subclass of MessageResponse.
Added ClientMessageError exception, a subclass of MessageException for send errors raised client-side.
Catching Link DETACH event will now work regardless of whether service returns delivery-state.
Fixed bug where received messages attempting to settle on a detached link crashed the client.
Fixed bug in amqp C DescribedValue.
Fixed bug where client crashed on deallocating failed management operation.
0.1.1 (2018-07-14) ++++++++++++++++++
None rather than raising ValueError.0.1.0 (2018-07-05) ++++++++++++++++++
0.1.0rc2 (2018-07-02) +++++++++++++++++++++
Breaking change Submodule async has been renamed to the internal _async.
All asynchronous classes in the submodule can now be accessed from uamqp or uamqp.authentication directly.
Breaking change Anything returned by a callback supplied to receive messages will now be ignored.
Breaking change Changed message state enum values:
Complete -> SendCompleteFailed -> SendFailedWaitingForAck -> WaitingForSendAckAdded new message state enum values:
ReceivedUnsettledReceivedSettledBreaking change Changes to message settlement exceptions:
AbandonMessage and DeferMessage exceptions as MessageModified to be in keeping with the AMQP specification.AcceptMessage to MessageAccepted.RejectMessage to MessageRejected which now takes condition and description arguments rather than message.Added errors.LinkDetach exception as new subclass of AMQPConnectionError as a wrapped for data in a Link DETACH dispostition.
Added errors.LinkRedirect as a specific subclass of LinkDetach to decode the specific redirect fields of a Link Redirect response.
Added errors.MessageAlreadySettled exception for operations performed on a received message that has already returned a receipt dispostition.
Added errors.MessageReleased exception.
Added errors.ErrorResponse exception.
A received Message can now be explicitly settled through a set of new functions on the message:
Message.accept()Message.reject(condition:str, description:str)Message.release()Message.modify(failed:bool, deliverable:bool, annotations:dict)Added explicit auto_complete argument to ReceiveClient and ReceiveClientAsync. If auto_complete is set to False then all messages must be
explicitly "accepted" or "rejected" by the user otherwise they will timeout and be released. The default is True, which is the exiting behaviour for each receive mechanism:
ReceiveClient.receive_messages()) will be automatically "accepted" if no explicit response has been set on completion of the callback.ReceiveClient.receive_message_batch()) will by automatically "accepted" before being returned to the user.ReceiveClient.receive_message_iter()) will by automatically "accepted" if no explicit response has been set once the generator is incremented.Added new methods to clients and connections to allow to redirect to an alternative endpoint when a LinkRedirect exception is raised. The client redirect helper cannot be used for clients that use a shared connection - the clients must be closed before the connection can be redirected. New credentials must be supplied for the new endpoint. The new methods are:
uamqp.Connection.redirect(redirect_info, auth)uamqp.async.ConnectionAsync.redirect_async(redirect_info, auth)uamqp.SendClient.redirect(redirect_info, auth)uamqp.ReceiveClient.redirect(redirect_info, auth)uamqp.async.SendClientAsync.redirect_async(redirect_info, auth)uamqp.async.ReceiveClientAsync.redirect_async(redirect_info, auth)Added on_detach_received argument to Sender and Receiver classes to pass in callback to run on Link DETACH.
Removed automatic char encoding for strings of length 1, and added types.AMQPChar for explicit encoding.
Bumped uAMQP C version to 1.2.5
Bumped Azure C Shared Utility to 1.1.5
Fixed memory leaks in MessageProperties, MessageHeader and message annotations.
0.1.0rc1 (2018-05-29) +++++++++++++++++++++
header argument to Message and BatchMessage for setting a MessageHeader.0.1.0b5 (2018-04-27) ++++++++++++++++++++
verify option to authentication classes to allow setting custom certificate path (for Linux and OSX).0.1.0b4 (2018-04-19) ++++++++++++++++++++
0.1.0b3 (2018-04-14) ++++++++++++++++++++
0.1.0b2 (2018-04-06) ++++++++++++++++++++
receive_batch behaviour to return messages as soon as they're available.batch_size in receive_batch renamed to max_batch_size.application_properties decode error.0.1.0b1 (2018-03-24) ++++++++++++++++++++
0.1.0a3 (2018-03-19) ++++++++++++++++++++
0.1.0a2 (2018-03-12) ++++++++++++++++++++
0.1.0a1 (2018-03-04) ++++++++++++++++++++