Skip to content

prefect-azure

prefect-azure makes it easy to leverage the capabilities of Azure in your workflows. For example, you can retrieve secrets, read and write Blob Storage objects, and deploy your flows on Azure Container Instances (ACI).

Getting Started

Prerequisites

Install prefect-azure for Prefect 2

pip install 'prefect[azure]<3'

If necessary, see additional installation options for Blob Storage, Cosmos DB, and ML Datastore.

To install with all additional functionality, use the following command:

pip install "prefect-azure[all_extras]<3"

Register newly installed block types

Register the block types in the module to make them available for use.

prefect block register -m prefect_azure

Examples

Download a blob

from prefect import flow

from prefect_azure import AzureBlobStorageCredentials
from prefect_azure.blob_storage import blob_storage_download

@flow
def example_blob_storage_download_flow():
    connection_string = "connection_string"
    blob_storage_credentials = AzureBlobStorageCredentials(
        connection_string=connection_string,
    )
    data = blob_storage_download(
        blob="prefect.txt",
        container="prefect",
        azure_credentials=blob_storage_credentials,
    )
    return data

example_blob_storage_download_flow()

Use with_options to customize options on any existing task or flow:

custom_blob_storage_download_flow = example_blob_storage_download_flow.with_options(
    name="My custom task name",
    retries=2,
    retry_delay_seconds=10,
)

Run flows on Azure Container Instances

Run flows on Azure Container Instances (ACI) to dynamically scale your infrastructure.

See the Azure Container Instances Worker Guide for a walkthrough of using ACI in a hybrid work pool.

If you're using Prefect Cloud, ACI push work pools provide all the benefits of ACI with a quick setup and no worker needed.

Resources

For assistance using Azure, consult the Azure documentation.

Refer to the prefect-azure API documentation linked in the sidebar to explore all the capabilities of the prefect-azure library.

Additional installation options

To use Blob Storage:

pip install "prefect-azure[blob_storage]<3"

To use Cosmos DB:

pip install "prefect-azure[cosmos_db]<3"

To use ML Datastore:

pip install "prefect-azure[ml_datastore]<3"