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
Request timeout
API requests time out after 5 seconds by default. Override it with the timeout argument
(seconds), or with the TASKBADGER_HTTP_TIMEOUT environment variable, which the CLI also
honours:
taskbadger.init(token="***", timeout=30)
Pass an httpx.Timeout for finer control,
or httpx.Timeout(None) to disable timeouts entirely.
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.
Skipping tracking for a single Celery call
Pass taskbadger_track=False to leave one execution untracked. This overrides auto-tracking as
well as the taskbadger.Task base class:
noisy_job.apply_async(args, taskbadger_track=False)
Canvas primitives don't go through apply_async on the task itself, so pass it in the headers:
noisy_job.map(items).apply_async(headers={"taskbadger_track": False})
Metadata
Release files for taskbadger 2.7.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 |
|---|---|---|---|---|
| taskbadger-2.7.0.tar.gz | 49.4 kB | Without provenance | Details for taskbadger-2.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| taskbadger-2.7.0-py3-none-any.whl | Python 3 | none | any | Details for taskbadger-2.7.0-py3-none-any.whl |
Total release size: 134.8 kB
Release files / taskbadger-2.7.0.tar.gz
| Download URL | taskbadger-2.7.0.tar.gz |
|---|---|
| Size | 49.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ed2e2f47651e8ed3f0bec30d25ef8605012e66ff9ca6373f883d776072c864a1
|
|
BLAKE2b-256 checksum How to use checksums |
2b549b22f2091a87964b202532034dca2fcbc2d5690e097bd5323f0ab5d63633
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","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}
|
Release files / taskbadger-2.7.0-py3-none-any.whl
| Download URL | taskbadger-2.7.0-py3-none-any.whl |
|---|---|
| Size | 85.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ead579673a80b277f8120d19b912d0f951283269573c30aab89613e132723723
|
|
BLAKE2b-256 checksum How to use checksums |
0a52c61ac447b6f179babde486dd18cd5a34a3afefa24a9eb05a93ed5c4073c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","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}
|
Security for taskbadger 2.7.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.