Skip to main content

snippets_py

Integration

New integration from credential
azure_blob_client = yepcode.integration.azure_blob("credential-slug")
New integration from plain authentication data
from azure.storage.blob import BlobServiceClient

azure_blob_client = BlobServiceClient.from_connection_string(conn_str="your_connection_string");

Create Container

Create container
container_client = azure_blob_client.get_container_client("container-name")

create_container_response = container_client.create_container()
print('Create container successfully', create_container_response)

List Containers

List containers
containers = azure_blob_client.list_containers()
for container in containers:
print(f"Found container: {container['name']}")

Delete container

Delete container
container_client = azure_blob_client.get_container_client("container-name")

container_client.delete_container()
print('Deleted container!')

List Blobs

List blobs
container_client = azure_blob_client.get_container_client("container-name")

blobs = container_client.list_blobs()
for blob in blobs:
print(f"Found blob: {blob.name}")

Create Blob from String

Create blob from string
container_client = azure_blob_client.get_container_client("container-name")
block_blob_client = container_client.get_blob_client("blob-name")

content = "content"
upload_blob_response = block_blob_client.upload_blob(
content,
len(content)
)
print(f"Created block blob successfully: {upload_blob_response})

Create Blob from Stream

Create blob from stream
container_client = azure_blob_client.get_container_client("container-name")
block_blob_client = container_client.get_blob_client("blob-name")

block_blob_client.upload_blob(stream)
print("Created block blob successfully")

Read Blob Content

Read blob content
container_client = azure_blob_client.get_container_client("container-name")
blob_client = container_client.get_blob_client("blob-name")

download_block_response = blob_client.download_blob(encoding='UTF-8')
data = download_block_response.readall()

print(f"Blob contents: {data}")