Skip to main content

Blob Python worker extension for Azure Functions.

Project description

Azure Functions Extensions Bindings Blob library for Python

This library allows Blob Trigger and Blob Input bindings in Python Function Apps to recognize and bind to client types from the Azure Storage Blob sdk.

Blob client types can be generated from:

  • Blob Triggers
  • Blob Input

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

Getting started

Prerequisites

Install the package

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

pip install azurefunctions-extensions-bindings-blob

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 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 azurefunctions.extensions.bindings.blob as blob

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

@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(encoding="utf-8").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(encoding="utf-8").read(size=1)}")

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 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:

Additional documentation

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.

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

victoria_test_blob_ext-1.0.3.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

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

victoria_test_blob_ext-1.0.3-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file victoria_test_blob_ext-1.0.3.tar.gz.

File metadata

  • Download URL: victoria_test_blob_ext-1.0.3.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for victoria_test_blob_ext-1.0.3.tar.gz
Algorithm Hash digest
SHA256 f48510f6eb42f8da7e0b9c2bb088a299419b6d8f205029f19ebf31320dece942
MD5 dba6968c6f4e41d6c4c30ae791ee4a40
BLAKE2b-256 38a49111121bdb9fe288c5a0e90034c889e9a7071604ccf3c0731107aa29d73b

See more details on using hashes here.

File details

Details for the file victoria_test_blob_ext-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for victoria_test_blob_ext-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 96e5958118f7504724101b4d4af0543a5576784a405ea300651f24da16bb8a7b
MD5 4420e308edc1d2e369a81abfddc78f8c
BLAKE2b-256 dda19991f9fbb1b8dea2933af92ca6fd5d3cb80d2ca40342b63d3950c1f47a74

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