azure.storage.queue.aio package

Module contents

class azure.storage.queue.aio.QueueClient(account_url: str, queue_name: str, credential: Optional[Any] = None, **kwargs: Any)[source]

Bases: azure.storage.queue._shared.base_client_async.AsyncStorageAccountHostsMixin, azure.storage.queue._queue_client.QueueClient

A client to interact with a specific Queue.

Parameters
  • account_url (str) – The URL to the storage account. In order to create a client given the full URI to the queue, use the from_queue_url() classmethod.

  • queue_name (str) – The name of the queue.

  • credential – The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, an account shared access key, or an instance of a TokenCredentials class from azure.identity.

Keyword Arguments
  • secondary_hostname (str) – The hostname of the secondary endpoint.

  • encode_policy – The encoding policy to use on outgoing messages. Default is not to encode messages. Other options include TextBase64EncodePolicy, BinaryBase64EncodePolicy or None.

  • decode_policy – The decoding policy to use on incoming messages. Default value is not to decode messages. Other options include TextBase64DecodePolicy, BinaryBase64DecodePolicy or None.

Example:

async clear_messages(**kwargs: Optional[Any]) → None[source]

Deletes all messages from the specified queue.

Keyword Arguments

timeout (int) – The server timeout, expressed in seconds.

Example:

async create_queue(**kwargs: Optional[Any]) → None[source]

Creates a new queue in the storage account.

If a queue with the same name already exists, the operation fails with a ResourceExistsError.

Keyword Arguments
  • metadata (dict(str,str)) – A dict containing name-value pairs to associate with the queue as metadata. Note that metadata names preserve the case with which they were created, but are case-insensitive when set or read.

  • timeout (int) – The server timeout, expressed in seconds.

Returns

None or the result of cls(response)

Return type

None

Raises

StorageErrorException

Example:

async delete_message(message: Any, pop_receipt: Optional[str] = None, **kwargs: Any) → None[source]

Deletes the specified message.

Normally after a client retrieves a message with the receive messages operation, the client is expected to process and delete the message. To delete the message, you must have the message object itself, or two items of data: id and pop_receipt. The id is returned from the previous receive_messages operation. The pop_receipt is returned from the most recent receive_messages() or update_message() operation. In order for the delete_message operation to succeed, the pop_receipt specified on the request must match the pop_receipt returned from the receive_messages() or update_message() operation.

Parameters
Keyword Arguments

timeout (int) – The server timeout, expressed in seconds.

Example:

async delete_queue(**kwargs: Optional[Any]) → None[source]

Deletes the specified queue and any messages it contains.

When a queue is successfully deleted, it is immediately marked for deletion and is no longer accessible to clients. The queue is later removed from the Queue service during garbage collection.

Note that deleting a queue is likely to take at least 40 seconds to complete. If an operation is attempted against the queue while it was being deleted, an HttpResponseError will be thrown.

Keyword Arguments

timeout (int) – The server timeout, expressed in seconds.

Return type

None

Example:

async get_queue_access_policy(**kwargs: Optional[Any]) → Dict[str, Any][source]

Returns details about any stored access policies specified on the queue that may be used with Shared Access Signatures.

Keyword Arguments

timeout (int) – The server timeout, expressed in seconds.

Returns

A dictionary of access policies associated with the queue.

Return type

dict(str, AccessPolicy)

async get_queue_properties(**kwargs: Optional[Any]) → QueueProperties[source]

Returns all user-defined metadata for the specified queue.

The data returned does not include the queue’s list of messages.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Returns

User-defined metadata for the queue.

Return type

QueueProperties

Example:

async peek_messages(max_messages: Optional[int] = None, **kwargs: Optional[Any]) → List[azure.storage.queue._models.QueueMessage][source]

Retrieves one or more messages from the front of the queue, but does not alter the visibility of the message.

