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.

Metadata

Release files for pgtask 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pgtask 0.3.0
File Size Uploaded
pgtask-0.3.0.tar.gz 206.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pgtask 0.3.0
File
pgtask-0.3.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
pgtask-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64 Details
pgtask-0.3.0-cp310-abi3-manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.28+ ARM64 Details
pgtask-0.3.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
pgtask-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 21.0 MB

Release files / pgtask-0.3.0.tar.gz

Download URL pgtask-0.3.0.tar.gz
Size 206.9 kB
Tags Source
SHA-256 checksum
How to use checksums
bb7d3189e0d599ff0cfc9a82064c1a516b37bb1a1c6da536a930d230b3b06a6f
BLAKE2b-256 checksum
How to use checksums
4250163df9cd15865d7245a33b6c790b13d1b287b2e36799084006ffaada449c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release files / pgtask-0.3.0-cp310-abi3-win_amd64.whl

Download URL pgtask-0.3.0-cp310-abi3-win_amd64.whl
Size 3.8 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
8d102537613ee4a5eeca7ff4cfc23c4d085da318ac10c836180577fa588023e1
BLAKE2b-256 checksum
How to use checksums
a3f474bd9ee45535444eba5e7920c6ac093cd7fdd0312a412c1197ac7a139f5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release files / pgtask-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl

Download URL pgtask-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl
Size 4.4 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
d43de8d01c4a568975f805149a5edcd3e2e5bba39dbed21c23af41ac33e4de0b
BLAKE2b-256 checksum
How to use checksums
fd6523031c09795f28e50f571108327350c959b674eb5f82c4cda73342aac224
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release files / pgtask-0.3.0-cp310-abi3-manylinux_2_28_aarch64.whl

Download URL pgtask-0.3.0-cp310-abi3-manylinux_2_28_aarch64.whl
Size 4.4 MB
Tags CPython 3.10 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
f9d6098f357fbaf510a0f9c192088252906baaa354d9cc07bf8c1128be986969
BLAKE2b-256 checksum
How to use checksums
770d8a369ce96318e7a5fd22203d2a6273ce5301d82b8d85f9f824207f059674
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release files / pgtask-0.3.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL pgtask-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
Size 4.0 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a4245161da2523b6dbfc223531494208399f73fbfcfcf596ec288d05c851cb11
BLAKE2b-256 checksum
How to use checksums
899bab0b07ee9f7393580a09a61302588b7b6112159e05d9351f937fc5621018
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release files / pgtask-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL pgtask-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 4.2 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
6eb051d7ccc6a4bd7e73afc9093188f390ab6cf7e0a1a5dbf40ba80e268ba215
BLAKE2b-256 checksum
How to use checksums
8a9a612f1995036126fac9e5af8eefe8cf373dc528086e19e144f178d703e030
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

6 release files

0.2.0

6 release files

0.1.3

6 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page