pgque
A simple message queue based on PostgreSQL's FOR UPDATE SKIP LOCKED.
Installation
Install the basic synchronous version:
pip install pgque
To use the asynchronous version, you need to install the async extra, which includes the asyncpg driver:
pip install pgque[async]
If you prefer to use psycopg2 instead of psycopg (v3) for the synchronous version, you can install the psycopg2 extra:
pip install pgque[psycopg2]
Usage
First, you need to create the message table in your database. You can optionally specify a custom table name.
from pgque import create_tables
database_url = "postgresql://user:password@host:port/dbname"
# Create a table with the default name "messages"
create_tables(database_url)
# Or, create a table with a custom name
create_tables(database_url, table_name="my_messages")
Synchronous
from pgque import get_sync_queue
# Connect to a queue with the default table name
queue = get_sync_queue("postgresql+psycopg://user:password@host:port/dbname")
# Connect to a queue with a custom table name
custom_queue = get_sync_queue(
"postgresql+psycopg://user:password@host:port/dbname",
table_name="my_messages",
)
# Send a message
custom_queue.send_message("my_queue", {"hello": "world"})
# Receive a message
message = custom_queue.receive_message("my_queue")
if message:
print(message["payload"])
custom_queue.complete_message(message["id"])
Asynchronous
import asyncio
from pgque import get_async_queue
async def main():
# Connect to a queue with a custom table name
queue = get_async_queue(
"postgresql+asyncpg://user:password@host:port/dbname",
table_name="my_messages",
)
# Send a message
await queue.send_message("my_queue", {"hello": "world"})
# Receive a message
message = await queue.receive_message("my_queue")
if message:
print(message["payload"])
await queue.complete_message(message["id"])
await queue.close()
asyncio.run(main())
Metadata
Release files for pgque 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pgque-0.1.0.tar.gz | 42.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pgque-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 50.0 kB
Release files / pgque-0.1.0.tar.gz
| Download URL | pgque-0.1.0.tar.gz |
|---|---|
| Size | 42.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3c714f46622ddf1c609972eb14afc4e38a52d1567860c89db9e25b60a1715c11
|
|
BLAKE2b-256 checksum How to use checksums |
c32d8c6f2a138af8f67c79d27e77bba829749db45710523edb5c88d858216445
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.2
|
Release files / pgque-0.1.0-py3-none-any.whl
| Download URL | pgque-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4dc4ca52a393cf5c404aedec4d7127f536c99720baeffbca69b6e25ca03c4ed8
|
|
BLAKE2b-256 checksum How to use checksums |
18354b0d8e6b3ab64a93fd07326685828639289cce56fe2704b9dd5d6a0f6c4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.2
|