Azure Functions: SDK type bindings for Azure Blob Storage with Azure Functions in Python (Preview)
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 the requirements.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:
ContainerClient type
StorageStreamDownloader type
Microsoft Tech Community – Latest Blogs –Read More