Using Azure Python SDK with Event Hubs

Python is a beautiful and powerful language. Many times in just a few lines of code you can accomplish amazing things. Following the Python mindset, the Azure team has provided an easy to use Python API for the Azure Service Bus.

But until recently it only worked with Queues and Topics. Interacting with the Event Hubs using Python required us to write pure rest calls, which worked fine but is not as clean and simple as python libraries usually are. But rejoice becuase this is no longer the case!

Azure SDK with Event Hubs

After some digging for my wood stove project, I found the latest release of the Python Azure SDK (version 0.11 on May 13, 2015) now includes a simple SDK to send events to the Event Hub:

from azure.servicebus import ServiceBusService

sbs = ServiceBusService(api_key["namespace"], shared_access_key_name=api_key["policy_name"], shared_access_key_value=api_key["policy_secret"])

sbs.send_event('eventhubname', '{ "DeviceId":"deviceId1", "Temperature":"10.0" }')

Conclusion

In just three lines of code we have enabled a python client to send data to an incredibly powerful Event Hubs ingestion service. You can see a full Internet of Things (IoT) example using the Azure Python library at my wood stove github project and you can find the documentation for the Azure Python API here.

Comments

comments powered by Disqus