Skip to main content

Python asynchronous and lightweight SQS client.

Project description

aiosqs

pypi

Python asynchronous and lightweight SQS client. The goal of this library is to provide fast and optimal access to SQS for Python projects, e.g. when you need a high-load queue consumer or high-load queue producer written in Python.

Supports Python versions 3.8, 3.9, 3.10, 3.11, 3.12.

Supported and tested Amazon-like SQS providers: Amazon, VK Cloud.


Why aiosqs?

Main problem of botocore and aiobotocore is huge memory and CPU consumption. Also aiobotocore itself is a transition of botocore to async interface without any optimizations.

Related issues:

Installation

Install package:

pip install aiosqs

Usage

Create a client:

from aiosqs import SQSClient

client = SQSClient(
    aws_access_key_id="access_key_id",
    aws_secret_access_key="secret_access_key",
    region_name="us-west-2",
    host="sqs.us-west-2.amazonaws.com",
)

Receive the queue url by queue name:

response = await client.get_queue_url(queue_name=queue_name)
queue_url = response["QueueUrl"]

Send a message to the queue:

response = await client.send_message(
    queue_url=queue_url,
    message_body=json.dumps({"demo": 1, "key": "value"}),
    delay_seconds=0,
)
print(response)

Receive a message from the queue:

response = await client.receive_message(
    queue_url=queue_url,
    max_number_of_messages=1,
    visibility_timeout=30,
)
if response:
    print(response)
    receipt_handle = response[0]["ReceiptHandle"]

Delete the message from the queue:

await client.delete_message(
    queue_url=queue_url,
    receipt_handle=receipt_handle,
)

Close the client at the end:

await client.close()

Another option is to use SQSClient as an async context manager. No need to call close manually in this case. Example:

from aiosqs import SQSClient

async with SQSClient(
    aws_access_key_id="access_key_id",
    aws_secret_access_key="secret_access_key",
    region_name="us-west-2",
    host="sqs.us-west-2.amazonaws.com",
) as client:
    response = await client.get_queue_url(queue_name="dev_orders")
    queue_url = response["QueueUrl"]
    print(queue_url)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiosqs-1.0.5.tar.gz (49.1 kB view details)

Uploaded Source

Built Distribution

aiosqs-1.0.5-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file aiosqs-1.0.5.tar.gz.

File metadata

  • Download URL: aiosqs-1.0.5.tar.gz
  • Upload date:
  • Size: 49.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.25.1

File hashes

Hashes for aiosqs-1.0.5.tar.gz
Algorithm Hash digest
SHA256 7d5d7d93e96b7226592356883fb460e139bd525236aa9cb79e8add0037544f96
MD5 8bd340d08b58141f562c0b420a3c6c62
BLAKE2b-256 05933d49ec7a7c8ce2e0310ab2e8340cef71fd5527346ac595603ef346b35300

See more details on using hashes here.

File details

Details for the file aiosqs-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: aiosqs-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.25.1

File hashes

Hashes for aiosqs-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 45e66436ca34b259551131a9c96531e89ffa3ffbd2cfd8c9bf04633368f4775e
MD5 f8de9083f645752d61a6d88b09fb0a63
BLAKE2b-256 3e7103aee8259fbb4fddc293e0176f4d1c897cf4a47f1fcbc3f45853638b4350

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page