Skip to main content

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 RichTask description 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

context_progress-0.1.4.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

context_progress-0.1.4-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file context_progress-0.1.4.tar.gz.

File metadata

  • Download URL: context_progress-0.1.4.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

Hashes for context_progress-0.1.4.tar.gz
Algorithm Hash digest
SHA256 6d85d79e51b6a6e81192914476502f5dde135b4a57f0a24c4f4fa46928c17dfe
MD5 2e4619325125c8375774f9afe2482574
BLAKE2b-256 71cd92060105b0618e2e0f340183e8b2ec000293e7cbd82486bddefa09ad607e

See more details on using hashes here.

Provenance

The following attestation bundles were made for context_progress-0.1.4.tar.gz:

Publisher: release.yml on KalleDK/py-context-progress

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

File details

Details for the file context_progress-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for context_progress-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3cc38f461a26530edbcb9488b9900f693f1c7405fe3dbf92795410a13d53a07f
MD5 d882b2a717e1b511e65695712a0c0991
BLAKE2b-256 6c2f5cdfee4b5de1d1ca0fad6ab9b906b61ee2e54951742d00427281453683fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for context_progress-0.1.4-py3-none-any.whl:

Publisher: release.yml on KalleDK/py-context-progress

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