Skip to main content

EventHub Python worker extension for Azure Functions.

Project description

Azure Functions Extensions Bindings EventHub library for Python

This library allows an EventHub Trigger binding in Python Function Apps to recognize and bind to the types from the Azure EventHub sdk (EventData).

EventHub types can be generated from:

Source code Package (PyPi) | API reference documentation | Product documentation | Samples

Getting started

Prerequisites

Install the package

Install the Azure Functions Extensions Bindings EventHub library for Python with pip:

pip install azurefunctions-extensions-bindings-eventhub

Create a storage account

If you wish to create a new storage account, you can use the Azure Portal, Azure PowerShell, or Azure CLI:

# Create a new resource group to hold the storage account -
# if using an existing resource group, skip this step
az group create --name my-resource-group --location westus2

# Create the storage account
az storage account create -n my-storage-account-name -g my-resource-group

Bind to the SDK-type

The Azure Functions Extensions Bindings EventHub library for Python allows you to create a function app with an EventHub Trigger and define the type as an EventData. Instead of receiving an EventHubEvent, when the function is executed, the type returned will be the defined SDK-type and have all of the properties and methods available as seen in the Azure EventHub library for Python.

import logging
import azure.functions as func
import azurefunctions.extensions.bindings.eventhub as eh

app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)

@app.event_hub_message_trigger(
    arg_name="event", event_hub_name="EVENTHUB_NAME", connection="AzureWebJobsStorage"
) 
def eventhub_trigger(event: eh.EventData):
    logging.info(
        "Python EventHub trigger processed an event %s",
        event.body_as_str()
    )


@app.event_hub_message_trigger(
    arg_name="events", event_hub_name="EVENTHUB_NAME", connection="AzureWebJobsStorage", cardinality="many"
)
def eventhub_trigger(events: List[eh.EventData]):
    for event in events:
        logging.info(
            "Python EventHub trigger processed an event %s",
            event.body_as_str()
        )

Troubleshooting

General

The SDK-types raise exceptions defined in Azure Core.

This list can be used for reference to catch thrown exceptions. To get the specific error code of the exception, use the error_code attribute, i.e, exception.error_code.

Next steps

More sample code

Get started with our EventHub samples.

Several samples are available in this GitHub repository. These samples provide example code for additional scenarios commonly encountered while working with EventHubs:

Additional documentation

For more information on the Azure EventHub SDK, see the Azure EventHub documentation on learn.microsoft.com and the Azure EventHub README.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

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

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file azurefunctions_extensions_bindings_eventhub-1.0.0b1.tar.gz.

File metadata

File hashes

Hashes for azurefunctions_extensions_bindings_eventhub-1.0.0b1.tar.gz
Algorithm Hash digest
SHA256 65e720c1568511fbac7c9cf33965bf950fc432cd184e994e68fe69422e69eb6c
MD5 0652f863ef262e9dc6633d2bb94986f4
BLAKE2b-256 f1461f1908d3c27e6f9dd13c8771d92365bc87853169fc0ff4538b755095a2dd

See more details on using hashes here.

File details

Details for the file azurefunctions_extensions_bindings_eventhub-1.0.0b1-py3-none-any.whl.

File metadata

File hashes

Hashes for azurefunctions_extensions_bindings_eventhub-1.0.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 773549959a3e7d5f2d1d709c33a729b547355499e797758abd7768d7fd3b1eea
MD5 d73cab935c61f2b43d7dfd27469245b4
BLAKE2b-256 ec3ce9c9934b6ebb501b617a7d7a63b8952124e8684b0b95f9678f845f8c608a

See more details on using hashes here.

Supported by

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