Putting task progress in contextvars
Project description
Context Progress
Context Progress lets you emit progress updates from anywhere in a call chain without passing progress objects through every function.
It uses a context-local task stack, so nested work can report progress via a small global API.
Install
Base package:
uv add context-progress
With Rich integration:
uv add 'context-progress[rich]'
Core API
add(backend): register a backend for the current context.remove(backend): unregister a backend.subtask(name, description=None, total=None): create a nested task scope.update(description=..., total=..., advance=...): push updates to all active backends.
RichProgress
context_progress.richprogress.RichProgress is a Rich backend for the core API.
Use RichProgress.session(...) for the simplest setup. It creates an
SProgress instance, registers the backend on enter, and unregisters it on
exit.
from time import sleep
from rich.progress import BarColumn, TaskProgressColumn, TextColumn, TimeElapsedColumn
from context_progress import subtask, update
from context_progress.richprogress import RichProgress
def run_step(description: str, total: int, delay: float = 0.1) -> None:
update(description=description)
for _ in range(total):
sleep(delay)
update(advance=1)
with RichProgress.session(
TextColumn("[progress.description]{task.description}"),
BarColumn(),
TaskProgressColumn(),
TimeElapsedColumn(),
):
with subtask("download", total=2):
run_step("metadata", total=2)
with subtask("artifacts", total=3):
run_step("files", total=3)
For a complete runnable example, see examples/richprogress.py.
RichProgress Behavior
- Nested subtasks are indented for readability.
- Child tasks are inserted directly after their parent in render order.
- Updating a
RichTaskdescription keeps the task name as a prefix.
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
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 context_progress-0.1.3.tar.gz.
File metadata
- Download URL: context_progress-0.1.3.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10f39882217671291e3201490d638f2c974779ac7b5a7c7487cee83441f87945
|
|
| MD5 |
75f752063889a1be4d95309d2672ac7a
|
|
| BLAKE2b-256 |
8aba0cd3fc67968f7f9b4a2f27525ed007b9f1326dbb803865af29cd04b681d4
|
Provenance
The following attestation bundles were made for context_progress-0.1.3.tar.gz:
Publisher:
release.yml on KalleDK/py-context-progress
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
context_progress-0.1.3.tar.gz -
Subject digest:
10f39882217671291e3201490d638f2c974779ac7b5a7c7487cee83441f87945 - Sigstore transparency entry: 2189927085
- Sigstore integration time:
-
Permalink:
KalleDK/py-context-progress@e228fcfbbfd49011f5e49943c8293341743f0983 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/KalleDK
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e228fcfbbfd49011f5e49943c8293341743f0983 -
Trigger Event:
push
-
Statement type:
File details
Details for the file context_progress-0.1.3-py3-none-any.whl.
File metadata
- Download URL: context_progress-0.1.3-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1db608c774fe190f2f64d21638640d880b78b645295dd243bc84dd86f424f3d
|
|
| MD5 |
080dcbc3f7682a809d13cf1b05986f4a
|
|
| BLAKE2b-256 |
918779b716e7a552d6e9236884819c51d29f23fffb287c0c94a515b55a23546e
|
Provenance
The following attestation bundles were made for context_progress-0.1.3-py3-none-any.whl:
Publisher:
release.yml on KalleDK/py-context-progress
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
context_progress-0.1.3-py3-none-any.whl -
Subject digest:
c1db608c774fe190f2f64d21638640d880b78b645295dd243bc84dd86f424f3d - Sigstore transparency entry: 2189927189
- Sigstore integration time:
-
Permalink:
KalleDK/py-context-progress@e228fcfbbfd49011f5e49943c8293341743f0983 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/KalleDK
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e228fcfbbfd49011f5e49943c8293341743f0983 -
Trigger Event:
push
-
Statement type: