Skip to main content

Add your description here

Project description

pg-task-tracker

A simple Python library for tracking multi-step task progress in PostgreSQL (or SQLite).

Installation

pip install pg-task-tracker

Quick Start

from sqlmodel import create_engine
from pg_task_tracker import create_task, get_task, ensure_schema

engine = create_engine("postgresql+psycopg2://user:pass@localhost/mydb")
ensure_schema(engine)

task = create_task(engine, "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")

Resuming a Task

task = get_task(engine, task_id)

for step in task.get_steps():
    print(f"{step.name}: {step.status}")

Database Strategy

Every method that mutates state commits immediately — there is no batching or deferred writes. This means each call is a separate database round-trip. Plan accordingly if you are tracking a large number of steps.

Method DB Operations Round-trips
ensure_schema(engine) CREATE TABLE IF NOT EXISTS for each table 1
create_task(engine, ...) INSERT into ptt_task 1
get_task(engine, 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
get_migration_sql() None (reads bundled .sql file from package) 0

For a typical task with N steps where each step transitions through pending -> running -> completed, expect roughly 2N + 2 round-trips: 1 to create the task, 1 per add_step, 2 per update_step, and 1 to update the final task status.

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())
# Copy and run with psql, or apply however you manage migrations

Step Statuses

Steps and tasks use the same set of statuses: pending, running, completed, failed.

Timestamps are managed automatically:

  • started_at is set when a step moves to running
  • completed_at is set when a step moves to completed or failed

Table Names

All tables are prefixed with st_ to avoid conflicts:

  • ptt_task
  • ptt_task_step

Project details


Download files

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

Source Distribution

pg_task_tracker-0.3.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

pg_task_tracker-0.3.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file pg_task_tracker-0.3.0.tar.gz.

File metadata

  • Download URL: pg_task_tracker-0.3.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.13

File hashes

Hashes for pg_task_tracker-0.3.0.tar.gz
Algorithm Hash digest
SHA256 cc7632f2b9f7327df9499fbb568397bafc71a3b63e7dbd77ab546661252e49be
MD5 a2ab3e8907fd3d3de322ab85e84ce5a0
BLAKE2b-256 dd18613459cc5c3ccbf0a3b6c7c397f2e3c837bc9b5db514a9d32378aa026f45

See more details on using hashes here.

File details

Details for the file pg_task_tracker-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pg_task_tracker-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dbebe0c9860702944d564c8d9e08860d08481a8b769f477ea52a5be0c6732244
MD5 45f45c2950a0a8f950cf77296139eb18
BLAKE2b-256 7c81aaf579ecc75ad5d4db19b02cec634b5a0d6c563829c67a399411eb6db97d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page