Skip to main content

A lightweight and fast background task processing library for Python, developed with simplicity in mind.

Project description

RapidQ

License Python PyPI Version Code style: Black

For those who want a bare minimum task queue, Just run and discard, no headaches.

Only :pinching_hand: ~700 lines of code

A lightweight :feather: and fast :rocket: background task processing library for Python, developed with simplicity in mind.
There is nothing fancy, no gimmick, RapidQ is a simple and easy to use package - works on any OS (yes, it supports windows).
Only Redis broker is currently available, and there is no result backend(could be implemented later).

Inspired by celery and dramatiq, but :feather:lightweight, :rocket:faster and easy to use for small projects.

Installation

pip install rapidq

It has:

  • Only Redis as broker, with json and pickle serialization options.
  • Process based workers, and is faster :rocket:.
  • No result backend
  • No retry behavior (of course it will be added)
  • No monitoring, as of now.

It requires:

  • No configurations for local setup. Although some broker property can be configured.

Motivation

Simply put - I just wanted to see if I could do it. :hugs:
Understanding how packages like celery and dramatiq works internally was a challenge I faced. I wanted a package that is understandable and simple.


How RapidQ works?

RapidQ uses python's multiprocessing library to run tasks. It has a master process, which is the RapidQ itself that handles the
broker communications and workers. Workers do not query the broker directly. Instead the master query the broker and assign tasks to idle workers.
Workers just run forever and check their task queues periodically. Master queries the broker only when there are idle workers available.


This project is under development, so expect breaking changes when you upgrade


A working example

The below code is available in example\minimal.py

# my_task.py
from rapidq import RapidQ

app = RapidQ()

@app.background_task(name="simple-task")
def test_func(msg):
    # of course this could do more than just print.
    print("simple task is running")
    print(msg)


if __name__ == "__main__":
    test_func.in_background(msg="Hello, I'm running")

Copy paste the above into a python file, say my_task.py

Run the rapidq worker first.
rapidq my_task

Then on another terminal, run the my_task.py
python my_task.py

Customizing broker properties

If you wish to customize the serialization to use pickle (json by default) or want to change the broker url? It can be customized with a small configuration, using a simple python file.
check similar example in example\minimal_custom.py and example\config_example.py

# my_custom_task.py
from rapidq import RapidQ

app = RapidQ()

# define the custom configuration. Below line can be omitted if configuration is not needed.
app.config_from_module("example.config_example")


@app.background_task(name="simple-task")
def test_func(msg):
    print("simple task is running")
    print(msg)


if __name__ == "__main__":
    test_func.in_background(msg="Hello, I'm running")

You can run rapidq as before.
rapidq my_custom_task
Then on another terminal, run the my_custom_task.py
python my_custom_task.py


Number of workers.

By default RapidQ uses 4 worker processes or the number of CPUs available on your system, whichever is smaller.
You can control the number of workers by passing -w argument. Eg rapidq my_task -w 6. Which will start 6 worker processes.


Flushing broker

May be you tested a lot and flooded your broker with messages.
You can flush the broker by running rapidq-flush

Integrating with web frameworks

It can be easily integrated with Flask and FastAPI applications. A simple Flask and FastAPI example is in example directory.
Currently RapidQ cannot be easily integrated with Django. Django support is coming in next version.

Local development

For local development in windows, you can use either of the following ways to get Redis working.

  1. Redis for windows from: https://github.com/redis-windows/redis-windows
  2. Using redis with WSL: https://redis.io/docs/latest/operate/oss_and_stack/install/archive/install-redis/install-redis-on-windows/
  3. Using a remote Redis server.

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

rapidq-0.2.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rapidq-0.2.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file rapidq-0.2.0.tar.gz.

File metadata

  • Download URL: rapidq-0.2.0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.11.9 Windows/10

File hashes

Hashes for rapidq-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e2261cbbeacb247fc186e39c7f169d34a894129c72d269f4d23c393376deb66c
MD5 c2d10a7cf22215cac9da6280a75d9a7d
BLAKE2b-256 33864b184485e70b5e510cd3bd25ebd5b3c58399861f833b4a86797ac6eddbec

See more details on using hashes here.

File details

Details for the file rapidq-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: rapidq-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.11.9 Windows/10

File hashes

Hashes for rapidq-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 05c4d51f7c73b1f83585ecbaad8168a8f95f595844fc91c1e02e394076813665
MD5 a52077b73571ed60a009448b54c0372f
BLAKE2b-256 e4db0983c8126fa347f36924797c919f35c89bcfbc92868d853b479988d3eeeb

See more details on using hashes here.

Supported by

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