Implementation:Iterative Dvc Progress
| Knowledge Sources | |
|---|---|
| Domains | User_Interface, Progress_Display |
| Last Updated | 2026-02-10 10:00 GMT |
Overview
dvc/progress.py (170 lines) defines the Tqdm class, a custom subclass of tqdm.tqdm that provides DVC-specific progress bar formatting. It features auto-disable logic based on logging level and TTY detection, byte-scale defaults, and custom bar format strings for nested and no-total scenarios.
from dvc.progress import Tqdm
Source File
| Property | Value |
|---|---|
| File | dvc/progress.py
|
| Lines | 170 |
| Class | Tqdm
|
| Extends | tqdm.tqdm
|
Module-Level Setup
The module sets a thread-safe lock on the tqdm class using tqdm.set_lock(RLock()), ensuring that progress bar updates are safe in multi-threaded contexts.
Class: Tqdm
Tqdm is described as a "maximum-compatibility tqdm-based progressbar" that adapts its behavior to DVC's logging and output requirements.
Class Constants
| Constant | Description |
|---|---|
BAR_FMT_DEFAULT |
Standard bar format showing percentage, description, bar, counts, timing, and rate |
BAR_FMT_DEFAULT_NESTED |
Format for nested bars with fixed 10-character bar width for alignment |
BAR_FMT_NOTOTAL |
Format used when total is unknown (no percentage, no remaining time) |
BYTES_DEFAULTS |
Default kwargs for byte-scale display: unit="B", unit_scale=True, unit_divisor=1024, miniters=1
|
Constructor
def __init__(
self,
iterable=None,
disable=None,
level=logging.ERROR,
desc=None,
leave=False,
bar_format=None,
bytes=False,
file=None,
total=None,
postfix=None,
**kwargs,
)
The constructor implements several layers of smart defaults:
- Byte mode: If
bytes=True, mergesBYTES_DEFAULTSinto kwargs - Unit scale: If not in byte mode, auto-scales units when total exceeds 999
- File target: Defaults to
sys.stderr - Auto-disable (log level): Disables the bar if the effective logging level exceeds the specified
level(default:ERROR) - Auto-disable (TTY): Disables the bar if the output file is not a TTY, unless
DVC_IGNORE_ISATTYenvironment variable is set - Bar format selection: After initialization, selects the appropriate format:
BAR_FMT_DEFAULT_NESTEDif the bar is nested (non-zero position)BAR_FMT_DEFAULTfor standard bars with a known totalBAR_FMT_NOTOTALwhen the total is unknown
Methods
update_msg
def update_msg(self, msg: str, n: int = 1) -> None
Convenience method that sets a message as postfix and advances the bar by n units.
set_msg
def set_msg(self, msg: str) -> None
Sets the info postfix to " {msg} |" for display between the bar and the counts.
update_to
def update_to(self, current, total=None) -> None
Sets the progress to an absolute position current (rather than an increment). Optionally updates the total. Calculates the delta from the current position and calls update().
wrap_fn
def wrap_fn(self, fn, callback=None)
Returns a wrapped version of fn that calls callback (defaults to self.update) after each invocation. Useful for adding progress tracking to any callable.
close
def close(self) -> None
Clears the info postfix and cleans up the bar format by removing the ETA display (<{remaining}) and the nested bar indicator (|{bar:10}|). Then calls the parent close().
format_dict (property)
@property
def format_dict(self) -> dict
Overrides the parent property to inject ncols_desc and ncols_info values, which dynamically fill the available display width. This is calculated by rendering the bar format with placeholder widths and measuring the remaining space. Falls back to width 1 with an empty prefix if no space remains.
as_callback
def as_callback(self) -> "TqdmCallback"
Wraps the progress bar instance in a TqdmCallback from dvc.fs.callbacks, enabling its use as a filesystem transfer callback.
Key Dependencies
| Module | Usage |
|---|---|
tqdm.tqdm |
Base progress bar class |
dvc.env.DVC_IGNORE_ISATTY |
Environment variable to override TTY detection |
dvc.utils.env2bool |
Converts environment variable to boolean |
dvc.fs.callbacks.TqdmCallback |
Callback adapter for filesystem operations |
See Also
- Implementation:Lock -- Uses Tqdm for lock acquisition waiting display
- Implementation:Dependency_Db -- Uses progress display for database downloads