Only messages that are visible may be retrieved. When a message is retrieved for the first time with a call to receive_messages(), its dequeue_count property is set to 1. If it is not deleted and is subsequently retrieved again, the dequeue_count property is incremented. The client may use this value to determine how many times a message has been retrieved. Note that a call to peek_messages does not increment the value of dequeue_count, but returns this value for the client to read.

If the key-encryption-key or resolver field is set on the local service object, the messages will be decrypted before being returned.

Parameters

max_messages (int) – A nonzero integer value that specifies the number of messages to peek from the queue, up to a maximum of 32. By default, a single message is peeked from the queue with this operation.

Keyword Arguments

timeout (int) – The server timeout, expressed in seconds.

Returns

A list of QueueMessage objects. Note that next_visible_on and pop_receipt will not be populated as peek does not pop the message and can only retrieve already visible messages.

Return type

list(QueueMessage)

Example:

receive_messages(**kwargs: Optional[Any]) → azure.core.async_paging.AsyncItemPaged[azure.storage.queue._models.QueueMessage][azure.storage.queue._models.QueueMessage][source]

Removes one or more messages from the front of the queue.

When a message is retrieved from the queue, the response includes the message content and a pop_receipt value, which is required to delete the message. The message is not automatically deleted from the queue, but after it has been retrieved, it is not visible to other clients for the time interval specified by the visibility_timeout parameter.

If the key-encryption-key or resolver field is set on the local service object, the messages will be decrypted before being returned.

Keyword Arguments
  • messages_per_page (int) – A nonzero integer value that specifies the number of messages to retrieve from the queue, up to a maximum of 32. If fewer are visible, the visible messages are returned. By default, a single message is retrieved from the queue with this operation.

  • visibility_timeout (int) – If not specified, the default value is 0. Specifies the new visibility timeout value, in seconds, relative to server time. The value must be larger than or equal to 0, and cannot be larger than 7 days. The visibility timeout of a message cannot be set to a value later than the expiry time. visibility_timeout should be set to a value smaller than the time-to-live value.

  • timeout (int) – The server timeout, expressed in seconds.

Returns

Returns a message iterator of dict-like Message objects.

Return type

AsyncItemPaged[QueueMessage]

Example:

async send_message(content: Any, **kwargs: Optional[Any]) → azure.storage.queue._models.QueueMessage[source]

Adds a new message to the back of the message queue.

The visibility timeout specifies the time that the message will be invisible. After the timeout expires, the message will become visible. If a visibility timeout is not specified, the default value of 0 is used.

The message time-to-live specifies how long a message will remain in the queue. The message will be deleted from the queue when the time-to-live period expires.

If the key-encryption-key field is set on the local service object, this method will encrypt the content before uploading.

Parameters

content (obj) – Message content. Allowed type is determined by the encode_function set on the service. Default is str. The encoded message can be up to 64KB in size.

Keyword Arguments
  • visibility_timeout (int) – If not specified, the default value is 0. Specifies the new visibility timeout value, in seconds, relative to server time. The value must be larger than or equal to 0, and cannot be larger than 7 days. The visibility timeout of a message cannot be set to a value later than the expiry time. visibility_timeout should be set to a value smaller than the time-to-live value.

  • time_to_live (int) – Specifies the time-to-live interval for the message, in seconds. The time-to-live may be any positive number or -1 for infinity. If this parameter is omitted, the default time-to-live is 7 days.

  • timeout (int) – The server timeout, expressed in seconds.

Returns

A QueueMessage object. This object is also populated with the content although it is not returned from the service.

Return type

QueueMessage

Example:

async set_queue_access_policy(signed_identifiers: Dict[str, azure.storage.queue._models.AccessPolicy], **kwargs: Optional[Any]) → None[source]

Sets stored access policies for the queue that may be used with Shared Access Signatures.

When you set permissions for a queue, the existing permissions are replaced. To update the queue’s permissions, call get_queue_access_policy() to fetch all access policies associated with the queue, modify the access policy that you wish to change, and then call this function with the complete set of data to perform the update.

