{"id":2391,"date":"2023-01-24T12:28:00","date_gmt":"2023-01-24T20:28:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/azure-sdk\/?p=2391"},"modified":"2023-01-24T18:02:45","modified_gmt":"2023-01-25T02:02:45","slug":"announcing-the-stable-release-of-the-python-event-hubs-client-library-using-pure-python-amqp-stack","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/azure-sdk\/announcing-the-stable-release-of-the-python-event-hubs-client-library-using-pure-python-amqp-stack\/","title":{"rendered":"Announcing the stable release of the Python Event Hubs client library using pure Python AMQP stack"},"content":{"rendered":"<p>We&#8217;re excited to announce the stable release of the <a href=\"https:\/\/pypi.org\/project\/azure-eventhub\/5.11.0\/\">Event Hubs client library for Python<\/a> that uses a new AMQP library written entirely in Python. The client library:<\/p>\n<ul>\n<li>Is feature complete and available for download now.<\/li>\n<li>Continues to follow our <a href=\"https:\/\/aka.ms\/azsdk\/guide\">Azure SDK Guidelines<\/a>, making for an idiomatic, consistent, approachable, diagnosable, and dependable library.<\/li>\n<\/ul>\n<h2>Highlights and benefits<\/h2>\n<ul>\n<li>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.<\/li>\n<li>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.<\/li>\n<li>The new client library has improved event throughput performance, when compared to previous library versions.<\/li>\n<li>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.<\/li>\n<\/ul>\n<h2>Get started<\/h2>\n<h3>Install the client library<\/h3>\n<p>Install the Azure Events Hubs client library with pip in your Python environment:<\/p>\n<pre><code class=\"language-python\">pip install azure-eventhub&gt;=5.11.0<\/code><\/pre>\n<h3>Create an event hub<\/h3>\n<p>For instructions on creating an event hub, follow this <a href=\"https:\/\/learn.microsoft.com\/azure\/event-hubs\/event-hubs-create\">step-by-step guide<\/a>.<\/p>\n<h3>Create the client and send an event<\/h3>\n<p>To create a client in this example, an Event Hubs connection string will be required (obtained from the <a href=\"https:\/\/portal.azure.com\">Azure portal<\/a>). In a real-world production application, consider using passwordless authentication instead. For more information on passwordless authentication with Event Hubs, see <a href=\"https:\/\/learn.microsoft.com\/azure\/event-hubs\/event-hubs-python-get-started-send?toc=%2Fazure%2Fdeveloper%2Fintro%2Ftoc.json&#038;bc=%2Fazure%2Fdeveloper%2Fintro%2Fbreadcrumb%2Ftoc.json&#038;tabs=passwordless%2Croles-azure-portal#authenticate-the-app-to-azure\">Authenticate the app to Azure<\/a>:<\/p>\n<pre><code class=\"language-python\">from azure.eventhub import EventHubProducerClient, EventData\r\n\r\nconnection_str = '&lt;&lt; CONNECTION STRING FOR THE EVENT HUBS NAMESPACE &gt;&gt;'\r\neventhub_name = '&lt;&lt; NAME OF THE EVENT HUB &gt;&gt;'\r\nclient = EventHubProducerClient.from_connection_string(connection_str, eventhub_name=eventhub_name)\r\n\r\nevent_data_batch = client.create_batch()\r\ncan_add = True\r\nwhile can_add:\r\n    try:\r\n        event_data_batch.add(EventData('Message inside EventBatchData'))\r\n    except ValueError:\r\n        can_add = False  # EventDataBatch object reaches max_size.\r\n\r\nwith client:\r\n    client.send_batch(event_data_batch)<\/code><\/pre>\n<h3>Create the client and receive events<\/h3>\n<pre><code class=\"language-python\">from azure.eventhub import EventHubConsumerClient\r\n\r\nconnection_str = '&lt;&lt; CONNECTION STRING FOR THE EVENT HUBS NAMESPACE &gt;&gt;'\r\nconsumer_group = '&lt;&lt; CONSUMER GROUP &gt;&gt;'\r\neventhub_name = '&lt;&lt; NAME OF THE EVENT HUB &gt;&gt;'\r\nclient = EventHubConsumerClient.from_connection_string(connection_str, consumer_group, eventhub_name=eventhub_name)\r\n\r\ndef on_event(partition_context, event):\r\n    logger.info(\"Received event from partition {}\".format(partition_context.partition_id))\r\n    partition_context.update_checkpoint(event)\r\n\r\nwith client:\r\n    client.receive(\r\n        on_event=on_event,\r\n        starting_position=\"-1\",  # \"-1\" is from the beginning of the partition.\r\n    )<\/code><\/pre>\n<p>For examples of how to use the client library to send and receive events to\/from Event Hubs, see the <a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-python\/tree\/main\/sdk\/eventhub\/azure-eventhub\/samples\">samples<\/a> directory. Information about backwards compatibility with the older library can be found in the <a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-python\/tree\/main\/sdk\/eventhub\/azure-eventhub#pure-python-amqp-transport-and-backward-compatibility-support\">readme<\/a><\/p>\n<h2>Summary<\/h2>\n<p>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&#8217;ll have more updates on its progress soon.<\/p>\n<p>For feature requests, bug reports, or general support, <a href=\"https:\/\/github.com\/Azure\/azure-sdk-for-python\/issues\">open an issue<\/a> in the Azure SDK for Python repository. For more information on how we triage issues, see <a href=\"https:\/\/devblogs.microsoft.com\/azure-sdk\/github-issue-support-process\/\">Azure SDK GitHub Issue Support Process<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post announces the GA release of the Python library for Event Hubs, which uses a new AMQP library written purely in Python.<\/p>\n","protected":false},"author":21139,"featured_media":2402,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[823,750,703,785,162],"class_list":["post-2391","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure-sdk","tag-amqp","tag-azure-sdk","tag-clientlibraries","tag-event-hubs","tag-python"],"acf":[],"blog_post_summary":"<p>This post announces the GA release of the Python library for Event Hubs, which uses a new AMQP library written purely in Python.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sdk\/wp-json\/wp\/v2\/posts\/2391","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sdk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sdk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sdk\/wp-json\/wp\/v2\/users\/21139"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sdk\/wp-json\/wp\/v2\/comments?post=2391"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/azure-sdk\/wp-json\/wp\/v2\/posts\/2391\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sdk\/wp-json\/wp\/v2\/media\/2402"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sdk\/wp-json\/wp\/v2\/media?parent=2391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sdk\/wp-json\/wp\/v2\/categories?post=2391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sdk\/wp-json\/wp\/v2\/tags?post=2391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}