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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

pgqrs-0.15.2-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.0 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.8+Windows x86-64

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

Uploaded CPython 3.8+musllinux: musl 1.2+ ARM64

pgqrs-0.15.2-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.2-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.2-cp38-abi3-macosx_11_0_arm64.whl (3.6 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

pgqrs-0.15.2-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.2-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pgqrs-0.15.2-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1025ab25ab1d923d746239458d802b184b33aafebfb9850c89b1bbd56e2a6efe
MD5 1fd4ab273acd0afae2570651052e6da6
BLAKE2b-256 b6e4b3562dad866ae6619dcc48458af0a0eec631c43c785937a94fd6e25e50a0

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pgqrs-0.15.2-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.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 02524ed2bb8568734057c66f64198fc7d9e962d3496cbfcd4d1ed3ecbc4308ec
MD5 65c185b2ed5a3f2e0ad36d610ecbdff0
BLAKE2b-256 978af1ef4a62dedc3a0333353726670ac680e54143a90c76df6a366372734a57

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pgqrs-0.15.2-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 881dbecaed521f646fe9b2681cbb4ceca6c0c3894b95e15f1402651c745e2b4f
MD5 5a223fc50504af550c946b1db01250f7
BLAKE2b-256 08f12428247783a444eff27a8677b36ebcd5f930c3d2acccfd7e1bd0472e9ec1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pgqrs-0.15.2-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 b995be7e3cd2ca8631ef58d81f733278717090c8919c5918f65eb2a74b124bb3
MD5 91dc5fdf53c0b66c5147c8466d0fd341
BLAKE2b-256 98c0a7c37a7be56b86407980d157f0ccf5776f815d09b7ea5098b10eb19ca2db

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pgqrs-0.15.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b20b9c4dc954b6b095ae8d4a0758c902ed786a22aea53fc66df6029802b3c7f3
MD5 e57743984161313a170156e9d238cd0a
BLAKE2b-256 cb43eb511c6873998a2213abe29a99dde5e9df4b23a09bb4781ee9afc4e99d37

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pgqrs-0.15.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 83b735751fd58db5805071932aed6d4485e44980022c975b92ed4219e38ac170
MD5 53328ac71404bbaf80859bc15b329bff
BLAKE2b-256 84e55ab295daf1f9ce968aadbff82ce91fe48760d1c6185c29ebc0183d17dc3e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pgqrs-0.15.2-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cbe2bca83a76ab2af50c192e21aec15c0589881034af312375c6805a37d8f104
MD5 7b02d2bd7ea34ed73c6f1b730de0dc00
BLAKE2b-256 2df58d9593e58608dedd365c3d6ba956bd1a59c6b671cc1efbf37892ac146cac

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pgqrs-0.15.2-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e4b13a5cc1a0ddbb4061b72a81ad5d18866eb94346eb938fddf6253d92edfec8
MD5 205d273f437be2b1a8c915db8c70c5f5
BLAKE2b-256 8c19c404695f288058a413e074824043e4145d29191f6f2f4c9dfd3f7a8d7c36

See more details on using hashes here.

Provenance

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