Skip to main content

Intercept and capture progress information from tqdm progress bars via callbacks without modifying existing code.

Project description

cjm-tqdm-capture

Install

pip install cjm-tqdm-capture

Project Structure

nbs/
├── patch_tqdm.ipynb    # Provides the patching mechanism to intercept tqdm and emit callbacks with that progress information
└── progress_info.ipynb # Defines the data structure used to represent progress state

Total: 2 notebooks

Module Dependencies

graph LR
    patch_tqdm[patch_tqdm<br/>patch tqdm]
    progress_info[progress_info<br/>progress info]

    patch_tqdm --> progress_info

1 cross-module dependencies detected

CLI Reference

No CLI commands found in this project.

Module Overview

Detailed documentation for each module in the project:

patch tqdm (patch_tqdm.ipynb)

Provides the patching mechanism to intercept tqdm and emit callbacks with that progress information

Import

from cjm_tqdm_capture.patch_tqdm import (
    patch_tqdm
)

Functions

def _make_callback_class(
    BaseTqdm,  # Base tqdm class to extend with callback functionality
    default_cb: Optional[Callable[[ProgressInfo], None]],
    min_update_interval: float = 0.1,  # Minimum time between callback invocations (seconds)
    min_delta_pct: float = 1.0,      # emit only if pct moves by >= this
    emit_initial: bool = False       # whether to emit at 0%
)
    "Create a tqdm subclass that emits progress callbacks during iteration"
@contextmanager
def patch_tqdm(
    progress_callback: Optional[Callable[[ProgressInfo], None]],  # Function to call with progress updates
    min_update_interval: float = 0.1,  # Minimum time between callback invocations (seconds)
    min_delta_pct: float = 10.0,   # e.g., only every ~10%
    emit_initial: bool = False  # Whether to emit callback at 0% progress
)
    "Context manager that patches tqdm to emit progress callbacks"

progress info (progress_info.ipynb)

Defines the data structure used to represent progress state

Import

from cjm_tqdm_capture.progress_info import (
    ProgressInfo
)

Classes

@dataclass
class ProgressInfo:
    "Structured progress information"
    
    progress: float  # Percentage completion (0-100)
    current: Optional[int]  # Current iteration count
    total: Optional[int]  # Total iterations expected
    rate: Optional[str]  # Processing rate (e.g., "50.5 it/s")
    elapsed: Optional[str]  # Time elapsed since start
    remaining: Optional[str]  # Estimated time remaining
    description: Optional[str]  # Progress bar description/label
    raw_output: str = ''  # Raw output string (if any)
    timestamp: float  # Unix timestamp when created
    

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

cjm_tqdm_capture-0.0.2.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

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

cjm_tqdm_capture-0.0.2-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file cjm_tqdm_capture-0.0.2.tar.gz.

File metadata

  • Download URL: cjm_tqdm_capture-0.0.2.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for cjm_tqdm_capture-0.0.2.tar.gz
Algorithm Hash digest
SHA256 8e54973d188b082374f8e4528dee81d53247046472fb6a3f41da0a3a7afdb544
MD5 293c9f5de8e53501641ad055396ef142
BLAKE2b-256 9b8265d239baf0c154c5114cca0e49e45b6e72a1e6b1a38eae6e54c682d36031

See more details on using hashes here.

File details

Details for the file cjm_tqdm_capture-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for cjm_tqdm_capture-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 263f3834a8707ca1f539e09a0f1f53053d68e720f605154d1686aba556159704
MD5 24fdef790ad05765389aa902bb943f8e
BLAKE2b-256 473e673d1d5cf6fcc0a0daee9b7ea9278736380b535f9b9f0fc53adefbfa6178

See more details on using hashes here.

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