Announcing the stable release of the Python Event Hubs client library using pure Python AMQP stack

Kashif Khan

We’re excited to announce the stable release of the Event Hubs client library for Python that uses a new AMQP library written entirely in Python. The client library:

  • Is feature complete and available for download now.
  • Continues to follow our Azure SDK Guidelines, making for an idiomatic, consistent, approachable, diagnosable, and dependable library.

Highlights and benefits

  • The new client library allows us to provide full multi-platform support, including ARM processors (Apple M1 etc.) and x86, without having to build separate wheels for individual platforms. The Event Hubs client library can now be integrated into a project like Home Assistant running on a Raspberry Pi.
  • A client library written all in Python has improved stability, robustness and maintenance, reducing any risks of C-related memory leaks or segmentation fault errors. An added benefit is that it also makes it easier for customers to interact and contribute back to the source code.
  • The new client library has improved event throughput performance, when compared to previous library versions.
  • The client library was designed to be a drop-in replacement with no breaking changes, making the transition to this new version seamless for projects already using it.

Get started

Install the client library

Install the Azure Events Hubs client library with pip in your Python environment:

pip install azure-eventhub>=5.11.0

Create an event hub

For instructions on creating an event hub, follow this step-by-step guide.

Create the client and send an event

To create a client in this example, an Event Hubs connection string will be required (obtained from the Azure portal). In a real-world production application, consider using passwordless authentication instead. For more information on passwordless authentication with Event Hubs, see Authenticate the app to Azure:

from azure.eventhub import EventHubProducerClient, EventData

connection_str = '<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>'
eventhub_name = '<< NAME OF THE EVENT HUB >>'
client = EventHubProducerClient.from_connection_string(connection_str, eventhub_name=eventhub_name)

event_data_batch = client.create_batch()
can_add = True
while can_add:
    try:
        event_data_batch.add(EventData('Message inside EventBatchData'))
    except ValueError:
        can_add = False  # EventDataBatch object reaches max_size.

with client:
    client.send_batch(event_data_batch)

Create the client and receive events

from azure.eventhub import EventHubConsumerClient

connection_str = '<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>'
consumer_group = '<< CONSUMER GROUP >>'
eventhub_name = '<< NAME OF THE EVENT HUB >>'
client = EventHubConsumerClient.from_connection_string(connection_str, consumer_group, eventhub_name=eventhub_name)

def on_event(partition_context, event):
    logger.info("Received event from partition {}".format(partition_context.partition_id))
    partition_context.update_checkpoint(event)

with client:
    client.receive(
        on_event=on_event,
        starting_position="-1",  # "-1" is from the beginning of the partition.
    )

For examples of how to use the client library to send and receive events to/from Event Hubs, see the samples directory. Information about backwards compatibility with the older library can be found in the readme

Summary

We encourage you to use this new version and we welcome your feedback. Similar work to move on to the new AMQP library will be starting for the Service Bus client library. We’ll have more updates on its progress soon.

For feature requests, bug reports, or general support, open an issue in the Azure SDK for Python repository. For more information on how we triage issues, see Azure SDK GitHub Issue Support Process.

4 comments

Discussion is closed. Login to edit/delete existing comments.

  • Ana William 1

    Thank you!

  • Marek Pavelka 0

    Hello,

    Is there any time estimate when the pure Python AMQP stack will be integrated in to the Python Service Bus library?

    best regards,
    Marek

    • Kashif KhanMicrosoft employee 0

      Hi Marek, we have just started the work on moving Service Bus over to the Python AMQP stack as we were focused on completing Event Hubs first. We are planning to release a beta shortly and will have a better idea around timelines for GA as it progresses through our internal testing for functionality parity, performance etc. We do mention beta releases in the monthly updates for the SDKs and it will be included in there.

    • Kashif KhanMicrosoft employee 0

      Hi Marek, we have released a beta version of servicebus which now uses pyamqp. Appreciate any feedback or bug reports 🙂

Feedback usabilla icon