When you establish a stored access policy on a queue, it may take up to 30 seconds to take effect. During this interval, a shared access signature that is associated with the stored access policy will throw an HttpResponseError until the access policy becomes active.

Parameters

signed_identifiers (dict(str, AccessPolicy)) – SignedIdentifier access policies to associate with the queue. This may contain up to 5 elements. An empty dict will clear the access policies set on the service.

Keyword Arguments

timeout (int) – The server timeout, expressed in seconds.

Example:

async set_queue_metadata(metadata: Optional[Dict[str, Any]] = None, **kwargs: Optional[Any]) → None[source]

Sets user-defined metadata on the specified queue.

Metadata is associated with the queue as name-value pairs.

Parameters

metadata (dict(str, str)) – A dict containing name-value pairs to associate with the queue as metadata.

Keyword Arguments

timeout (int) – The server timeout, expressed in seconds.

Example:

async update_message(message: Any, pop_receipt: int = None, content: Optional[str] = None, **kwargs: Optional[Any]) → azure.storage.queue._models.QueueMessage[source]

Updates the visibility timeout of a message. You can also use this operation to update the contents of a message.

This operation can be used to continually extend the invisibility of a queue message. This functionality can be useful if you want a worker role to “lease” a queue message. For example, if a worker role calls receive_messages() and recognizes that it needs more time to process a message, it can continually extend the message’s invisibility until it is processed. If the worker role were to fail during processing, eventually the message would become visible again and another worker role could process it.

If the key-encryption-key field is set on the local service object, this method will encrypt the content before uploading.

Parameters
  • message (str or QueueMessage) – The message object or id identifying the message to update.

  • pop_receipt (str) – A valid pop receipt value returned from an earlier call to the receive_messages() or update_message() operation.

  • content (obj) – Message content. Allowed type is determined by the encode_function set on the service. Default is str.

Keyword Arguments
  • visibility_timeout (int) – Specifies the new visibility timeout value, in seconds, relative to server time. The new value must be larger than or equal to 0, and cannot be larger than 7 days. The visibility timeout of a message cannot be set to a value later than the expiry time. A message can be updated until it has been deleted or has expired. The message object or message id identifying the message to update.

  • timeout (int) – The server timeout, expressed in seconds.

Returns

A QueueMessage object. For convenience, this object is also populated with the content, although it is not returned by the service.

Return type

QueueMessage

Example:

class azure.storage.queue.aio.QueueServiceClient(account_url: str, credential: Optional[Any] = None, **kwargs: Any)[source]

Bases: azure.storage.queue._shared.base_client_async.AsyncStorageAccountHostsMixin, azure.storage.queue._queue_service_client.QueueServiceClient

A client to interact with the Queue Service at the account level.

This client provides operations to retrieve and configure the account properties as well as list, create and delete queues within the account. For operations relating to a specific queue, a client for this entity can be retrieved using the get_queue_client() function.

Parameters
  • account_url (str) – The URL to the queue service endpoint. Any other entities included in the URL path (e.g. queue) will be discarded. This URL can be optionally authenticated with a SAS token.

  • credential – The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, an account shared access key, or an instance of a TokenCredentials class from azure.identity.

Keyword Arguments

secondary_hostname (str) – The hostname of the secondary endpoint.

Example:

async create_queue(name: str, metadata: Optional[Dict[str, str]] = None, **kwargs) → azure.storage.queue.aio._queue_client_async.QueueClient[source]

Creates a new queue under the specified account.

If a queue with the same name already exists, the operation fails. Returns a client with which to interact with the newly created queue.

Parameters
  • name (str) – The name of the queue to create.

  • metadata (dict(str, str)) – A dict with name_value pairs to associate with the queue as metadata. Example: {‘Category’: ‘test’}

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Return type

QueueClient

Example:

