PostgreSQL All-in-One Toolkit (Queue + Cron + KV Store + PubSub)
Project description
PgMate
PgMate (formerly PgKit) is a lightweight PostgreSQL All-in-One Toolkit that provides:
- Queue: Simple job queue backed by PostgreSQL.
- Cron: Scheduled tasks using
pg_cron. - KV Store: Key-Value store with TTL support.
- PubSub: Real-time event notifications using
LISTEN/NOTIFY.
Requirements
- Python 3.8+
- PostgreSQL database
pg_cronextension enabled in PostgreSQL (required for Cron and KV cleanup features)
Installation
pip install pgmate
Usage
Initialization
from pgmate import PgMate
# Initialize with PostgreSQL DSN
# Automatically creates necessary tables (_pgmate_jobs, _pgmate_kv) if they don't exist
mate = PgMate(dsn="postgres://user:password@localhost:5432/dbname")
Job Queue
Producer:
# Enqueue a job
job_id = mate.enqueue(
queue_name="my_queue",
payload={"task": "send_email", "email": "user@example.com"},
delay_seconds=0
)
print(f"Job enqueued with ID: {job_id}")
Consumer:
def process_job(payload):
print(f"Processing: {payload}")
# Raise exception to retry the job
# Start a worker that listens for new jobs
# This is a blocking call
mate.listen_and_consume("my_queue", process_job)
Key-Value Store
# Set a value with TTL (optional)
mate.kv_set("session:123", {"user_id": 42}, ttl_seconds=3600)
# Get a value
value = mate.kv_get("session:123")
print(value) # {'user_id': 42}
# Delete a value
mate.kv_delete("session:123")
# Enable auto-cleanup for expired keys (requires pg_cron)
mate.enable_kv_cleanup_job()
Cron Scheduler
Schedule recurring jobs using cron expressions.
# Schedule a job to run every minute
mate.schedule_cron(
cron_expression="* * * * *",
job_name="daily_report",
queue_name="reports",
payload={"type": "daily"}
)
Architecture
- Tables:
_pgmate_jobs,_pgmate_kv - Notifications: Uses
LISTEN/NOTIFYon channel_pgmate_event_new_jobfor low-latency job processing. - Concurrency: Safe for multiple workers (uses
FOR UPDATE SKIP LOCKED).
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 pgmate-0.1.0.tar.gz.
File metadata
- Download URL: pgmate-0.1.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d682ddcadb31f5677d32014480428a86b32a6a7491056ae6495fb78b8173750a
|
|
| MD5 |
04a13e39f0bd1397b8fa1e674a89ffcf
|
|
| BLAKE2b-256 |
d80cadd5635dcfe031262600fa82533097f306db2b9ded3c7b19411198ee6e4a
|
Provenance
The following attestation bundles were made for pgmate-0.1.0.tar.gz:
Publisher:
publish.yml on zhenchuan/PgKit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pgmate-0.1.0.tar.gz -
Subject digest:
d682ddcadb31f5677d32014480428a86b32a6a7491056ae6495fb78b8173750a - Sigstore transparency entry: 752474835
- Sigstore integration time:
-
Permalink:
zhenchuan/PgKit@e8ea06b170602a3e4f9cf66b442cc144f998288c -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/zhenchuan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e8ea06b170602a3e4f9cf66b442cc144f998288c -
Trigger Event:
release
-
Statement type:
File details
Details for the file pgmate-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pgmate-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52964c8e31e2a0c23bda2e57bd7be08c808a7274d0db362d72b06ced8c59ecc6
|
|
| MD5 |
992df23c327a1e6516baa4929f7ccca9
|
|
| BLAKE2b-256 |
eb0594b11c89df3cb6cbb7f91a01f998f29e00821a2c22d4d314701c26bdb884
|
Provenance
The following attestation bundles were made for pgmate-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on zhenchuan/PgKit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pgmate-0.1.0-py3-none-any.whl -
Subject digest:
52964c8e31e2a0c23bda2e57bd7be08c808a7274d0db362d72b06ced8c59ecc6 - Sigstore transparency entry: 752474836
- Sigstore integration time:
-
Permalink:
zhenchuan/PgKit@e8ea06b170602a3e4f9cf66b442cc144f998288c -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/zhenchuan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e8ea06b170602a3e4f9cf66b442cc144f998288c -
Trigger Event:
release
-
Statement type: