Azure Storage Blob client library for Python Samples
These are code samples that show common scenario operations with the Azure Storage Blob client library.
The async versions of the samples (the python sample files appended with _async
) show asynchronous operations.
Several Storage Blobs Python SDK samples are available to you in the SDK's GitHub repository. These samples provide example code for additional scenarios commonly encountered while working with Storage Blobs:
blob_samples_hello_world.py (async version) - Examples for common Storage Blob tasks:
- Set up a container
- Create a block, page, or append blob
- Upload blobs
- Download blobs
- Delete blobs
blob_samples_authentication.py (async version) - Examples for authenticating and creating the client:
- From a connection string
- From a shared access key
- From a shared access signature token
- From active directory
blob_samples_service.py (async version) - Examples for interacting with the blob service:
- Get account information
- Get and set service properties
- Get service statistics
- Create, list, and delete containers
- Get the Blob or Container client
blob_samples_containers.py (async version) - Examples for interacting with containers:
- Create a container and delete containers
- Set metadata on containers
- Get container properties
- Acquire a lease on container
- Set an access policy on a container
- Upload, list, delete blobs in container
- Get the blob client to interact with a specific blob
blob_samples_common.py (async version) - Examples common to all types of blobs:
- Create a snapshot
- Delete a blob snapshot
- Soft delete a blob
- Undelete a blob
- Acquire a lease on a blob
- Copy a blob from a URL
blob_samples_directory_interface.py - Examples for interfacing with Blob storage as if it were a directory on a filesystem:
- Copy (upload or download) a single file or directory
- List files or directories at a single level or recursively
- Delete a single file or recursively delete a directory
blob_samples_batch_delete_blobs.py - Examples for batch deleting blobs
- Delete multiple blobs at the same time.
blob_samples_container_access_policy.py (async version) - Examples to get and set access policies:
- Get and Set container Access Policy
blob_samples_copy_blob.py (async version) - Examples to start and abort copy:
- Start a copy from url and abort it.
blob_samples_enumerate_blobs.py (async version) - Example to enumerate blobs
- List all the blobs in a container.
blob_samples_walk_blob_hierarchy.py (async version) - Example to walk through containers and blobs in a hierarchical structure.
- Walk through the container.
blob_samples_network_activity_logging.py - Examples to enable logging to the console.
- Log the network activity at different levels.
blob_samples_proxy_configuration.py - Examples to work with a proxy.
- Work with a proxy using the storage account.
forecasting_in_vs_code_with_blob.ipynb - An end-to-end sample and writeup on leveraging blobs as part of an Azure data infrastructure.
- Integrate blob with other Azure Services such as App Insights, and utilize it as a tool for data experimentation.
Prerequisites
- Python 3.6 or later is required to use this package
- You must have an Azure subscription and an Azure storage account to run these samples.
Setup
- Install the Azure Storage Blob client library for Python with pip:
pip install azure-storage-blob
- Clone or download this sample repository
- Open the sample folder in Visual Studio Code or your IDE of choice.
Running the samples
- Open a terminal window and
cd
to the directory that the samples are saved in. - Set the environment variables specified in the sample file you wish to run.
- Follow the usage described in the file, e.g.
python blob_samples_hello_world.py
Next steps
Check out the API reference documentation to learn more about what you can do with the Azure Storage Blob client library.