Skip to main content

PostgreSQL-backed job queue with Rust and Python bindings

Project description

py-pgqrs

pgqrs is a postgres-native, library-only durable execution engine.

Python bindings for the Rust core. Built for Postgres. Also supports SQLite and Turso.

What is Durable Execution?

A durable execution engine ensures workflows resume from application crashes or pauses. Each step executes exactly once. State persists in the database. Processes resume from the last completed step.

Key Properties

  • Postgres-native: Leverages SKIP LOCKED, ACID transactions
  • Library-only: Runs in-process with your application
  • Multi-backend: Postgres (production), SQLite/Turso (testing, CLI, embedded)
  • Type-safe: Rust core with idiomatic Python bindings
  • Transaction-safe: Exactly-once step execution within database transactions

Installation

pip install pgqrs

For local development:

make requirements

Backend Support

py-pgqrs supports all three backends. Choose the right one for your use case:

# PostgreSQL (production)
store = await pgqrs.connect("postgresql://user:pass@localhost:5432/db")

# SQLite (embedded, testing)
store = await pgqrs.connect("sqlite:///path/to/database.db")

# Turso (SQLite-compatible, embedded)
store = await pgqrs.connect("turso:///path/to/database.db")

Usage

Producer + Consumer

import asyncio
import pgqrs

async def main():
    store = await pgqrs.connect("postgresql://localhost/mydb")

    admin = pgqrs.admin(store)
    await admin.install()
    await store.queue("tasks")

    producer = await store.producer("tasks")
    msg_id = await producer.enqueue({"task": "process_image", "url": "..."})
    print(f"Enqueued job {msg_id}")

    consumer = await store.consumer("tasks")
    messages = await consumer.dequeue(batch_size=1)
    for msg in messages:
        print(f"Processing {msg.id}: {msg.payload}")
        await consumer.archive(msg.id)

asyncio.run(main())

Durable Workflow (Python)

import asyncio
import pgqrs

async def main():
    store = await pgqrs.connect("postgresql://localhost/mydb")
    admin = pgqrs.admin(store)
    await admin.install()

    await pgqrs.workflow().name("archive_files").store(store).create()
    consumer = await pgqrs.consumer("worker-1", 8080, "archive_files").create(store)

    await pgqrs.workflow() \
        .name("archive_files") \
        .store(store) \
        .trigger({"path": "/tmp/report.csv"}) \
        .execute()

    messages = await consumer.dequeue(batch_size=1)
    msg = messages[0]

    run = await pgqrs.run().message(msg).store(store).execute()
    step = await run.acquire_step("list_files", current_time=run.current_time)
    if step.status == "EXECUTE":
        await step.guard.success([msg.payload["path"]])

    step = await run.acquire_step("create_archive", current_time=run.current_time)
    if step.status == "EXECUTE":
        await step.guard.success(f"{msg.payload['path']}.zip")

    await run.complete({"archive": f"{msg.payload['path']}.zip"})
    await consumer.archive(msg.id)

asyncio.run(main())

Testing

make test-py PGQRS_TEST_BACKEND=postgres

Documentation

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

pgqrs-0.15.3.tar.gz (204.0 kB view details)

Uploaded Source

Built Distributions

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

pgqrs-0.15.3-cp38-abi3-win_amd64.whl (3.6 MB view details)

Uploaded CPython 3.8+Windows x86-64

pgqrs-0.15.3-cp38-abi3-musllinux_1_2_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ x86-64

