Skip to main content

Lightweight background task monitor with live progress, ETA, hooks, concurrent tasks, and SQLite history

Project description

taskpulse

Lightweight background task monitor — live progress bars, ETA, elapsed time, concurrent tasks, callback hooks, and SQLite history. No Celery, no Redis, pure Python.

PyPI version Python License: MIT


Installation

pip install taskpulse

No dependencies. Requires Python 3.8+.


Quick Start

from taskpulse import TaskPulse

pulse = TaskPulse()

@pulse.task(name="Process files", total=100)
def process(task):
    for i in range(100):
        do_work()
        task.update(i + 1)
    return "done"

t = pulse.run(process)
pulse.wait(t.id)
print(t.result)   # "done"

Terminal output:

  ⚡ Process files           [████████████░░░░░░░░░░░░░░░░░░]  41.0%  elapsed 2.1s  ETA 3.0s
  ✅ Process files           [done]                             elapsed 5.1s

Usage

Define Tasks

# Decorator style
@pulse.task(name="My Task", total=50)
def my_task(task):
    for i in range(50):
        process_item(i)
        task.update(i + 1)   # report progress
    return "finished"

# Run it
t = pulse.run(my_task)
# Inline (no decorator)
def simple(task, items):
    for i, item in enumerate(items):
        process(item)
        task.update(i + 1, total=len(items))
    return len(items)

t = pulse.run(simple, my_items, name="Process items")

Progress Updates

def fn(task):
    task.update(5)           # just update progress
    task.update(10, total=50)  # also update total

Concurrent Tasks

tasks = [pulse.run(process, batch) for batch in batches]
pulse.wait(*[t.id for t in tasks])   # wait for all

Hooks

def on_start(task):
    print(f"Starting: {task.name}")

def on_progress(task):
    if task.percent and task.percent > 50:
        notify_team("halfway done")

def on_done(task):
    send_email(f"Task complete: {task.result}")

def on_error(task):
    alert(f"Task failed: {task.error}")

@pulse.task(
    name="Important Job",
    on_start=on_start,
    on_progress=on_progress,
    on_done=on_done,
    on_error=on_error,
)
def important_job(task):
    ...

Task Status

task = pulse.get("task-0001")
print(task.status)    # TaskStatus.RUNNING
print(task.percent)   # 42.0
print(task.elapsed)   # 3.2  (seconds)
print(task.eta)       # 4.4  (seconds remaining)
print(task.result)    # None while running
print(task.error)     # None if no error

Live Dashboard

from taskpulse import TaskPulse
from taskpulse import Monitor

pulse = TaskPulse(show_progress=False)
monitor = Monitor(pulse, refresh=0.5)
monitor.start()

for batch in batches:
    pulse.run(process, batch)

pulse.wait()
monitor.stop()

SQLite History

# Full run history persisted across restarts
history = pulse.history(limit=20)
for run in history:
    print(run["name"], run["status"], run["elapsed"])

API Reference

TaskPulse

TaskPulse(
    db_path="taskpulse.db",  # SQLite history file
    max_workers=4,            # Max concurrent tasks
    show_progress=True,       # Live progress bars
)
Method Description
task(name, total, on_start, ...) Decorator to define a task
run(func, *args, **kwargs) Submit task, returns Task immediately
wait(*task_ids, timeout) Block until tasks complete
get(task_id) Get Task by ID
all_tasks() List all Task objects
status() List of status dicts
history(limit) Run history from SQLite
print_status() Print formatted table
cancel(task_id) Cancel a pending task

Task

Attribute Type Description
id str Unique task ID
name str Task name
status TaskStatus pending/running/done/failed/cancelled
progress int Current step count
total int | None Total steps
percent float | None 0-100
elapsed float Seconds since start
eta float | None Estimated seconds remaining
result Any Return value (when done)
error str | None Traceback (when failed)

Running Tests

pip install pytest
pytest tests/ -v

License

MIT © prabhay759

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

taskpulse-1.0.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

taskpulse-1.0.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file taskpulse-1.0.0.tar.gz.

File metadata

  • Download URL: taskpulse-1.0.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for taskpulse-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f31dc0c0e9d25478209cb7d8b777fa53dc0fdd2ff72dd550576b9ba07641864a
MD5 20b3c773be0d23cab9f812e180ce9616
BLAKE2b-256 2b6fc24ea51939dcb4c04536ec25367dcc1f304815876c3506f313703efe6216

See more details on using hashes here.

Provenance

The following attestation bundles were made for taskpulse-1.0.0.tar.gz:

Publisher: Publish.yml on prabhay759/taskpulse

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file taskpulse-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: taskpulse-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for taskpulse-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 586e75453cc672f28293972868db492e75fe9168fd97d62e79f4058dd9a78713
MD5 c1f06ea2df5ffffa8e2cc760f75eb691
BLAKE2b-256 83d99786585cf1648959e9cea5c1d1f2bcf9750574fcad785525e024a697bf25

See more details on using hashes here.

Provenance

The following attestation bundles were made for taskpulse-1.0.0-py3-none-any.whl:

Publisher: Publish.yml on prabhay759/taskpulse

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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