async delete_queue(queue: Union[QueueProperties, str], **kwargs) → None[source]

Deletes the specified queue and any messages it contains.

When a queue is successfully deleted, it is immediately marked for deletion and is no longer accessible to clients. The queue is later removed from the Queue service during garbage collection.

Note that deleting a queue is likely to take at least 40 seconds to complete. If an operation is attempted against the queue while it was being deleted, an HttpResponseError will be thrown.

Parameters

queue (str or QueueProperties) – The queue to delete. This can either be the name of the queue, or an instance of QueueProperties.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Return type

None

Example:

get_queue_client(queue: Union[QueueProperties, str], **kwargs: Optional[Any]) → QueueClient[source]

Get a client to interact with the specified queue.

The queue need not already exist.

Parameters

queue (str or QueueProperties) – The queue. This can either be the name of the queue, or an instance of QueueProperties.

Returns

A QueueClient object.

Return type

QueueClient

Example:

async get_service_properties(**kwargs: Optional[Any]) → Dict[str, Any][source]

Gets the properties of a storage account’s Queue service, including Azure Storage Analytics.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Returns

An object containing queue service properties such as analytics logging, hour/minute metrics, cors rules, etc.

Return type

Dict[str, Any]

Example:

async get_service_stats(**kwargs: Optional[Any]) → Dict[str, Any][source]

Retrieves statistics related to replication for the Queue service.

It is only available when read-access geo-redundant replication is enabled for the storage account.

With geo-redundant replication, Azure Storage maintains your data durable in two locations. In both locations, Azure Storage constantly maintains multiple healthy replicas of your data. The location where you read, create, update, or delete data is the primary storage account location. The primary location exists in the region you choose at the time you create an account via the Azure Management Azure classic portal, for example, North Central US. The location to which your data is replicated is the secondary location. The secondary location is automatically determined based on the location of the primary; it is in a second data center that resides in the same region as the primary location. Read-only access is available from the secondary location, if read-access geo-redundant replication is enabled for your storage account.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Returns

The queue service stats.

Return type

Dict[str, Any]

list_queues(name_starts_with: Optional[str] = None, include_metadata: Optional[bool] = False, **kwargs) → azure.core.async_paging.AsyncItemPaged[source]

Returns a generator to list the queues under the specified account.

The generator will lazily follow the continuation tokens returned by the service and stop when all queues have been returned.

Parameters
  • name_starts_with (str) – Filters the results to return only queues whose names begin with the specified prefix.

  • include_metadata (bool) – Specifies that queue metadata be returned in the response.

Keyword Arguments
  • results_per_page (int) – The maximum number of queue names to retrieve per API call. If the request does not specify the server will return up to 5,000 items.

  • timeout (int) – The server timeout, expressed in seconds. This function may make multiple calls to the service in which case the timeout value specified will be applied to each individual call.

Returns

An iterable (auto-paging) of QueueProperties.

Return type

AsyncItemPaged[QueueProperties]

Example:

async set_service_properties(analytics_logging: Optional[QueueAnalyticsLogging] = None, hour_metrics: Optional[Metrics] = None, minute_metrics: Optional[Metrics] = None, cors: Optional[List[CorsRule]] = None, **kwargs) → None[source]

Sets the properties of a storage account’s Queue service, including Azure Storage Analytics.

If an element (e.g. analytics_logging) is left as None, the existing settings on the service for that functionality are preserved.

Parameters
  • analytics_logging (QueueAnalyticsLogging) – Groups the Azure Analytics Logging settings.

  • hour_metrics (Metrics) – The hour metrics settings provide a summary of request statistics grouped by API in hourly aggregates for queues.

  • minute_metrics (Metrics) – The minute metrics settings provide request statistics for each minute for queues.

  • cors (list(CorsRule)) – You can include up to five CorsRule elements in the list. If an empty list is specified, all CORS rules will be deleted, and CORS will be disabled for the service.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Return type

None

Example: