Switch branches/tags
v2.0.0rc6 v2.0.0rc5 v2.0.0rc4 v2.0.0rc3 v2.0.0rc2 v2.0.0rc1 v2.0.0a1 v1.0.3 v1.0.2 v1.0.1 v1.0.0 v0.11.1 v0.11.0 v0.10.2 v0.10.0 v0.9.0 v0.8.4 v0.8.3 v0.8.2 azure_3.0.0 azure_2.0.0 azure-servicemanagement-legacy_0.20.6 azure-servicefabric_6.2.0.0 azure-servicefabric_6.1.2.9 azure-servicefabric_6.1.1.9 azure-servicefabric_6.0.2 azure-servicefabric_6.0.1 azure-servicefabric_6.0.0rc1 azure-servicefabric_6.0 azure-servicefabric_5.6.130 azure-servicebus_0.21.1 azure-servicebus_0.21.0 azure-monitor_0.3.1 azure-monitor_0.3.0 azure-monitor_0.2.0 azure-mgmt_2.0.0 azure-mgmt_1.0.0 azure-mgmt_1.0.0rc1 azure-mgmt-web_0.35.0 azure-mgmt-web_0.34.1 azure-mgmt-web_0.34.0 azure-mgmt-web_0.33.0 azure-mgmt-web_0.32.0 azure-mgmt-web_0.31.1 azure-mgmt-web_0.31.0 azure-mgmt-trafficmanager_0.50.0 azure-mgmt-trafficmanager_0.40.0 azure-mgmt-trafficmanager_0.30.0 azure-mgmt-subscription_0.2.0 azure-mgmt-subscription_0.1.0 azure-mgmt-storage_2.0.0rc4 azure-mgmt-storage_2.0.0rc3 azure-mgmt-storage_2.0.0rc2 azure-mgmt-storage_2.0.0rc1 azure-mgmt-storage_1.5.0 azure-mgmt-storage_1.4.0 azure-mgmt-storage_1.3.0 azure-mgmt-storage_1.2.1 azure-mgmt-storage_1.2.0 azure-mgmt-storage_1.1.0 azure-mgmt-storage_1.0.0 azure-mgmt-storage_1.0.0rc1 azure-mgmt-storage_0.31.0 azure-mgmt-sql_0.9.1 azure-mgmt-sql_0.9.0 azure-mgmt-sql_0.8.6 azure-mgmt-sql_0.8.5 azure-mgmt-sql_0.8.4 azure-mgmt-sql_0.8.3 azure-mgmt-sql_0.8.2 azure-mgmt-sql_0.8.1 azure-mgmt-sql_0.8.0 azure-mgmt-sql_0.7.1 azure-mgmt-sql_0.7.0 azure-mgmt-sql_0.6.0 azure-mgmt-sql_0.5.3 azure-mgmt-sql_0.5.2 azure-mgmt-sql_0.5.1 azure-mgmt-sql_0.5.0 azure-mgmt-sql_0.4.0 azure-mgmt-sql_0.3.3 azure-mgmt-sql_0.3.2 azure-mgmt-sql_0.3.1 azure-mgmt-sql_0.3.0 azure-mgmt-signalr_0.1.0 azure-mgmt-servicefabric_0.1.0 azure-mgmt-servicebus_0.5.1 azure-mgmt-servicebus_0.5.0 azure-mgmt-servicebus_0.4.0 azure-mgmt-servicebus_0.3.1 azure-mgmt-servicebus_0.3.0 azure-mgmt-servicebus_0.2.0 azure-mgmt-servermanager_2.0.0 azure-mgmt-servermanager_1.2.0 azure-mgmt-search_2.0.0 azure-mgmt-search_1.0.0 azure-mgmt-scheduler_2.0.0 azure-mgmt-scheduler_1.1.3 azure-mgmt-scheduler_1.1.2 azure-mgmt-scheduler_1.1.1
Nothing to show
Find file History


