GitHub Copilot ChatGPT Claude Codex CLI Cursor opencode Skill Text

azure-storage-queue-py

Azure Queue Storage SDK for Python. Use for reliable message queuing, task distribution, and asynchronous processing. Triggers: "queue storage", "QueueServiceClient", "QueueClient", "message queue", "dequeue".

Ciza · 0 points · 22 views 0 listing impressions 0 install-command copies
Virus-scanned Reviewed automatically before listing.

Full trust report

Download microsoft-skills-.github_plugins_azure-sdk-python_skills_azure-storage-queue-py-e58528d.zip · 4 KB
Part of microsoft/skills — 195 skills

Install

skills CLI npx skills add https://github.com/microsoft/skills/tree/main/.github/plugins/azure-sdk-python/skills/azure-storage-queue-py
Claude Code claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install microsoft-skills@llmmart
Git git clone https://github.com/microsoft/skills.git

The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole microsoft/skills collection as a plugin from our marketplace. Git is the plain clone.

Skill manifest

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  # Required for all auth methods
AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production

Authentication & Lifecycle

🔑 Two rules apply to every code sample below:

  1. Prefer DefaultAzureCredential. It works locally (Azure CLI / VS Code / Developer CLI) and in Azure (managed identity, workload identity) with no code change. Avoid connection strings, account/API keys — they bypass Entra audit and rotation.
    • Local dev: DefaultAzureCredential works as-is.
    • Production: set AZURE_TOKEN_CREDENTIALS=prod (or AZURE_TOKEN_CREDENTIALS=<specific_credential>) to constrain the credential chain to production-safe credentials.
  2. Wrap every client in a context manager so HTTP transports, sockets, and token caches are released deterministically:
    • Sync: with <Client>(...) as client:
    • Async: async with <Client>(...) as client: and async with DefaultAzureCredential() as credential: (from azure.identity.aio)

Snippets may abbreviate this setup, but production code should always follow both rules.

from azure.identity import DefaultAzureCredential, ManagedIdentityCredential
from azure.storage.queue import QueueServiceClient, QueueClient

# Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
credential = DefaultAzureCredential(require_envvar=True)
# Or use a specific credential directly in production:
# See https://learn.microsoft.com/python/api/overview/azure/identity-readme?view=azure-python#credential-classes
# credential = ManagedIdentityCredential()
account_url = "https://<account>.queue.core.windows.net"

# Service client
with QueueServiceClient(account_url=account_url, credential=credential) as service_client:
    # Use service_client here (see following sections for operations)
    ...

# Queue client
with QueueClient(account_url=account_url, queue_name="myqueue", credential=credential) as queue_client:
    # Use queue_client here (see following sections for operations)
    ...

Queue Operations

# Create queue
service_client.create_queue("myqueue")

# Get queue client
queue_client = service_client.get_queue_client("myqueue")

# Delete queue
service_client.delete_queue("myqueue")

# List queues
for queue in service_client.list_queues():
    print(queue.name)

Send Messages

# Send message (string)
queue_client.send_message("Hello, Queue!")

# Send with options
queue_client.send_message(
    content="Delayed message",
    visibility_timeout=60,  # Hidden for 60 seconds
    time_to_live=3600       # Expires in 1 hour
)

# Send JSON
import json
data = {"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}")
    print(f"Content: {message.content}")
    print(f"Dequeue count: {message.dequeue_count}")
    
    # Process message...
    
    # Delete after processing
    queue_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:
    print(message.content)

Update Message

# Extend visibility or update content
messages = queue_client.receive_messages()
for message in messages:
    # Extend timeout (need more time)
    queue_client.update_message(
        message,
        visibility_timeout=60
    )
    
    # Update content and timeout
    queue_client.update_message(
        message,
        content="Updated content",
        visibility_timeout=60
    )

Delete Message

# Delete after successful processing
messages = queue_client.receive_messages()
for message in messages:
    try:
        # Process...
        queue_client.delete_message(message)
    except Exception:
        # Message becomes visible again after timeout
        pass

Clear Queue

# Delete all messages
queue_client.clear_messages()

Queue Properties

# Get queue properties
properties = queue_client.get_queue_properties()
print(f"Approximate message count: {properties.approximate_message_count}")

# Set/get metadata
queue_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, QueueClient
from azure.identity.aio import DefaultAzureCredential

async def queue_operations():
    credential = DefaultAzureCredential()
    
    async with QueueClient(
        account_url="https://<account>.queue.core.windows.net",
        queue_name="myqueue",
        credential=credential
    ) as client:
        # Send
        await client.send_message("Async message")
        
        # Receive
        async for message in client.receive_messages():
            print(message.content)
            await client.delete_message(message)

