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.1.tar.gz (210.5 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.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.0 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

pgqrs-0.15.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.0 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

pgqrs-0.15.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.0 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

pgqrs-0.15.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.0 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.8+Windows x86-64

pgqrs-0.15.1-cp38-abi3-musllinux_1_2_x86_64.whl (4.2 MB view details)

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

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

Uploaded CPython 3.8+musllinux: musl 1.2+ ARM64

pgqrs-0.15.1-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.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.8+macOS 11.0+ ARM64

pgqrs-0.15.1-cp38-abi3-macosx_10_12_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pgqrs-0.15.1.tar.gz
Algorithm Hash digest
SHA256 6e999e2f82a69fa2c6835394951ee54dd093033a489eb46dd0f35905f1846c4f
MD5 307b8de1f0b9381e36df02cd936bce54
BLAKE2b-256 5411b5d3ce3cb1829694a63db258af9ebb8585d1e2d5b0e2ae71a89f3e6fb6f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.15.1.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.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pgqrs-0.15.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 75106989591940c017a66554b48246b151d8a9dcef5594aa3929501c0d18eed0
MD5 87e5d54cc41c5489192c22210aa42761
BLAKE2b-256 5ca2ddb72f3fa0f2d781f9d3e31f6ae672ce926009be6d58381a547b16cbe2f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.15.1-pp310-pypy310_pp73-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.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pgqrs-0.15.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 01cafe5742da6b5115f800cbb907dd9b81bdd0a0fad7d66ed78a21d0debbd676
MD5 3381daa267ed1971c2dd3de334320a2d
BLAKE2b-256 9054c15d882288f72a94f05c359ec1e945fb0ebdfc6ba15a38d98e50378eff16

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.15.1-pp39-pypy39_pp73-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.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pgqrs-0.15.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 89ce5702a2ba9ab01797de4c3696fa5395216dbd7eb803571e0c7f0782549abc
MD5 af1424e11ec6b624333eec5898b94404
BLAKE2b-256 e5b3290d78e0860f1f9fc0e3b97a63a236063d164fbecba7e4592e20a3c5ab91

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.15.1-pp38-pypy38_pp73-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.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pgqrs-0.15.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 28c340b7d9709e67fd07ba02040652b0314d8cf894c9e65a50395f80eda0f4bf
MD5 59db5a6ad28dbb96d68b0b9b01ecf8ec
BLAKE2b-256 f2665fb2b5d523479fdb2ad08c5743cb69227b7600838c572773702465efef99

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.15.1-pp37-pypy37_pp73-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.1-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: pgqrs-0.15.1-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.7

File hashes

Hashes for pgqrs-0.15.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e06f3d373fb557de462c941bed39136bf0d301cb7cc9090915ef78eca97f036b
MD5 18fd5c061be6f15aa196988924a298be
BLAKE2b-256 c79cb0f89823443741939759ce1b3ab21b35bc972f1da407d835d519588326c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.15.1-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.1-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pgqrs-0.15.1-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 57d6285c9a9d58968308d50466297cd1f644c72afeaea0ff31b0577117353428
MD5 0bd2978fa3c573ed5a6ac7145de484aa
BLAKE2b-256 2dc34325c9a564fbfe3da4b1965deeca2dcdbadabd035bacaac3df1d8870eb71

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.15.1-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.1-cp38-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pgqrs-0.15.1-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 50e610c8ea181de05511163eb17303f2def9e6f02c667abb6718202d173a39be
MD5 04eb9728a740a691a1db5fff17b64003
BLAKE2b-256 71c663d59d96705995d824afb111b49d6332b76a1c38ddac7593375c3ba13d8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.15.1-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.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pgqrs-0.15.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8529da8a2510952678850950454d7878aa6bf221ca5f6edf1b435dcfb8dcfab6
MD5 b8238075bbaaea903b054ba04654a9cc
BLAKE2b-256 4819de4e1a65523cd5ba0b076b522acab56bb6dd333f35e77b92d5da02082174

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.15.1-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.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pgqrs-0.15.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e92f964f9f08e2ca5b94a4fcb184ec57941c405f87c9c1fd134f54b376aa1520
MD5 66abf31063868b6328da61fc2c4afb56
BLAKE2b-256 f4615d36acdde681136bbaa1640530bdca51640f7ae2befe103ecc156efe33fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.15.1-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.1-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pgqrs-0.15.1-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7f8a32d5c2ea55f49092a5c0ff32205e78aa8056e56e01b9277458c6d7cb549f
MD5 772723f216ba6fb0600871957423697a
BLAKE2b-256 a0219ceb457eb507b6eb1aa65d0b36365dbccbf2a30d16dbff96a1fdb97edc7e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.15.1-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.1-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pgqrs-0.15.1-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c70bff0b06732a3b95047e2f7d02056921a5a2454a0a31268659bcb24880d65f
MD5 c9b84a77dae545bdcbbaf72ff33b2bd9
BLAKE2b-256 deb78f9c0552c2a6d50f53d948c32c23d4792688048df7f2fe6baf27ff38b9d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.15.1-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