Skip to main content

Microsoft Azure Service Bus Client Library for Python

Project description

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.

Compatibility

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

Features

  • 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

Installation

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

Usage

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,
                        shared_access_key_name=key_name,
                        shared_access_key_value=key_value)

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,
                        account_key=account_key,
                        issuer=issuer)

Sending and Receiving Messages

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

sbs.create_queue('taskqueue')

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:

sbs.create_topic('taskdiscussion')

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:

sbs.create_event_hub('myhub')

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

Release History

0.20.3 (2016-08-11)

News

  • #547 Add get dead letter path static methods to Python

  • #513 Add renew lock

Bugfixes

  • #628 Fix custom properties with double quotes

0.20.2 (2016-06-28)

Bugfixes

  • New header in Rest API which breaks the SDK #658 #657

0.20.1 (2015-09-14)

News

  • Create a requests.Session() if the user doesn’t pass one in.

0.20.0 (2015-08-31)

Initial release of this package, from the split of the azure package. See the azure package release note for 1.0.0 for details and previous history on service bus.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

azure-servicebus-0.20.3.zip (41.0 kB view details)

Uploaded Source

Built Distribution

azure_servicebus-0.20.3-py2.py3-none-any.whl (36.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file azure-servicebus-0.20.3.zip.

File metadata

File hashes

Hashes for azure-servicebus-0.20.3.zip
Algorithm Hash digest
SHA256 442bf44d32286cdaef71f75e03bcff912a7111f281462b9c4d560f77687684f7
MD5 4a21251928090e44341aacf1e71a2b9b
BLAKE2b-256 3897a0f9a44d2c9501329338ae252794c12939e70188a41d902c2717f26f7385

See more details on using hashes here.

File details

Details for the file azure_servicebus-0.20.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for azure_servicebus-0.20.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a6dec3d70478a21b40d0e2985bdbf99fd9dfb963a969199982d41aab55308524
MD5 b23a7c48632aa72a455f49b802eeb1f3
BLAKE2b-256 666d45edba471066fd8b1c7ae5b16bdbaa73965642b8c1e8abe999f6d6e029f9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page