pg-task-tracker
A simple Python library for tracking multi-step task progress in PostgreSQL.
Installation
pip install pg-task-tracker
Setup
from sqlmodel import create_engine
import pg_task_tracker
from pg_task_tracker import ensure_schema
engine = create_engine("postgresql+psycopg2://user:pass@localhost/mydb")
ensure_schema(engine)
pg_task_tracker.init(engine)
ensure_schema(engine) creates the tables if they don't exist. pg_task_tracker.init(engine) stores the engine so you don't have to pass it to every call. Both are one-time setup.
Decorator
The simplest way to track a function:
from pg_task_tracker import track
@track()
def run_pipeline():
extract_data()
transform_data()
load_data()
run_pipeline()
This creates a task named "run_pipeline" and sets its status to "completed" or "failed" based on whether the function raises an exception. The exception is always re-raised.
Override the task name:
@track(name="nightly-etl")
def run_pipeline():
...
Manual Tracking
For more control, create tasks and steps explicitly:
from pg_task_tracker import create_task, get_task
task = create_task("etl-pipeline")
task.add_step("extract", status="running")
task.update_step("extract", status="completed", metadata={"rows": 5000})
task.add_step("transform", status="running")
task.update_step("transform", status="completed", metadata={"duration_s": 12.3})
task.add_step("load", status="running")
task.update_step("load", status="failed", metadata={"error": "connection timeout"})
task.update_status("failed")
Resume an existing task by ID:
task = get_task(task_id)
for step in task.get_steps():
print(f"{step.name}: {step.status}")
Both create_task and get_task accept an optional engine= parameter to override the initialized engine.
Step Statuses
Steps and tasks use the same set of statuses: pending, running, completed, failed.
Timestamps are managed automatically:
started_atis set when a step moves torunningcompleted_atis set when a step moves tocompletedorfailed
Database Strategy
Every method that mutates state commits immediately — there is no batching or deferred writes. Each call is a separate database round-trip.
| Method | DB Operations | Round-trips |
|---|---|---|
ensure_schema(engine) |
CREATE TABLE IF NOT EXISTS for each table |
1 |
create_task(name) |
INSERT into ptt_task |
1 |
get_task(task_id) |
SELECT from ptt_task to verify existence |
1 |
task.add_step(...) |
INSERT into ptt_task_step |
1 |
task.update_step(...) |
SELECT + UPDATE on ptt_task_step |
2 |
task.update_status(...) |
SELECT + UPDATE on ptt_task |
2 |
task.get_steps() |
SELECT from ptt_task_step ordered by created_at |
1 |
@track() |
INSERT + SELECT + UPDATE (create task + update status) |
3 |
get_migration_sql() |
None (reads bundled .sql file from package) |
0 |
For manual tracking with N steps where each transitions through running -> completed, expect roughly 2N + 2 round-trips.
Schema Management
Create tables automatically:
ensure_schema(engine)
Or apply the bundled SQL migration manually:
from pg_task_tracker import get_migration_sql
print(get_migration_sql())
# Apply with psql or your preferred migration tool
Table Names
All tables are prefixed with ptt_ to avoid conflicts:
ptt_taskptt_task_step
Metadata
Release files for pg-task-tracker 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pg_task_tracker-0.5.0.tar.gz | 5.1 kB | Without provenance | Details for pg_task_tracker-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pg_task_tracker-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for pg_task_tracker-0.5.0-py3-none-any.whl |
Total release size: 12.9 kB
Release files / pg_task_tracker-0.5.0.tar.gz
| Download URL | pg_task_tracker-0.5.0.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2a2196c58f555609d93b9f9b2c118bbde193b1cb2775cb88625190dda6224ffe
|
|
BLAKE2b-256 checksum How to use checksums |
f1ebb6cb9e0bf8b67cb1f605a317016474b2f3f349e7f630070595053ca43db5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.13
|
Release files / pg_task_tracker-0.5.0-py3-none-any.whl
| Download URL | pg_task_tracker-0.5.0-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f1516dc638ff130b680515a4cfb22451e326a3f61b67f6c712cf9146b73b75da
|
|
BLAKE2b-256 checksum How to use checksums |
64252142435816bdc7ad1f44886b2e58b2df836672f47220d61e8cc9bf9b2d83
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.13
|
Security for pg-task-tracker 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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.