pgqrs-0.15.3-cp38-abi3-musllinux_1_2_aarch64.whl (4.2 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARM64

pgqrs-0.15.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

pgqrs-0.15.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.1 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

pgqrs-0.15.3-cp38-abi3-macosx_11_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

pgqrs-0.15.3-cp38-abi3-macosx_10_12_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file pgqrs-0.15.3.tar.gz.

File metadata

  • Download URL: pgqrs-0.15.3.tar.gz
  • Upload date:
  • Size: 204.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pgqrs-0.15.3.tar.gz
Algorithm Hash digest
SHA256 f53f5c12be523d10348678efcbce5ae8f7b1c8990e1c89a2a63b3725861e262d
MD5 c1b28dd8d96ba9682827ca658a54ac49
BLAKE2b-256 fee55de7b66e49b54376f26c417b648d406dd1d1888666a67498ae7e133a9d14

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.15.3.tar.gz:

Publisher: release.yml on vrajat/pgqrs

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

File details

Details for the file pgqrs-0.15.3-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: pgqrs-0.15.3-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 3.6 MB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pgqrs-0.15.3-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 92d073b872dda74198ec625a02f2fb3d12a7ecbebb156b7bd59aac12743900af
MD5 b87e5fe2a8b2504d39418b9e5db57dcc
BLAKE2b-256 cf424b5ee756807302737cc76eeac1fedc869adcd221e79d834f831945f05a72

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.15.3-cp38-abi3-win_amd64.whl:

Publisher: release.yml on vrajat/pgqrs

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

File details

Details for the file pgqrs-0.15.3-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pgqrs-0.15.3-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 114905bf1d5c522d7ff20a19dd9c08c934bf0ca5a060f09cb6a45e5f72ff67ed
MD5 24e9e6de560250dfaf6f851238f4e361
BLAKE2b-256 753fc0038bb0170f6ba8921354c59cd42aad369e86d2a33aa8e3ceed74731253

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.15.3-cp38-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.yml on vrajat/pgqrs

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

File details

Details for the file pgqrs-0.15.3-cp38-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pgqrs-0.15.3-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 b04af1a5f3f178d0dc9c4567f4fcf5b4fb39fb93824266607a5c407aa4e3c6b6
MD5 f0b0cad9be32c7b7781b718e139324e1
BLAKE2b-256 37e2e9ae24ae11730d8b6b3bdc3bb08162eb61c936d1ae8fa94ac8ca070119af

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.15.3-cp38-abi3-musllinux_1_2_aarch64.whl:

Publisher: release.yml on vrajat/pgqrs

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

File details

Details for the file pgqrs-0.15.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pgqrs-0.15.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a435e9a69538cfaf628157dbd18187e4d9ce074f8fa8adafd73046c2a8969c2e
MD5 94f98b6988ed3b5cca2a07299e7456f2
BLAKE2b-256 b21be7d2994372da2bbe636e295d28fc8330616dcef5a2e5cacd87664daf68f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.15.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on vrajat/pgqrs

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

File details

Details for the file pgqrs-0.15.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pgqrs-0.15.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bb4e3b1deb11a67dd0099731abe168bc9bd4d6fc4c2fd0c5a45b1e65a44b8e9b
MD5 4ef8aa763b39d369d8f80759dbdfe2f7
BLAKE2b-256 afb26702b4d73fd22d09b01e0980d23825798241a6351e773d2238021609e3da

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.15.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on vrajat/pgqrs

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

File details

Details for the file pgqrs-0.15.3-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pgqrs-0.15.3-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 af0acac952c6d796191175192155cf6df5a7c86e96bd87dc44101f32f0e30262
MD5 e17fa7940a4c3e4a60bff1637b883774
BLAKE2b-256 c8deae7fd08beda7226271f944a12e530d97f9a3e212ae97448ceeb5df34ed09

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.15.3-cp38-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on vrajat/pgqrs

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

File details

Details for the file pgqrs-0.15.3-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pgqrs-0.15.3-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 47fc21c254cf0bb78e8147130044847ec0d697656287ea479151e8ed2e037c8f
MD5 0f01492ecc3deb1223893a82431dcd2e
BLAKE2b-256 20820d202d096ab605ac334039c06a000e0318b6babe2bf3a41ee5b5e26fa247

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.15.3-cp38-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on vrajat/pgqrs

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