Introduce and Install Azurite
Azurite is a local emulator for Azure Storage. It provides a local environment for testing and developing with Azure Storage.
Reference:
Quick Start
- Install Azurite with docker
docker pull mcr.microsoft.com/azure-storage/azurite
- Run Azurite with docker
docker run -p 10000:10000 -p 10001:10001 -p 10002:10002 \
mcr.microsoft.com/azure-storage/azurite
``
3. Connect to Azurite with Storage Explorer
- Open Azure Storage Explorer
- Add a new connection
- Attach to local emulator
4. Use Azurite Python SDK to connect to Azurite
Install Azurite Python SDK
```bash
pip install azure-storage-blob
from azure.storage.blob import BlobServiceClient
import os
def test_generate_tests():
os.environ["AZURE_STORAGE_CONNECTION_STRING"] = (
"DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10022/devstoreaccount1;"
)
os.environ["STORAGE_CONTAINER"] = "test-container"
# Create a container for Azurite for the first run
blob_service_client = BlobServiceClient.from_connection_string(
os.environ.get(