Progress API Reference¶
Complete API reference for Concurry's progress tracking.
Module: concurry.utils.progress
¶
Classes¶
ProgressBar¶
A progress bar implementation using tqdm with additional features.
This class provides beautiful, informative progress bars with rich features including: - Automatic success/failure/stop state indicators with color coding - Multiple styles (auto, notebook, standard, Ray) - Iterable wrapping for easy integration - Fine-grained control over updates - Customizable appearance
Example
from concurry.utils.progress import ProgressBar
import time
# Wrap an iterable
for item in ProgressBar(range(100), desc="Processing"):
time.sleep(0.01)
# Automatically shows success!
# Manual progress bar
pbar = ProgressBar(total=100, desc="Manual")
for i in range(100):
time.sleep(0.01)
pbar.update(1)
pbar.success("Complete!")
Source code in src/concurry/utils/progress.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 |
|
__init__(*args, pbar: Optional[TqdmProgressBar] = None, style: Literal['auto', 'notebook', 'std', 'ray'] = 'auto', unit: str = 'row', color: str = '#0288d1', ncols: Optional[int] = None, smoothing: Optional[float] = None, total: Optional[int] = None, disable: bool = False, miniters: Optional[int] = None, progress_bar: Union[bool, dict, ProgressBar] = True, prefer_kwargs: bool = True, **kwargs)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pbar
|
Optional[TqdmProgressBar]
|
Optional existing tqdm progress bar instance |
None
|
style
|
Literal['auto', 'notebook', 'std', 'ray']
|
Progress bar style. Options: - "auto": Automatically detect environment (default) - "notebook": Optimized for Jupyter notebooks - "std": Standard terminal output - "ray": Ray distributed progress (requires Ray) |
'auto'
|
unit
|
str
|
Unit name for items being processed (default: "row") |
'row'
|
color
|
str
|
Hex color code for the progress bar (default: "#0288d1" - blue) |
'#0288d1'
|
ncols
|
Optional[int]
|
Width of the progress bar in characters (default: global_config.defaults.progress_bar_ncols) |
None
|
smoothing
|
Optional[float]
|
Smoothing factor for progress updates (default: global_config.defaults.progress_bar_smoothing) |
None
|
total
|
Optional[int]
|
Total number of items to process |
None
|
disable
|
bool
|
Whether to disable the progress bar (default: False) |
False
|
miniters
|
Optional[int]
|
Minimum iterations between display updates (default: global_config.defaults.progress_bar_miniters) Higher values improve performance for large iteration counts |
None
|
progress_bar
|
Union[bool, dict, ProgressBar]
|
Progress bar configuration: - True: Use default configuration - False/None: Disable progress bar - dict: Configuration dictionary - ProgressBar: Existing ProgressBar instance to reuse |
True
|
prefer_kwargs
|
bool
|
Whether to prefer kwargs over progress_bar dict (default: True) |
True
|
**kwargs
|
Additional arguments to pass to tqdm |
{}
|
Example
Source code in src/concurry/utils/progress.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
update(n: int = 1) -> Optional[bool]
¶
Update the progress bar by n steps.
Updates are batched based on the miniters
parameter for better performance.
The display only updates when enough iterations have accumulated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
int
|
Number of steps to increment (default: 1) |
1
|
Returns:
Type | Description |
---|---|
Optional[bool]
|
True if the display was updated, None if the update was buffered |
Source code in src/concurry/utils/progress.py
set_n(new_n: int) -> None
¶
Set the current progress value directly.
This method sets the progress to an absolute value rather than incrementing. Useful for jumping to a specific point in the progress.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_n
|
int
|
The new progress value |
required |
Source code in src/concurry/utils/progress.py
set_total(new_total: int) -> None
¶
Set the total number of items to process.
This method allows dynamically updating the total when the final count becomes known or changes during processing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_total
|
int
|
The new total value |
required |
Example
Source code in src/concurry/utils/progress.py
set_description(desc: Optional[str] = None, refresh: Optional[bool] = True) -> Optional[str]
¶
Set the description of the progress bar.
This method allows dynamically updating the description text during processing, useful for showing different phases or stages.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
desc
|
Optional[str]
|
New description text |
None
|
refresh
|
Optional[bool]
|
Whether to refresh the display (default: True) |
True
|
Returns:
Type | Description |
---|---|
Optional[str]
|
The previous description |
Example
Source code in src/concurry/utils/progress.py
set_unit(new_unit: str) -> None
¶
Set the unit displayed in the progress bar.
This method allows changing the unit name during processing, useful when switching between different types of work (e.g., files to MB).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_unit
|
str
|
The new unit name (e.g., "files", "MB", "items") |
required |
Example
Source code in src/concurry/utils/progress.py
success(desc: Optional[str] = None, close: bool = True, append_desc: bool = True) -> None
¶
Mark the progress bar as successful (green color).
This method completes the progress bar with a success indicator, changing the color to green and optionally adding a success message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
desc
|
Optional[str]
|
Success message to display |
None
|
close
|
bool
|
Whether to close the progress bar (default: True) |
True
|
append_desc
|
bool
|
Whether to append to existing description (default: True) |
True
|
Example
Source code in src/concurry/utils/progress.py
stop(desc: Optional[str] = None, close: bool = True, append_desc: bool = True) -> None
¶
Mark the progress bar as stopped (grey color).
This method completes the progress bar with a stop indicator, changing the color to grey and optionally adding a stop message. Useful for indicating early termination or cancellation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
desc
|
Optional[str]
|
Stop message to display |
None
|
close
|
bool
|
Whether to close the progress bar (default: True) |
True
|
append_desc
|
bool
|
Whether to append to existing description (default: True) |
True
|
Example
Source code in src/concurry/utils/progress.py
failure(desc: Optional[str] = None, close: bool = True, append_desc: bool = True) -> None
¶
Mark the progress bar as failed (red color).
This method completes the progress bar with a failure indicator, changing the color to red and optionally adding a failure message. Use in exception handlers to indicate errors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
desc
|
Optional[str]
|
Failure message to display |
None
|
close
|
bool
|
Whether to close the progress bar (default: True) |
True
|
append_desc
|
bool
|
Whether to append to existing description (default: True) |
True
|
Example
Source code in src/concurry/utils/progress.py
refresh() -> None
¶
Refresh the progress bar display.
This method manually updates the progress bar display. It's typically called automatically by other methods, but can be called manually if needed.
Example
Source code in src/concurry/utils/progress.py
close() -> None
¶
Close and clean up the progress bar.
This method closes the progress bar and releases any resources. It's automatically called by success(), failure(), and stop() when close=True.
Example
Source code in src/concurry/utils/progress.py
Usage Examples¶
Basic Usage¶
from concurry.utils.progress import ProgressBar
import time
# Wrap an iterable
for item in ProgressBar(range(100), desc="Processing"):
time.sleep(0.01)
# Automatically shows success!
# Manual progress bar
pbar = ProgressBar(total=100, desc="Manual")
for i in range(100):
time.sleep(0.01)
pbar.update(1)
pbar.success("Complete!")
Customization¶
from concurry.utils.progress import ProgressBar
# Custom colors and settings
pbar = ProgressBar(
total=100,
desc="Processing",
unit="files",
color="#9c27b0", # Purple
ncols=120,
smoothing=0.1,
miniters=5
)
for i in range(100):
pbar.update(1)
pbar.success()
State Management¶
from concurry.utils.progress import ProgressBar
pbar = ProgressBar(total=100, desc="Processing")
try:
for i in range(100):
if error_condition:
raise ValueError("Error occurred")
process(i)
pbar.update(1)
pbar.success("All done!") # Green
except Exception as e:
pbar.failure(f"Failed: {e}") # Red
raise
Dynamic Updates¶
from concurry.utils.progress import ProgressBar
pbar = ProgressBar(total=100, desc="Phase 1")
for i in range(100):
# Update description dynamically
if i == 50:
pbar.set_description("Phase 2")
# Update total if needed
if i == 75 and more_work_discovered:
pbar.set_total(150)
pbar.update(1)
pbar.success()
Constructor Parameters¶
Required Parameters¶
total
(int, optional): Total number of items to process. Required for manual progress bars.
Optional Parameters¶
Display Options¶
desc
(str): Description shown before the progress barunit
(str): Unit name for items being processed (default: "row")color
(str): Hex color code for the progress bar (default: "#0288d1")ncols
(int): Width of the progress bar in characters (default: 100)
Behavior Options¶
style
(Literal["auto", "notebook", "std", "ray"]): Progress bar style (default: "auto")smoothing
(float): Smoothing factor for progress updates (default: 0.15)disable
(bool): Whether to disable the progress bar (default: False)miniters
(int): Minimum iterations between updates (default: 1)
Advanced Options¶
pbar
(TqdmProgressBar, optional): Existing tqdm progress bar instanceprogress_bar
(Union[bool, dict, ProgressBar]): Progress bar configuration or instanceprefer_kwargs
(bool): Whether to prefer kwargs over progress_bar dict (default: True)
Methods¶
update()¶
Update the progress bar by n steps.
Parameters:
- n
(int): Number of steps to increment (default: 1)
Returns:
- Optional[bool]
: True if display was updated, None if buffered
set_n()¶
Set the current progress value directly.
Parameters:
- new_n
(int): New progress value
set_total()¶
Set the total number of items.
Parameters:
- new_total
(int): New total value
set_description()¶
Set the description text.
Parameters:
- desc
(str, optional): New description
- refresh
(bool, optional): Whether to refresh display (default: True)
Returns:
- Optional[str]
: The previous description
set_unit()¶
Set the unit name.
Parameters:
- new_unit
(str): New unit name
success()¶
Mark the progress bar as successful (green color).
pbar.success() # Default success message
pbar.success("All done!") # Custom message
pbar.success("Complete", close=False) # Keep open
Parameters:
- desc
(str, optional): Success message
- close
(bool): Whether to close the progress bar (default: True)
- append_desc
(bool): Whether to append to existing description (default: True)
failure()¶
Mark the progress bar as failed (red color).
Parameters:
- desc
(str, optional): Failure message
- close
(bool): Whether to close the progress bar (default: True)
- append_desc
(bool): Whether to append to existing description (default: True)
stop()¶
Mark the progress bar as stopped (grey color).
Parameters:
- desc
(str, optional): Stop message
- close
(bool): Whether to close the progress bar (default: True)
- append_desc
(bool): Whether to append to existing description (default: True)
refresh()¶
Manually refresh the progress bar display.
close()¶
Close and clean up the progress bar.
Type Signatures¶
ProgressBar Class¶
from concurry.utils.progress import ProgressBar
from typing import Literal, Optional, Union
class ProgressBar:
def __init__(
self,
*args,
pbar: Optional[TqdmProgressBar] = None,
style: Literal["auto", "notebook", "std", "ray"] = "auto",
unit: str = "row",
color: str = "#0288d1",
ncols: int = 100,
smoothing: float = 0.15,
total: Optional[int] = None,
disable: bool = False,
miniters: int = 1,
progress_bar: Union[bool, dict, ProgressBar] = True,
prefer_kwargs: bool = True,
**kwargs,
) -> None:
...
def update(self, n: int = 1) -> Optional[bool]:
...
def set_n(self, new_n: int) -> None:
...
def set_total(self, new_total: int) -> None:
...
def set_description(
self,
desc: Optional[str] = None,
refresh: Optional[bool] = True
) -> Optional[str]:
...
def set_unit(self, new_unit: str) -> None:
...
def success(
self,
desc: Optional[str] = None,
close: bool = True,
append_desc: bool = True
) -> None:
...
def stop(
self,
desc: Optional[str] = None,
close: bool = True,
append_desc: bool = True
) -> None:
...
def failure(
self,
desc: Optional[str] = None,
close: bool = True,
append_desc: bool = True
) -> None:
...
def refresh(self) -> None:
...
def close(self) -> None:
...
Progress Bar Styles¶
auto¶
Automatically detects the environment: - Uses notebook style in Jupyter/IPython - Uses standard terminal style otherwise
notebook¶
Optimized for Jupyter notebooks with rich HTML widgets.
std¶
Standard terminal-based progress bar.
ray¶
Integrates with Ray's distributed progress tracking (requires Ray).
Color Codes¶
Default colors for different states:
- Progress:
#0288d1
(blue) - Success:
#43a047
(green) - Failure:
#e64a19
(red) - Stop:
#b0bec5
(grey)
Custom colors can be specified as hex codes:
See Also¶
- Progress User Guide - Learn how to use progress bars
- Examples - See practical examples
- Futures API - Futures API reference