Python async api for creating and managing queues in postgres
Postgres is not best solution for storing and managing queues, but sometimes we have no choice.
async-pq can work with millions of entities and thousands of
requests in one queue. Is used in production. So its well tested and stable.
Install
> pip install async-pq
Quick start
To work with async-pq we need asyncpg library:
import asyncpg
conn = await asyncpg.connect('postgresql://postgres@localhost/test')
QueueFabric.find_queue method will create needed
tables (one for requests and one for messages) in database if it is new queue.
Also it has is_exists_queue method for situations when you
need to know that it is exists or not and will be the new queue.
from async_pq import Queue, QueueFabric
queue: Queue = await QueueFabric(conn).find_queue('items')
Operations with queue
Put new items (should be dumped JSONs) in queue:
await queue.put('{"id":1,"data":[1,2,3]}', '{"id":2,"data":[3,2,6]}')
Pop items from queue with some limit.
It will create one request and return its id.
It is useful when you want to use acknowledgement pattern:
# If with_ack=False (default from > 0.2.1), massage will be acknowledged in place automatically
request_id, data = await queue.pop(limit=2, with_ack=True)
To acknowledge request use ack method:
# returns False if request does not found or acked already
is_acked: bool = await queue.ack(request_id)
Or vice versa:
# returns False if request does not found or acked already
is_unacked: bool = await queue.unack(request_id)
You can return unacknowledged massages older than timeout seconds
(default limit=1000 requests) to queue:
requests_number = await queue.return_unacked(timeout=300, limit=500)
Clean queue (delete acknowledged massages) to not overfill database with old data (default limit= messages of 1000 requests):
requests_number = await queue.clean_acked_queue(limit=500)
Metadata
Release files for async-pq 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| async-pq-0.3.1.tar.gz | 3.9 kB | Without provenance | Details for async-pq-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| async_pq-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for async_pq-0.3.1-py3-none-any.whl |
Total release size: 8.2 kB
Release files / async-pq-0.3.1.tar.gz
| Download URL | async-pq-0.3.1.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d4fbeaa3ebae4d1477063f5687c51ecf53b78f7ce9d36b2115e194478e828d81
|
|
BLAKE2b-256 checksum How to use checksums |
1f36cc3a3dc83523385a0f15e6b369d55297a3d47054a71b4777cee012b6b489
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/2.7.15
|
Release files / async_pq-0.3.1-py3-none-any.whl
| Download URL | async_pq-0.3.1-py3-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a94a54a7fc0ff398fe88d861cc7ec512a4dca1ef6689d564646bdf44e4417612
|
|
BLAKE2b-256 checksum How to use checksums |
f742366cf2b5d4b323cca3ce5d99407b42beeaa896ec07b6f42650a86dbe70d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/2.7.15
|
Security for async-pq 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.