Add your description here
Project description
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())
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pgque-0.1.0.tar.gz.
File metadata
- Download URL: pgque-0.1.0.tar.gz
- Upload date:
- Size: 42.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c714f46622ddf1c609972eb14afc4e38a52d1567860c89db9e25b60a1715c11
|
|
| MD5 |
4b87119b538f3347909ef36925510c8c
|
|
| BLAKE2b-256 |
c32d8c6f2a138af8f67c79d27e77bba829749db45710523edb5c88d858216445
|
File details
Details for the file pgque-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pgque-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4dc4ca52a393cf5c404aedec4d7127f536c99720baeffbca69b6e25ca03c4ed8
|
|
| MD5 |
166aaf0c7bec8bfce5239ecdc41db182
|
|
| BLAKE2b-256 |
18354b0d8e6b3ab64a93fd07326685828639289cce56fe2704b9dd5d6a0f6c4f
|