import asyncio
asyncio.run(queue_operations())

Base64 Encoding

from azure.storage.queue import QueueClient, BinaryBase64EncodePolicy, BinaryBase64DecodePolicy

# For binary data
with QueueClient(
    account_url=account_url,
    queue_name="myqueue",
    credential=credential,
    message_encode_policy=BinaryBase64EncodePolicy(),
    message_decode_policy=BinaryBase64DecodePolicy()
) as queue_client:
    # Send bytes
    queue_client.send_message(b"Binary content")

Best Practices

  1. Pick sync OR async and stay consistent. Do not mix azure.xxx sync clients with azure.xxx.aio async clients in the same call path. Choose one mode per module.
  2. Always use context managers for clients and async credentials. Wrap every client in with Client(...) as client: (sync) or async with Client(...) as client: (async). For async DefaultAzureCredential from azure.identity.aio, also use async with credential: so tokens and transports are cleaned up.
  3. Use DefaultAzureCredential for portable auth across local dev and Azure (avoid connection strings / API keys when possible).
  4. Delete messages after processing to prevent reprocessing
  5. Set appropriate visibility timeout based on processing time
  6. Handle dequeue_count for poison message detection
  7. Use async client for high-throughput scenarios
  8. Use peek_messages for monitoring without affecting queue
  9. Set time_to_live to prevent stale messages
  10. Consider Service Bus for advanced features (sessions, topics)

Reference Files

