Skill v1.0.1
currentAutomated scan100/100+4 new
version: "1.0.1" name: azure-storage-queue-py description: Azure Queue Storage SDK for Python. Use for reliable message queuing, task distribution, and asynchronous processing. risk: critical source: community date_added: '2026-02-27'
Azure Queue Storage SDK for Python
Simple, cost-effective message queuing for asynchronous communication.
Installation
pip install azure-storage-queue azure-identity
Environment Variables
AZURE_STORAGE_ACCOUNT_URL=https://<account>.queue.core.windows.net
Authentication
from azure.identity import DefaultAzureCredentialfrom azure.storage.queue import QueueServiceClient, QueueClientcredential = DefaultAzureCredential()account_url = "https://<account>.queue.core.windows.net"# Service clientservice_client = QueueServiceClient(account_url=account_url, credential=credential)# Queue clientqueue_client = QueueClient(account_url=account_url, queue_name="myqueue", credential=credential)
Examples are independent fragments, not a run-all script. Confirm account/queue and whether reads may change visibility; use peek for observational checks. Receiving/deleting/clearing impacts other consumers and needs explicit scope. Bound message count/time/bytes, handle poison messages, and make processing idempotent because delivery can repeat. Do not delete a message until durable processing succeeds; replace placeholder processing before execution. Preserve the latest pop receipt after updates and reconcile ambiguous outcomes before retrying. Close both async clients and credentials in failure paths.
Queue Operations
# Create queueservice_client.create_queue("myqueue")# Get queue clientqueue_client = service_client.get_queue_client("myqueue")# Delete queueservice_client.delete_queue("myqueue")# List queuesfor queue in service_client.list_queues():print(queue.name)
Send Messages
# Send message (string)queue_client.send_message("Hello, Queue!")# Send with optionsqueue_client.send_message(content="Delayed message",visibility_timeout=60, # Hidden for 60 secondstime_to_live=3600 # Expires in 1 hour)# Send JSONimport jsondata = {"task": "process", "id": 123}queue_client.send_message(json.dumps(data))
Receive Messages
# Receive messages (makes them invisible temporarily)messages = queue_client.receive_messages(messages_per_page=10,visibility_timeout=30 # 30 seconds to process)for message in messages:print(f"ID: {message.id}")# Do not log message payloads.print(f"Dequeue count: {message.dequeue_count}")# Process message...# Delete after processingqueue_client.delete_message(message)
Peek Messages
# Peek without hiding (doesn't affect visibility)messages = queue_client.peek_messages(max_messages=5)for message in messages:# Inspect only authorized synthetic content; do not log payloads.
Update Message
# Extend visibility or update contentmessages = queue_client.receive_messages()for message in messages:# Extend timeout (need more time)queue_client.update_message(message,visibility_timeout=60)# Update content and timeoutqueue_client.update_message(message,content="Updated content",visibility_timeout=60)
Delete Message
# Delete after successful processingmessages = queue_client.receive_messages()for message in messages:try:# Process...queue_client.delete_message(message)except Exception:# Message becomes visible again after timeoutpass
Clear Queue
# Delete all messagesqueue_client.clear_messages()
Queue Properties
# Get queue propertiesproperties = queue_client.get_queue_properties()print(f"Approximate message count: {properties.approximate_message_count}")# Set/get metadataqueue_client.set_queue_metadata(metadata={"environment": "production"})properties = queue_client.get_queue_properties()print(properties.metadata)
Async Client
from azure.storage.queue.aio import QueueServiceClient, QueueClientfrom azure.identity.aio import DefaultAzureCredentialasync def queue_operations():credential = DefaultAzureCredential()async with QueueClient(account_url="https://<account>.queue.core.windows.net",queue_name="myqueue",credential=credential) as client:# Sendawait client.send_message("Async message")# Receiveasync for message in client.receive_messages():# Inspect only authorized synthetic content; do not log payloads.await client.delete_message(message)import asyncioasyncio.run(queue_operations())
Base64 Encoding
from azure.storage.queue import QueueClient, BinaryBase64EncodePolicy, BinaryBase64DecodePolicy# For binary dataqueue_client = QueueClient(account_url=account_url,queue_name="myqueue",credential=credential,message_encode_policy=BinaryBase64EncodePolicy(),message_decode_policy=BinaryBase64DecodePolicy())# Send bytesqueue_client.send_message(b"Binary content")
Best Practices
- Delete messages after processing to prevent reprocessing
- Set appropriate visibility timeout based on processing time
- Handle `dequeue_count` for poison message detection
- Use async client for high-throughput scenarios
- Use `peek_messages` for monitoring without affecting queue
- Set `time_to_live` to prevent stale messages
- Consider Service Bus for advanced features (sessions, topics)
When to Use
This skill is applicable to execute the workflow or actions described in the overview.
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.