Skip to main content

Send and receive messages by using SQS queues.

Project description

Comlink logo

Send and receive messages by using SQS queues.

PyPI version PyPI - Python Version PyPI - License

pip install comlink
poetry add comlink

Docs

Example

import asyncio
import datetime
from comlink import SqsConsumer, SqsQueue


async def example(sqs_client, queue_url):
    # Create a queue object
    sqs_queue = SqsQueue(url=queue_url, client=sqs_client)

    # Event for stopping the consumer
    stop_event = asyncio.Event()
    # Create a consumer with a handler that just prints the message
    consumer = SqsConsumer(queue=sqs_queue, handler=print)
    # Start the consumer
    consumer_task = await consumer.start(stop_event=stop_event)

    # Send a message to the queue
    await sqs_queue.put(f"{datetime.datetime.now()} Hello, world!")
    # Wait for 1 second for the message to be processed
    await asyncio.sleep(1)

    # Stop the consumer
    stop_event.set()
    # Wait for the consumer to stop
    await consumer_task

More examples can be found in the examples directory.

Development

Setup

  1. Install Poetry.
  2. Install dependencies with poetry install.
  3. Install Docker.
  4. Run docker compose -f docker-compose.dev.yml up -d to start the development environment (localstack). Tests will fail until the environment is up and running.

Testing

Run poetry run pytest to run the tests.

Formatting

Run poetry run black . to format the code.

Run poetry run isort . to sort the imports.

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

comlink-0.2.0.tar.gz (5.1 kB view hashes)

Uploaded Source

Built Distribution

comlink-0.2.0-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

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