File Contents
references/capabilities.md Additional non-hero capabilities, operation-group coverage, and production checklists.
references/non-hero-scenarios.md Dedicated non-hero examples for secondary/advanced scenarios.
Files (skills)
  • references
    • capabilities.md 1.8 KB
      # azure-storage-queue-py capability coverage
      
      **SDK/package**: `azure-storage-queue`
      
      This index maps hero scenarios in `SKILL.md` and links non-hero scenarios documented in dedicated reference files.
      
      ## Hero scenarios covered in SKILL.md
      
      - `Queue Operations`
      - `Send Messages`
      - `Receive Messages`
      - `Peek Messages`
      
      ## Non-hero scenarios
      
      - `Update Message`: Dedicated example and implementation notes.  
        See: [`non-hero-scenarios.md#update-message`](non-hero-scenarios.md#update-message)
      - `Delete Message`: Dedicated example and implementation notes.  
        See: [`non-hero-scenarios.md#delete-message`](non-hero-scenarios.md#delete-message)
      - `Clear Queue`: Dedicated example and implementation notes.  
        See: [`non-hero-scenarios.md#clear-queue`](non-hero-scenarios.md#clear-queue)
      - `Queue Properties`: Dedicated example and implementation notes.  
        See: [`non-hero-scenarios.md#queue-properties`](non-hero-scenarios.md#queue-properties)
      - `Async Client`: Dedicated example and implementation notes.  
        See: [`non-hero-scenarios.md#async-client`](non-hero-scenarios.md#async-client)
      - `Base64 Encoding`: Dedicated example and implementation notes.  
        See: [`non-hero-scenarios.md#base64-encoding`](non-hero-scenarios.md#base64-encoding)
      
      ## Related deep-dive references
      
      - [`non-hero-scenarios.md`](non-hero-scenarios.md): Dedicated non-hero examples and implementation notes.
      
      ## API breadth checklist
      
      - Verify client/auth mode for the environment before coding.
      - Confirm operation-group/method names against current Microsoft Learn API reference.
      - For Python SDKs with both sync and async clients, document both forms without a blanket preference.
      - Include cleanup/delete paths for created resources in examples.
      - Prefer idempotent create/update operations where available.
      - Validate paging/LRO/error-handling patterns for production paths.
      
    • non-hero-scenarios.md 2.6 KB
      # azure-storage-queue-py non-hero scenarios
      
      These scenarios are intentionally separate from hero flows in `SKILL.md`.
      They cover secondary/advanced patterns typically used after the primary end-to-end path is working.
      
      ## Update Message
      
      ```python
      # Extend visibility or update content
      messages = queue_client.receive_messages()
      for message in messages:
          # Extend timeout (need more time)
          queue_client.update_message(
              message,
              visibility_timeout=60
          )
          
          # Update content and timeout
          queue_client.update_message(
              message,
              content="Updated content",
              visibility_timeout=60
          )
      ```
      
      ## Delete Message
      
      ```python
      # Delete after successful processing
      messages = queue_client.receive_messages()
      for message in messages:
          try:
              # Process...
              queue_client.delete_message(message)
          except Exception:
              # Message becomes visible again after visibility timeout for retry.
              # Log the failure and re-raise so the caller is aware.
              raise
      ```
      
      ## Clear Queue
      
      ```python
      # Delete all messages
      queue_client.clear_messages()
      ```
      
      ## Queue Properties
      
      ```python
      # Get queue properties
      properties = queue_client.get_queue_properties()
      print(f"Approximate message count: {properties.approximate_message_count}")
      
      # Set/get metadata
      queue_client.set_queue_metadata(metadata={"environment": "production"})
      properties = queue_client.get_queue_properties()
      print(properties.metadata)
      ```
      
      ## Async Client
      
      ```python
      from azure.storage.queue.aio import QueueServiceClient, QueueClient
      from azure.identity.aio import DefaultAzureCredential
      
      async def queue_operations():
          async with DefaultAzureCredential() as credential:
              async with QueueClient(
                  account_url="https://<account>.queue.core.windows.net",
                  queue_name="myqueue",
                  credential=credential
              ) as client:
                  # Send
                  await client.send_message("Async message")
      
                  # Receive
                  async for message in client.receive_messages():
                      print(message.content)
                      await client.delete_message(message)
      
      import asyncio
      asyncio.run(queue_operations())
      ```
      
      ## Base64 Encoding
      
      ```python
      from azure.storage.queue import QueueClient, BinaryBase64EncodePolicy, BinaryBase64DecodePolicy
      
      # For binary data
      with QueueClient(
          account_url=account_url,
          queue_name="myqueue",
          credential=credential,
          message_encode_policy=BinaryBase64EncodePolicy(),
          message_decode_policy=BinaryBase64DecodePolicy()
      ) as queue_client:
          # Send bytes
          queue_client.send_message(b"Binary content")
      ```
      
  • SKILL.md 7.6 KB
    ---
    name: azure-storage-queue-py
    description: |
      Azure Queue Storage SDK for Python. Use for reliable message queuing, task distribution, and asynchronous processing.
      Triggers: "queue storage", "QueueServiceClient", "QueueClient", "message queue", "dequeue".
    license: MIT
    metadata:
      author: Microsoft
      version: "1.0.0"
      package: azure-storage-queue
    ---
    
    # Azure Queue Storage SDK for Python
    
    Simple, cost-effective message queuing for asynchronous communication.
    
    ## Installation
    
    ```bash
    pip install azure-storage-queue azure-identity
    ```
    
    ## Environment Variables
    
    ```bash
    AZURE_STORAGE_ACCOUNT_URL=https://<account>.queue.core.windows.net  # Required for all auth methods
    AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production
    ```
    
    ## Authentication & Lifecycle
    
    > **🔑 Two rules apply to every code sample below:**
    >
    > 1. **Prefer `DefaultAzureCredential`.** It works locally (Azure CLI / VS Code / Developer CLI) and in Azure (managed identity, workload identity) with no code change. Avoid connection strings, account/API keys — they bypass Entra audit and rotation.
    >    - Local dev: `DefaultAzureCredential` works as-is.
    >    - Production: set `AZURE_TOKEN_CREDENTIALS=prod` (or `AZURE_TOKEN_CREDENTIALS=<specific_credential>`) to constrain the credential chain to production-safe credentials.
    > 2. **Wrap every client in a context manager** so HTTP transports, sockets, and token caches are released deterministically:
    >    - Sync: `with <Client>(...) as client:`
    >    - Async: `async with <Client>(...) as client:` **and** `async with DefaultAzureCredential() as credential:` (from `azure.identity.aio`)
    >
    > Snippets may abbreviate this setup, but production code should always follow both rules.
    
    ```python
    from azure.identity import DefaultAzureCredential, ManagedIdentityCredential
    from azure.storage.queue import QueueServiceClient, QueueClient
    
    # Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
    credential = DefaultAzureCredential(require_envvar=True)
    # Or use a specific credential directly in production:
    # See https://learn.microsoft.com/python/api/overview/azure/identity-readme?view=azure-python#credential-classes
    # credential = ManagedIdentityCredential()
    account_url = "https://<account>.queue.core.windows.net"
    
    # Service client
    with QueueServiceClient(account_url=account_url, credential=credential) as service_client:
        # Use service_client here (see following sections for operations)
        ...
    
    # Queue client
    with QueueClient(account_url=account_url, queue_name="myqueue", credential=credential) as queue_client:
        # Use queue_client here (see following sections for operations)
        ...
    ```
    
    ## Queue Operations
    
    ```python
    # Create queue
    service_client.create_queue("myqueue")
    
    # Get queue client
    queue_client = service_client.get_queue_client("myqueue")
    
    # Delete queue
    service_client.delete_queue("myqueue")
    
    # List queues
    for queue in service_client.list_queues():
        print(queue.name)
    ```
    
    ## Send Messages
    
    ```python
    # Send message (string)
    queue_client.send_message("Hello, Queue!")
    
    # Send with options
    queue_client.send_message(
        content="Delayed message",
        visibility_timeout=60,  # Hidden for 60 seconds
        time_to_live=3600       # Expires in 1 hour
    )
    
    # Send JSON
    import json
    data = {"task": "process", "id": 123}
    queue_client.send_message(json.dumps(data))
    ```
    
    ## Receive Messages
    
    ```python
    # 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}")
        print(f"Content: {message.content}")
        print(f"Dequeue count: {message.dequeue_count}")
        
        # Process message...
        
        # Delete after processing
        queue_client.delete_message(message)
    ```
    
    ## Peek Messages
    
    ```python
    # Peek without hiding (doesn't affect visibility)
    messages = queue_client.peek_messages(max_messages=5)
    
    for message in messages:
        print(message.content)
    ```
    
    ## Update Message
    
    ```python
    # Extend visibility or update content
    messages = queue_client.receive_messages()
    for message in messages:
        # Extend timeout (need more time)
        queue_client.update_message(
            message,
            visibility_timeout=60
        )
        
        # Update content and timeout
        queue_client.update_message(
            message,
            content="Updated content",
            visibility_timeout=60
        )
    ```
    
    ## Delete Message
    
    ```python
    # Delete after successful processing
    messages = queue_client.receive_messages()
    for message in messages:
        try:
            # Process...
            queue_client.delete_message(message)
        except Exception:
            # Message becomes visible again after timeout
            pass
    ```
    
    ## Clear Queue
    
    ```python
    # Delete all messages
    queue_client.clear_messages()
    ```
    
    ## Queue Properties
    
    ```python
    # Get queue properties
    properties = queue_client.get_queue_properties()
    print(f"Approximate message count: {properties.approximate_message_count}")
    
    # Set/get metadata
    queue_client.set_queue_metadata(metadata={"environment": "production"})
    properties = queue_client.get_queue_properties()
    print(properties.metadata)
    ```
    
    ## Async Client
    
    ```python
    from azure.storage.queue.aio import QueueServiceClient, QueueClient
    from azure.identity.aio import DefaultAzureCredential
    
    async def queue_operations():
        credential = DefaultAzureCredential()
        
        async with QueueClient(
            account_url="https://<account>.queue.core.windows.net",
            queue_name="myqueue",
            credential=credential
        ) as client:
            # Send
            await client.send_message("Async message")
            
            # Receive
            async for message in client.receive_messages():
                print(message.content)
                await client.delete_message(message)
    
    import asyncio
    asyncio.run(queue_operations())
    ```
    
    ## Base64 Encoding
    
    ```python
    from azure.storage.queue import QueueClient, BinaryBase64EncodePolicy, BinaryBase64DecodePolicy
    
    # For binary data
    with QueueClient(
        account_url=account_url,
        queue_name="myqueue",
        credential=credential,
        message_encode_policy=BinaryBase64EncodePolicy(),
        message_decode_policy=BinaryBase64DecodePolicy()
    ) as queue_client:
        # Send bytes
        queue_client.send_message(b"Binary content")
    ```
    
    ## Best Practices
    
    1. **Pick sync OR async and stay consistent.** Do not mix `azure.xxx` sync clients with `azure.xxx.aio` async clients in the same call path. Choose one mode per module.
    2. **Always use context managers for clients and async credentials.** Wrap every client in `with Client(...) as client:` (sync) or `async with Client(...) as client:` (async). For async `DefaultAzureCredential` from `azure.identity.aio`, also use `async with credential:` so tokens and transports are cleaned up.
    3. **Use `DefaultAzureCredential`** for portable auth across local dev and Azure (avoid connection strings / API keys when possible).
    4. **Delete messages after processing** to prevent reprocessing
    5. **Set appropriate visibility timeout** based on processing time
    6. **Handle `dequeue_count`** for poison message detection
    7. **Use async client** for high-throughput scenarios
    8. **Use `peek_messages`** for monitoring without affecting queue
    9. **Set `time_to_live`** to prevent stale messages
    10. **Consider Service Bus** for advanced features (sessions, topics)
    
    ## Reference Files
    
    | File | Contents |
    |------|----------|
    | [references/capabilities.md](references/capabilities.md) | Additional non-hero capabilities, operation-group coverage, and production checklists. |
    | [references/non-hero-scenarios.md](references/non-hero-scenarios.md) | Dedicated non-hero examples for secondary/advanced scenarios. |
    

Comments (0)

Sign in to join the conversation.

No comments yet.

Reviews (0)

No reviews yet.

Related