Prefect tasks and subflows for interacting with Azure
Project description
prefect-azure
Welcome!
prefect-azure is a collection of prebuilt Prefect tasks that can be used to quickly construct Prefect flows.
Getting Started
Python setup
Requires an installation of Python 3.7+
We recommend using a Python virtual environment manager such as pipenv, conda or virtualenv.
These tasks are designed to work with Prefect 2.0. For more information about how to use Prefect, please refer to the Prefect documentation.
Installation
Install prefect-azure
with pip
pip install prefect-azure
To use Blob Storage:
pip install "prefect-azure[blob_storage]"
To use Cosmos DB:
pip install "prefect-azure[cosmos_db]"
To use ML Datastore:
pip install "prefect-azure[ml_datastore]"
Then, register to view the block on Prefect Cloud:
prefect block register -m prefect_azure
Note, to use the load
method on Blocks, you must already have a block document saved through code or saved through the UI.
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()
Run a command on an Azure container instance
from prefect import flow
from prefect_azure import AzureContainerInstanceCredentials
from prefect_azure.container_instance import AzureContainerInstanceJob
@flow
def container_instance_job_flow():
aci_credentials = AzureContainerInstanceCredentials.load("MY_BLOCK_NAME")
container_instance_job = AzureContainerInstanceJob(
aci_credentials=aci_credentials,
resource_group_name="azure_resource_group.example.name",
subscription_id="<MY_AZURE_SUBSCRIPTION_ID>",
command=["echo", "hello world"],
)
return container_instance_job.run()
Use Azure Container Instance as infrastructure
If we have a_flow_module.py
:
from prefect import flow, get_run_logger
@flow
def log_hello_flow(name="Marvin"):
logger = get_run_logger()
logger.info(f"{name} said hello!")
if __name__ == "__main__":
log_hello_flow()
We can run that flow using an Azure Container Instance, but first create the infrastructure block:
from prefect_azure import AzureContainerInstanceCredentials
from prefect_azure.container_instance import AzureContainerInstanceJob
container_instance_job = AzureContainerInstanceJob(
aci_credentials=AzureContainerInstanceCredentials.load("MY_BLOCK_NAME"),
resource_group_name="azure_resource_group.example.name",
subscription_id="<MY_AZURE_SUBSCRIPTION_ID>",
)
container_instance_job.save("aci-dev")
Then, create the deployment either on the UI or through the CLI:
prefect deployment build a_flow_module.py:log_hello_flow --name aci-dev -ib container-instance-job/aci-dev
Visit Prefect Deployments for more information about deployments.
Resources
If you encounter and bugs while using prefect-azure
, feel free to open an issue in the prefect-azure repository.
If you have any questions or issues while using prefect-azure
, you can find help in either the Prefect Discourse forum or the Prefect Slack community
Feel free to ⭐️ or watch prefect-azure
for updates too!
Development
If you'd like to install a version of prefect-azure
for development, clone the repository and perform an editable install with pip
:
git clone https://github.com/PrefectHQ/prefect-azure.git
cd prefect-azure/
pip install -e ".[dev]"
# Install linting pre-commit hooks
pre-commit install
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for prefect_azure-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 156befb123a1a3e43319c97175d8e6091833ddc90a63f4723e858f291a541e24 |
|
MD5 | 403a902b80c95149a06266bcf79b7253 |
|
BLAKE2b-256 | 5bf01f2bbe6c80f700064a2808d6793982b5f8c50f44f0d62eae15a06278e18b |