Skip to main content

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_cron extension 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/NOTIFY on channel _pgmate_event_new_job for low-latency job processing.
  • Concurrency: Safe for multiple workers (uses FOR UPDATE SKIP LOCKED).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pgmate-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pgmate-0.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

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

Hashes for pgmate-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d682ddcadb31f5677d32014480428a86b32a6a7491056ae6495fb78b8173750a
MD5 04a13e39f0bd1397b8fa1e674a89ffcf
BLAKE2b-256 d80cadd5635dcfe031262600fa82533097f306db2b9ded3c7b19411198ee6e4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgmate-0.1.0.tar.gz:

Publisher: publish.yml on zhenchuan/PgKit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pgmate-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 52964c8e31e2a0c23bda2e57bd7be08c808a7274d0db362d72b06ced8c59ecc6
MD5 992df23c327a1e6516baa4929f7ccca9
BLAKE2b-256 eb0594b11c89df3cb6cbb7f91a01f998f29e00821a2c22d4d314701c26bdb884

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgmate-0.1.0-py3-none-any.whl:

Publisher: publish.yml on zhenchuan/PgKit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page