-
Notifications
You must be signed in to change notification settings - Fork 4
Getting Started
These extensions allows for supported trigger and input types in Python Function Apps to recognize and bind to client types from the Azure SDK.
Supported binding types include:
- Blob Triggers
- Blob Input
-
Python 3.9 or later is required to use this package.
-
You must have an Azure subscription and an Azure storage account to use this package.
Install the Azure Functions Extension Blob library for Python with pip:
pip install azure-functions-extension-blob
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
The Azure Functions Extension Blob library for Python allows you to create a function app with a Blob Trigger or Blob Input and define the type as a BlobClient, ContainerClient, or StorageStreamDownloader. Instead of receiving an InputStream, 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 Storage Blob library for Python.
import logging
import azure.functions as func
import azure.functions.extension.blob as blob
@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: {client.download_blob(encoding="utf-8").readall()}")
@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: {client.download_blob(encoding="utf-8").readall()}")
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
.
Get started with our Blob samples.
Several samples are available in this GitHub repository. These samples provide example code for additional scenarios commonly encountered while working with Storage Blobs:
-
blob_samples_blobclient - Examples for using the BlobClient type:
- From BlobTrigger
- From BlobInput
-
blob_samples_containerclient - Examples for using the ContainerClient type:
- From BlobTrigger
- From BlobInput
-
blob_samples_storagestreamdownloader - Examples for using the StorageStreamDownloader type:
- From BlobTrigger
- From BlobInput
For more information on the Azure Storage Blob SDK, see the Azure Blob storage documentation on docs.microsoft.com and the Azure Storage Blobs README.