Skip to main content

Asynchronous message dispatcher for concurrent tasks processing

Project description

Circular Image

pyinsole is an asynchronous message dispatcher inpired by loafer designed to provide a flexible and efficient way to consume messages from Amazon SQS queues. The pyinsole simplifies the process of integrating with SQS by offering multiple consumption strategies, allowing you to choose the best approach for your application's needs.


💻 Usage

The script defines an asynchronous message handler function (my_handler) that will be invoked whenever a message is received from the SQS queue. The SQSRoute class is used to route messages from the example-queue to the handler.

Example Code

Here’s the main code that processes messages from the example-queue. The script will listen for messages on the example-queue, and for each message received, it will print the message content, associated metadata, and any additional keyword arguments.

import os

from pyinsole import Manager
from pyinsole.ext.aws import SQSRoute

async def my_handler(message: dict, metadata: dict, **kwargs):
    print(f"message={message}, metadata={metadata}, kwargs={kwargs}")
    return True

provider_options = {
    "endpoint_url": os.getenv("AWS_ENDPOINT_URL"),
    "options": {
        "MaxNumberOfMessages": 10,
        "WaitTimeSeconds": os.getenv("AWS_WAIT_TIME_SECONDS", 20),
    },
}

routes = [
    SQSRoute('example-queue', handler=my_handler, provider_options=provider_options),
]

if __name__ == '__main__':
    manager = Manager(routes)
    manager.run()

Running the Script

This setup allows you to easily process messages from an SQS queue using the pyinsole library. You can modify the my_handler function to implement your specific message processing logic.

  1. Start LocalStack (or ensure you have access to AWS SQS). If you are using LocalStack, make sure it's running and the example-queue is created:

    aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name example-queue
    
  2. Run the script:

    python your_script.py
    
  3. Push some messages:

    aws --endpoint-url=http://localhost:4566 sqs send-message --queue-url http://localhost:4566/000000000000/example-queue --message-body "Your message body"
    

🎯 Roadmap

You can find the project roadmap here.

This document outlines future improvements, features, and tasks planned for the project.


🫱🏻‍🫲🏽 How to contribute

We welcome contributions of all kinds to make pyinsole better! To contribute to the project, follow these steps:

  1. Fork the repository: Click on the "Fork" button at the top right of the repository page.

  2. Clone your fork:

    git clone https://github.com/edopneto/pyinsole
    cd pyinsole
    
  3. Create a new branch: It's best practice to create a feature branch for your changes.

    git checkout -b feature/your-feature-name
    
  4. Make your changes: Work on your feature, bug fix, or documentation improvement.

  5. Test your changes: Ensure everything is working as expected.

  6. Commit your changes:

    git add .
    git commit -m "Add a brief message describing your changes"
    
  7. Push to your branch:

    git push origin feature/your-feature-name
    
  8. Open a Pull Request: Go to the repository on GitHub, and you’ll see a button to "Compare & Pull Request." Submit a pull request with a clear title and description of your changes.

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

pyinsole-0.1.0a0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

pyinsole-0.1.0a0-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file pyinsole-0.1.0a0.tar.gz.

File metadata

  • Download URL: pyinsole-0.1.0a0.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pyinsole-0.1.0a0.tar.gz
Algorithm Hash digest
SHA256 fdb8a52bacefb8d9d68960ff4fb4366c959afe19ca9db61743ee0564d6f5b053
MD5 b74d95588f68801cb3749867af556b23
BLAKE2b-256 ea9a506063b06756033db777369b0db95ad71aec05fd0961c98124d6bb64fa6c

See more details on using hashes here.

File details

Details for the file pyinsole-0.1.0a0-py3-none-any.whl.

File metadata

  • Download URL: pyinsole-0.1.0a0-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pyinsole-0.1.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 01f7660a792907b04269059080e8ca19953115669236324062b4e4936179d2ef
MD5 6380cb5ad03c41bf61573dfa8a640cdd
BLAKE2b-256 6a5aedeb5b33100b5fe125ce0d3087abcd5f9c3ed3a5108c9718c1ea4828be1f

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