Azure Functions triggers and bindings enable you to easily integrate event and data sources with function applications. With SDK type bindings, you can use types from service SDKs and frameworks, providing more capability beyond what is currently offered. SDK type bindings for Azure Storage Blob when using Python in Azure Functions is now in Preview.
SDK type bindings for Azure Storage Blob enable the following key scenarios:
- Downloading and uploading blobs of large sizes, reducing current memory limitations and GRPC limits.
- Improved performance by using blobs with Azure Functions
To get started using SDK type bindings for Azure Storage Blob, the following prerequisites are required:
- Azure Functions runtime version 4.34.1, or a later version.
- Python version 3.9, or a later supported version.
- Python v2 programming model
Note that currently, only synchronous SDK types are supported.
Then, enable the feature in your Azure Function app:
- Add the
azurefunctions-extensions-bindings-blob
extension package to therequirements.txt
file in the project. - Add this code to the
function_app.py
file in the project, which imports the SDK type bindings:import azurefunctions.extensions.bindings.blob as blob
This example shows how to get the BlobClient
from both a Blob storage trigger (blob_trigger
) and from the input binding on an HTTP trigger (blob_input
).
import logging
import azure.functions as func
import azurefunctions.extensions.bindings.blob as blob
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
@app.blob_trigger(
arg_name="client", path="PATH/TO/BLOB", connection="AzureWebJobsStorage"
)
def blob_trigger(client: blob.BlobClient):
logging.info(
f"Python blob trigger function processed blob \n"
f"Properties: {client.get_blob_properties()}\n"
f"Blob content head: {client.download_blob().read(size=1)}"
)
@app.route(route="file")
@app.blob_input(
arg_name="client", path="PATH/TO/BLOB", connection="AzureWebJobsStorage"
)
def blob_input(req: func.HttpRequest, client: blob.BlobClient):
logging.info(
f"Python blob input function processed blob \n"
f"Properties: {client.get_blob_properties()}\n"
f"Blob content head: {client.download_blob().read(size=1)}"
)
return "ok"
You can view other SDK type bindings samples for Blob storage in the Python extensions repository:
Thanks for reading along! To learn more about SDK type bindings for Blob in Azure Functions using Python, checkout the developer reference guide. For questions and comments, create an issue in our Azure Functions Python GitHub repository.
Updated May 21, 2024
Version 1.0shreyab
Former Employee
Joined November 29, 2021
Azure Compute Blog
Follow this blog board to get notified when there's new activity