Microsoft Azure SDK for Python

This is the Microsoft Azure Service Bus Runtime Client Library.

This package has been tested with Python 2.7, 3.3, 3.4 and 3.5.

For a more complete set of Azure libraries, see the azure bundle package.


IMPORTANT: If you have an earlier version of the azure package (version < 1.0), you should uninstall it before installing this package.

You can check the version using pip:

pip freeze

If you see azure==0.11.0 (or any version below 1.0), uninstall it first:

pip uninstall azure


  • Queues: create, list and delete queues; create, list, and delete subscriptions; send, receive, unlock and delete messages
  • Topics: create, list, and delete topics; create, list, and delete rules
  • Event Hubs: create and delete event hubs; send events


Download Package

To install via the Python Package Index (PyPI), type:

pip install azure-servicebus

Download Source Code

To get the source code of the SDK via git type:

git clone https://github.com/Azure/azure-sdk-for-python.git
cd azure-sdk-for-python
cd azure-servicebus
python setup.py install


ServiceBus Queues

ServiceBus Queues are an alternative to Storage Queues that might be useful in scenarios where more advanced messaging features are needed (larger message sizes, message ordering, single-operation destructive reads, scheduled delivery) using push-style delivery (using long polling).

The service can use Shared Access Signature authentication, or ACS authentication.

Service bus namespaces created using the Azure portal after August 2014 no longer support ACS authentication. You can create ACS compatible namespaces with the Azure SDK.

Shared Access Signature Authentication

To use Shared Access Signature authentication, create the service bus service with:

from azure.servicebus import ServiceBusService

key_name = 'RootManageSharedAccessKey' # SharedAccessKeyName from Azure portal
key_value = '' # SharedAccessKey from Azure portal
sbs = ServiceBusService(service_namespace,

ACS Authentication

To use ACS authentication, create the service bus service with:

from azure.servicebus import ServiceBusService

account_key = '' # DEFAULT KEY from Azure portal
issuer = 'owner' # DEFAULT ISSUER from Azure portal
sbs = ServiceBusService(service_namespace,

Sending and Receiving Messages

The create_queue method can be used to ensure a queue exists:


The send_queue_message method can then be called to insert the message into the queue:

from azure.servicebus import Message

msg = Message('Hello World!')
sbs.send_queue_message('taskqueue', msg)

It is then possible to call the receive_queue_message method to dequeue the message.

msg = sbs.receive_queue_message('taskqueue')

ServiceBus Topics

ServiceBus topics are an abstraction on top of ServiceBus Queues that make pub/sub scenarios easy to implement.

The create_topic method can be used to create a server-side topic:


The send_topic_message method can be used to send a message to a topic:

from azure.servicebus import Message

msg = Message('Hello World!')
sbs.send_topic_message('taskdiscussion', msg)

A client can then create a subscription and start consuming messages by calling the create_subscription method followed by the receive_subscription_message method. Please note that any messages sent before the subscription is created will not be received.

from azure.servicebus import Message

sbs.create_subscription('taskdiscussion', 'client1')
msg = Message('Hello World!')
sbs.send_topic_message('taskdiscussion', msg)
msg = sbs.receive_subscription_message('taskdiscussion', 'client1')

Event Hub

Event Hubs enable the collection of event streams at high throughput, from a diverse set of devices and services.

The create_event_hub method can be used to create an event hub:


To send an event:

sbs.send_event('myhub', '{ "DeviceId":"dev-01", "Temperature":"37.0" }')

The event content is the event message or JSON-encoded string that contains multiple messages.

Need Help?

Be sure to check out the Microsoft Azure Developer Forums on Stack Overflow if you have trouble with the provided code.

Contribute Code or Provide Feedback

If you would like to become an active contributor to this project please follow the instructions provided in Microsoft Azure Projects Contribution Guidelines.

If you encounter any bugs with the library please file an issue in the Issues section of the project.

Learn More

Microsoft Azure Python Developer Center