Task Badger Python Client
This is the official Python SDK for Task Badger.
For full documentation go to https://docs.taskbadger.net/python/.
Getting Started
Install
pip install taskbadger
To use the taskbadger command-line tool, install the cli extra:
pip install 'taskbadger[cli]'
Client Usage
import taskbadger
from taskbadger.systems import CelerySystemIntegration
taskbadger.init(
token="***",
systems=[CelerySystemIntegration()],
tags={"environment": "production"}
)
CLI Usage
$ export TASKBADGER_API_KEY=***
$ taskbadger run "nightly-backup" -- ./backup.sh
Procrastinate Integration
The SDK includes optional support for the Procrastinate task queue.
Install with the extra:
pip install 'taskbadger[procrastinate]'
Opt a single task into tracking with the track decorator:
import procrastinate
from taskbadger.procrastinate import track, current_task
app = procrastinate.App(connector=...)
@track
@app.task(queue="default")
async def add(a, b):
return a + b
@track(name="report", value_max=100, tags={"env": "prod"})
@app.task
async def report(rows):
tb = current_task()
for i, row in enumerate(rows):
await process(row)
if i % 10 == 0:
tb.update(value=i)
To auto-track every task on an App, register the system integration:
import taskbadger
from taskbadger.systems.procrastinate import ProcrastinateSystemIntegration
taskbadger.init(
token="***",
systems=[ProcrastinateSystemIntegration(
app=app,
auto_track_tasks=True,
includes=[r"myapp\..*"],
excludes=[r"myapp\.cleanup\..*"],
record_task_args=True,
)],
)
Known limitations
task.configure(...).defer(...)is not tracked. Procrastinate'sconfigure()returns a separateJobDeferrerwhose methods bypass our wrapper. Usetask.defer(...)directly for tracked deferrals. Tasks deferred viaconfigure().defer()will run normally but will not appear in TaskBadger.task.batch_defer*is not tracked. Same reason asconfigure().defer().- Tasks added via
app.add_tasks_from(blueprint)afterProcrastinateSystemIntegrationis constructed are not auto-instrumented. Construct the integration after all blueprints are registered, or apply@trackto those tasks explicitly.
Keeping long-running tasks fresh
A task with a stale_timeout is marked stale by Task Badger if it goes too long without an
update. Set heartbeat_interval (seconds) to have the SDK ping the task for you while it runs,
rather than updating it from the task body.
For Procrastinate, on the task or on ProcrastinateSystemIntegration(...):
@track(heartbeat_interval=60)
@app.task
async def slow_job():
...
For Celery, on CelerySystemIntegration(...), on the task, or per call with
slow_job.apply_async(taskbadger_heartbeat_interval=60):
@app.task(base=taskbadger.Task, taskbadger_heartbeat_interval=60)
def slow_job():
...
Unless stale_timeout is given explicitly it is set to twice the interval. All running tasks are
pinged from a single background thread, started the first time a task with a heartbeat runs.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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 taskbadger-2.5.1.tar.gz.
File metadata
- Download URL: taskbadger-2.5.1.tar.gz
- Upload date:
- Size: 47.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.12.2 {"installer":{"name":"uv","version":"0.12.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fcaa7936edce0114203fd8ebb1ccb9b1fec1632ba3126227094134d7a0637eb
|
|
| MD5 |
78b17a9b0e127f5923a6646e6a4e2290
|
|
| BLAKE2b-256 |
fa9b96e3fe15c195e266717926e6b8b042b994600a62725462aec2a2ce5e472d
|
File details
Details for the file taskbadger-2.5.1-py3-none-any.whl.
File metadata
- Download URL: taskbadger-2.5.1-py3-none-any.whl
- Upload date:
- Size: 82.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.12.2 {"installer":{"name":"uv","version":"0.12.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
855905c9152d6b961ff1734c4916c3869038002275b32784e19ebf04417cd172
|
|
| MD5 |
d5df96dd1f0f9cc3eaded395bcf2b032
|
|
| BLAKE2b-256 |
0e33d6e0979ce85b83c238f5a9cba74472d56df995860adfbd9b52342a89826c
|