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.

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.5.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.5.0
File Size Uploaded Provenance Actions
pgtask-0.5.0.tar.gz 251.1 kB With provenance Details for pgtask-0.5.0.tar.gz

Built distributions (wheels)

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

Total release size: 22.9 MB

Release files / pgtask-0.5.0.tar.gz

Download URL pgtask-0.5.0.tar.gz
Size 251.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7cf093dc125541671ad55dc5866e754e65656803116cc32807690e76d56c5fca
BLAKE2b-256 checksum
How to use checksums
30268cce48b6a8f61f747fa97d8fb86608ce0bd0c12f84c6ce2ac610b9a37ac1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Dec 2, 2026.

Transparency log

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

Download URL pgtask-0.5.0-cp310-abi3-win_amd64.whl
Size 4.1 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
4e2593e65f460df1daa9abbef3465651cef2db97c0d28d9c8856a5dcb4c55177
BLAKE2b-256 checksum
How to use checksums
e5f05d597cda28e6d38a17c78a77be14df7b041b7dedd0bd327af6a09aba3a5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Dec 2, 2026.

Transparency log

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

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

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 Dec 2, 2026.

Transparency log

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

Download URL pgtask-0.5.0-cp310-abi3-manylinux_2_28_aarch64.whl
Size 4.8 MB
Tags CPython 3.10 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
76a6ac222493f6e2c40e9d4932e452cbc67ffa8accdbd4dcb0b35f541f45b8bb
BLAKE2b-256 checksum
How to use checksums
5b578ead4ab84fe96d00446d86084c6964f6f173db5f04b1fde72a14292a27af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Dec 2, 2026.

Transparency log

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

Download URL pgtask-0.5.0-cp310-abi3-macosx_11_0_arm64.whl
Size 4.4 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
076bf996f3a0b1b4d7be1522105ab2bfb5ac1624b70e6d7381ae0da41315b583
BLAKE2b-256 checksum
How to use checksums
88a407935a9f4adfa462271b0b24fd55c18e829e5d2b302b1e9062c8f2785745
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Dec 2, 2026.

Transparency log

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

Download URL pgtask-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 4.5 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
29629a21c68c55b47851f50b7a91dcfc9a26a07868025a407867a2eab854f086
BLAKE2b-256 checksum
How to use checksums
7c58f6453aacd0aa1ee5995a5426e73d154f79b33cfcc5c99642fc089bc8fb66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Dec 2, 2026.

Transparency log

Security for pgtask 0.5.0

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.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for pgtask-0.5.0.tar.gz

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 Dec 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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