Azure Event Hubs client library for Python Samples

These are code samples that show common scenario operations with the Azure Event Hubs client library. Both sync version and async version of samples are provided.

Prerequisites

  • Python 3.8 or later.

  • Microsoft Azure Subscription: To use Azure services, including Azure Event Hubs, you'll need a subscription. If you do not have an existing Azure account, you may sign up for a free trial or use your MSDN subscriber benefits when you create an account.

  • Event Hubs namespace with an Event Hub: To interact with Azure Event Hubs, you'll also need to have a namespace and Event Hub available. If you are not familiar with creating Azure resources, you may wish to follow the step-by-step guide for creating an Event Hub using the Azure portal. There, you can also find detailed instructions for using the Azure CLI, Azure PowerShell, or Azure Resource Manager (ARM) templates to create an Event Hub.

  • Azure Storage Account (Optional): To run receiving samples with blob checkpoint store for persist checkpoint, you need to create an Azure Storage account and a Blob Container.

Setup

  1. Install the Azure Event Hubs client library for Python with pip:
pip install azure-eventhub

To run samples that utilize the Azure Active Directory for authentication, please install the azure-identity library:

pip install azure-identity

To run receiving samples that utilize blob checkpoint store for persist checkpoint, please install the corresponding checkpoint store library:

pip install azure-eventhub-checkpointstoreblob  # sync version
pip install azure-eventhub-checkpointstoreblob-aio  # async version
  1. Clone or download this sample repository.
  2. Open the sample folder in Visual Studio Code or your IDE of choice.

Running the samples

  1. Open a terminal window and cd to the directory that the samples are saved in.
  2. Set the environment variables specified in the sample file you wish to run.
  3. Follow the usage described in the file, e.g. python send.py.

Next steps

Check out the API reference documentation to learn more about what you can do with the Azure Event Hubs client library.