Skip to main content

pgtask

Durable tasks and workflows that live entirely in PostgreSQL.

There is no broker, no coordinator, and no extension to install. If your database is up, your queue is up.

[!WARNING] pgtask is under active development. It is not ready for production use.

Installation

pip install pgtask

Define a task and run a worker

A registry maps a task name to the function that runs it. A worker claims work for that queue, one lease at a time, so a worker that dies hands its tasks back instead of taking them with it.

from __future__ import annotations

import asyncio
import os

from pgtask import Client, Task, TaskRegistry, Worker

tasks = TaskRegistry(queue_name="reports")


@tasks.task("reports.render")
async def render(task: Task, payload: dict) -> dict:
    return {"report_id": payload["report_id"], "attempt": task.attempt}


async def main() -> None:
    database_url = os.environ["PGTASK_DATABASE_URL"]
    client = await Client.connect(database_url)
    await client.migrate()
    await Worker(database_url, tasks).run()


asyncio.run(main())

Delivery is at least once, so write handlers that are safe to run again.

Enqueue a task

from __future__ import annotations

import asyncio
import os

from pgtask import Client, EnqueueRequest


async def main() -> None:
    client = await Client.connect(os.environ["PGTASK_DATABASE_URL"])
    handle = await client.enqueue(
        EnqueueRequest("reports.render", {"report_id": "report-123"}, queue_name="reports")
    )
    print(await handle.result(timeout=30.0))


asyncio.run(main())

Enqueue inside your transaction

This is the reason to keep the queue in the database. Pass your own connection and the task commits with your data or not at all. Roll back and the task never existed, which is what an outbox table is usually for.

async with connection.transaction():
    await connection.execute("INSERT INTO reports (id) VALUES (%s)", ("report-123",))
    await Client.enqueue_on(connection, request)

connection is your psycopg connection, not one of ours.

Documentation

kludex.github.io/pgtask covers workers, durable execution, signals, cancellation, scheduling, and OpenTelemetry propagation.

Download files

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

Source Distribution

pgtask-0.2.0.tar.gz (168.7 kB view details)

Uploaded Source

Built Distributions

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

pgtask-0.2.0-cp310-abi3-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.10+Windows x86-64

pgtask-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

pgtask-0.2.0-cp310-abi3-manylinux_2_28_aarch64.whl (4.4 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

pgtask-0.2.0-cp310-abi3-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

pgtask-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file pgtask-0.2.0.tar.gz.

File metadata

  • Download URL: pgtask-0.2.0.tar.gz
  • Upload date:
  • Size: 168.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pgtask-0.2.0.tar.gz
Algorithm Hash digest
SHA256 40d82bca4a26d003650ee98899f5d649809ed44c9a280eb515ea89512fdb9372
MD5 426678e6ce81b2f976ef5f4c646ed659
BLAKE2b-256 a3cb22fd9d6ebe7565139becfab490b9a85da8d7c4cc097381384a598f2a3deb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgtask-0.2.0.tar.gz:

Publisher: release.yml on Kludex/pgtask

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

File details

Details for the file pgtask-0.2.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: pgtask-0.2.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 3.7 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pgtask-0.2.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a3160bc86bdecbc255e30d74228bb665f696c00d18b77a9a0b21665305c2733d
MD5 f28f55f26c28162752fa56c369711aa9
BLAKE2b-256 08fbb8d376a070ffeefa170ece71f2cbcdf32a046e2ce44512e46a0d5483363b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgtask-0.2.0-cp310-abi3-win_amd64.whl:

Publisher: release.yml on Kludex/pgtask

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

File details

Details for the file pgtask-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pgtask-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9c4f954c067ee17e278b57008ff9e619b69912cb2695aaa5d51e2390e256e7d9
MD5 a1810a7f93a1deedc7f4de3a39a59e10
BLAKE2b-256 5e8926d2d89553f8ba6e0c6b2d1d027fe29aa72937b5bd332d6c8c8c752d23dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgtask-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl:

Publisher: release.yml on Kludex/pgtask

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

File details

Details for the file pgtask-0.2.0-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pgtask-0.2.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6bdcf7efc83a91ce74691544b5da5a5d491de82d6cf9fbd1ad83b8ea23c0247a
MD5 49ce45eaf2d6cc46daa6708ad4e515f2
BLAKE2b-256 4193df4fa2d9d8433552abd1ed043d9cc8f2ba2a151b540cf9736b4644a6a71f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgtask-0.2.0-cp310-abi3-manylinux_2_28_aarch64.whl:

Publisher: release.yml on Kludex/pgtask

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

File details

Details for the file pgtask-0.2.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pgtask-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b8860b265ee347cfd6d57986a5485116b11f6bd2997895f7ee55247c496f3466
MD5 28494b1c59323385e8faf64ce06002a2
BLAKE2b-256 005dae3cde966794a69d7c3a7415646f1f69a96ae5248de2538b59fe83eccdce

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgtask-0.2.0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on Kludex/pgtask

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

File details

Details for the file pgtask-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pgtask-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5efc6dfb47a666c4d8e3a31532f3a4ee551cd8504274bbc64d72025ccd14710c
MD5 eac785fee4efaf6d628a21397b2dd68d
BLAKE2b-256 f4b4cbbf6a1d2d965727180f68eb1b6a79efa3b910a7bdcef340e831d97003d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgtask-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on Kludex/pgtask

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 Sentry Error logging StatusPage Status page