Taqu Task Queue system
Project description
Python Task Queue system built on Azure Service Bus queues and pydantic models.
What is this?
Lots of systems benefit from having a queue for background tasks, that run independently of e.g. your APIs or other processes. This can help e.g. by enhancing your API performance, limiting the effects of traffic peaks, as well as scaling out with parallel processing of various things.
The defacto standard for Python is Celery + RabbitMQ, but hosting RabbitMQ is another liability and not always the most fun experience, and Celery doesn’t support asyncio yet. Fully hosted solutions such as the Azure Service Bus help you get off the ground faster, with less things to worry about, and can allow you to save on costs as well.
Primarily intended for use with asyncio (from taqu.aio module), but works with non-async code just as well (using imports from the taqu module).
Supports all the basic things you could need:
Fast insertion of tasks to queue
Async task processing
Easy to scale workers
Retry logic - if there’s an uncaught exception the task will automatically be put back in the queue
Clean shutdown on Ctrl+C (waits until tasks finish processing)
License
Licensing is important. This project itself uses BSD 3-clause license, but e.g. Azure library for Storage Bus and other such libraries used by it may have their own licenses.
For more information check the LICENSE -file.
Getting started
In the Azure Portal set up a new Service Bus (any tier is fine), and then a queue in it. You probably want to enable partitioning, maybe also dead-lettering. Then you’ll want to get the access credentials for your code. Ensure you’ve got the Azure CLI installed and then run:
az login # Ensure you're logged in to Azure
az account list # List subscriptions
az account set --subscription <subscriptionId> # Set active subscription
az servicebus namespace authorization-rule keys list \
--resource-group <rgName> \
--namespace-name <namespace> \
--name RootManageSharedAccessKey \
--query primaryConnectionString \
--output tsv
Also you’ll need the Taqu library installed, e.g. for use with the Azure:
pip install taqu[azure]
Then, you can set up your worker, here’s an example worker.py that you can just run with python worker.py:
import asyncio
from taqu.aio import TaquAzureWorker
from pydantic import BaseModel
CONNECTION_STRING = "..."
worker = TaquAzureWorker(CONNECTION_STRING)
class CreateUser(BaseModel):
username: str
async def create_user(user: CreateUser):
print(user.username)
worker.register(create_user)
worker.run()
With the worker in place, you can create a client and send some tasks
from taqu import TaquAzureClient
from pydantic import BaseModel
CONNECTION_STRING = "..."
taqu = TaquAzureClient(CONNECTION_STRING)
class CreateUser(BaseModel):
username: str
taqu.add_task(CreateUser(username="my_new_username"))
You can also check out the examples.
Contributing
This project is run on GitHub using the issue tracking and pull requests here. If you want to contribute, feel free to submit issues (incl. feature requests) or PRs here.
To test changes locally python setup.py develop is a good way to run this, and you can python setup.py develop --uninstall afterwards (you might want to also use the --user flag).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file taqu-1.0.0.tar.gz
.
File metadata
- Download URL: taqu-1.0.0.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ee3fca3eadc1d5f003af8b11e815ddf9f9719edbeaaed17589d89d56574a141 |
|
MD5 | aa758c45f9089bf9146a4f8c67a81ef6 |
|
BLAKE2b-256 | 119ca124b05e8ecc3bb8937df791529f81946d6dadf72e4a43cfdbc324a99407 |
File details
Details for the file taqu-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: taqu-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c998dc29fd7dcf00b802476d03b96c013790f6ba4344e36f506087661ed8c818 |
|
MD5 | 25ee6c85d582104bae7bb54d5bc55da5 |
|
BLAKE2b-256 | b65b79ac554ec61ddedd5c542bce22bdd490c056386a0d8978cb9a338309e4f3 |