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.14.0.tar.gz (192.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.14.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.1 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

pgqrs-0.14.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.1 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

pgqrs-0.14.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.1 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

pgqrs-0.14.0-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.1 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.8+Windows x86-64

pgqrs-0.14.0-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.14.0-cp38-abi3-musllinux_1_2_aarch64.whl (4.2 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARM64

pgqrs-0.14.0-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.14.0-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.14.0-cp38-abi3-macosx_11_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

pgqrs-0.14.0-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.14.0.tar.gz.

File metadata

  • Download URL: pgqrs-0.14.0.tar.gz
  • Upload date:
  • Size: 192.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.14.0.tar.gz
Algorithm Hash digest
SHA256 8a3ed03fb2dda08e94204fe81d537aa5531687132add8d45f3f065d24d7ec180
MD5 f796db3a45a33861437a6301747b0487
BLAKE2b-256 f41069a2b57d07778b41cef7817e3ee42078ab09fcd5b7cc8302c820245265ab

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pgqrs-0.14.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1a40444c8e8bc3a1f6c132fec7ea5bf823779245815607ec23c04c0456189e82
MD5 f951839b7b8ac6d6e2137f17a46f42dd
BLAKE2b-256 c5c5473d30846ce255574e762424fab4030d79f9c058f2d236092abd28e73620

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.14.0-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.14.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pgqrs-0.14.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4c38d21bc1c880c75326a69f30d2412b39dd293a52b5633815ee1a662b2d4882
MD5 6774a0b6bf20ed2843792f66dbcd8864
BLAKE2b-256 2c6fc08fd5a251680f52634370993b82239acbe882041f36339209f8aacc183b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.14.0-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.14.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pgqrs-0.14.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 30bcb69c3249a5c918d632f06f074882d3af9cbbae8b0a29963bd1a1372801d5
MD5 ef9551254d64a3be56e6fa781e59c51f
BLAKE2b-256 a13bd079e92d3f427bda03360a1892f5d549bb7dd0ce37da80436e8506ffee4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.14.0-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.14.0-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pgqrs-0.14.0-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 becda314bdfcd35c5408e170fa0714a0893673f15190cb5a99ba4d7aa4093ce0
MD5 1c4498a51c866ebb2fbbd86d238dd54e
BLAKE2b-256 4d95a92876c78f7cf983874318b279a981f6006abe75b84d3ca1a5b473730a54

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgqrs-0.14.0-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.14.0-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: pgqrs-0.14.0-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.14.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ed7fc6dd45e55056212229745ebd5d909434b25beb32826a73cc8f49cba5fbcc
MD5 57f9f99f7d413b52af133d1cc6984075
BLAKE2b-256 042db7edda310ba0b003c62c2952cb3c3672703f8bf0a9e1df1e860fdffe9fcf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pgqrs-0.14.0-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7ac5922e167c78fc6085418baf2624fe488d826840c695db97e6628aab89955d
MD5 0e36ab97742db0b2b2ad628386bfd5a9
BLAKE2b-256 0dc6ea5789146ad5b88cfb77958056ad923e3e4ac3ce5f1caa339ee8c0708bc4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pgqrs-0.14.0-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 6ad5bf03d8051154aeeb81321b9672224373b0f923dc90de43fdc1f23904fe19
MD5 0aa8fc9b498abbc26f6f13b062df38b2
BLAKE2b-256 4de3c1441475f0ea8c967c0277177e16236a84c128e5bec4e4c564f566f9af78

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pgqrs-0.14.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a2f98bbf471ed1bb6bad4f655de2c8bec34bb00863a89f60e0985aa0586288fa
MD5 9548ab7066e3423515c1066029063d06
BLAKE2b-256 e32130c1c461054feab8783e14f634450243248a8d77eb33eea59bdc93cf5638

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pgqrs-0.14.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 86be157a79f27cdef111ef72a274a31f829202638b16d83047dd0b221ba8ff84
MD5 e156e3ca1fb12bd139498b7830f6a515
BLAKE2b-256 1352f8671d791d2577652a710dfb71b853b6cdfe88dbacad250d01899769935a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pgqrs-0.14.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0b0ca72b357781cd9907cf061ce74803b42c1593ab83951621c14ea03269deb5
MD5 ba80e240c2af49140113e479e55f2019
BLAKE2b-256 2f65fcbf27ece371d19d9bf02305f724c812e43d71bc1e04fda510dab5940abb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pgqrs-0.14.0-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a64fc2843a9f0159c7ea3ac74fc3c2756a4fb7e9220d7cd3f630a5f38fb0a5d7
MD5 c8f6b8ea4938e13a1eb99cbd09424ab6
BLAKE2b-256 0719974b1decb5e664a0782a575603f10fda761425c3c08642f4eabd326ae409

See more details on using hashes here.

Provenance

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