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]
pgtaskis 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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40d82bca4a26d003650ee98899f5d649809ed44c9a280eb515ea89512fdb9372
|
|
| MD5 |
426678e6ce81b2f976ef5f4c646ed659
|
|
| BLAKE2b-256 |
a3cb22fd9d6ebe7565139becfab490b9a85da8d7c4cc097381384a598f2a3deb
|
Provenance
The following attestation bundles were made for pgtask-0.2.0.tar.gz:
Publisher:
release.yml on Kludex/pgtask
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pgtask-0.2.0.tar.gz -
Subject digest:
40d82bca4a26d003650ee98899f5d649809ed44c9a280eb515ea89512fdb9372 - Sigstore transparency entry: 2498466519
- Sigstore integration time:
-
Permalink:
Kludex/pgtask@8a1c97b138c165e331e92087380a3849a481fef2 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Kludex
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8a1c97b138c165e331e92087380a3849a481fef2 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3160bc86bdecbc255e30d74228bb665f696c00d18b77a9a0b21665305c2733d
|
|
| MD5 |
f28f55f26c28162752fa56c369711aa9
|
|
| BLAKE2b-256 |
08fbb8d376a070ffeefa170ece71f2cbcdf32a046e2ce44512e46a0d5483363b
|
Provenance
The following attestation bundles were made for pgtask-0.2.0-cp310-abi3-win_amd64.whl:
Publisher:
release.yml on Kludex/pgtask
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pgtask-0.2.0-cp310-abi3-win_amd64.whl -
Subject digest:
a3160bc86bdecbc255e30d74228bb665f696c00d18b77a9a0b21665305c2733d - Sigstore transparency entry: 2498466533
- Sigstore integration time:
-
Permalink:
Kludex/pgtask@8a1c97b138c165e331e92087380a3849a481fef2 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Kludex
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8a1c97b138c165e331e92087380a3849a481fef2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pgtask-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pgtask-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.10+, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c4f954c067ee17e278b57008ff9e619b69912cb2695aaa5d51e2390e256e7d9
|
|
| MD5 |
a1810a7f93a1deedc7f4de3a39a59e10
|
|
| BLAKE2b-256 |
5e8926d2d89553f8ba6e0c6b2d1d027fe29aa72937b5bd332d6c8c8c752d23dc
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pgtask-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl -
Subject digest:
9c4f954c067ee17e278b57008ff9e619b69912cb2695aaa5d51e2390e256e7d9 - Sigstore transparency entry: 2498466523
- Sigstore integration time:
-
Permalink:
Kludex/pgtask@8a1c97b138c165e331e92087380a3849a481fef2 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Kludex
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8a1c97b138c165e331e92087380a3849a481fef2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pgtask-0.2.0-cp310-abi3-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: pgtask-0.2.0-cp310-abi3-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.10+, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bdcf7efc83a91ce74691544b5da5a5d491de82d6cf9fbd1ad83b8ea23c0247a
|
|
| MD5 |
49ce45eaf2d6cc46daa6708ad4e515f2
|
|
| BLAKE2b-256 |
4193df4fa2d9d8433552abd1ed043d9cc8f2ba2a151b540cf9736b4644a6a71f
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pgtask-0.2.0-cp310-abi3-manylinux_2_28_aarch64.whl -
Subject digest:
6bdcf7efc83a91ce74691544b5da5a5d491de82d6cf9fbd1ad83b8ea23c0247a - Sigstore transparency entry: 2498466531
- Sigstore integration time:
-
Permalink:
Kludex/pgtask@8a1c97b138c165e331e92087380a3849a481fef2 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Kludex
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8a1c97b138c165e331e92087380a3849a481fef2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pgtask-0.2.0-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: pgtask-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 4.0 MB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8860b265ee347cfd6d57986a5485116b11f6bd2997895f7ee55247c496f3466
|
|
| MD5 |
28494b1c59323385e8faf64ce06002a2
|
|
| BLAKE2b-256 |
005dae3cde966794a69d7c3a7415646f1f69a96ae5248de2538b59fe83eccdce
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pgtask-0.2.0-cp310-abi3-macosx_11_0_arm64.whl -
Subject digest:
b8860b265ee347cfd6d57986a5485116b11f6bd2997895f7ee55247c496f3466 - Sigstore transparency entry: 2498466544
- Sigstore integration time:
-
Permalink:
Kludex/pgtask@8a1c97b138c165e331e92087380a3849a481fef2 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Kludex
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8a1c97b138c165e331e92087380a3849a481fef2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pgtask-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: pgtask-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 4.1 MB
- Tags: CPython 3.10+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5efc6dfb47a666c4d8e3a31532f3a4ee551cd8504274bbc64d72025ccd14710c
|
|
| MD5 |
eac785fee4efaf6d628a21397b2dd68d
|
|
| BLAKE2b-256 |
f4b4cbbf6a1d2d965727180f68eb1b6a79efa3b910a7bdcef340e831d97003d8
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pgtask-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl -
Subject digest:
5efc6dfb47a666c4d8e3a31532f3a4ee551cd8504274bbc64d72025ccd14710c - Sigstore transparency entry: 2498466527
- Sigstore integration time:
-
Permalink:
Kludex/pgtask@8a1c97b138c165e331e92087380a3849a481fef2 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Kludex
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8a1c97b138c165e331e92087380a3849a481fef2 -
Trigger Event:
release
-
Statement type: