API reference
Implements the generic progress logger class, and the ProgressBar class.
- class proglog.MuteProgressBarLogger(init_state=None, bars=None, ignored_bars=None, logged_bars='all', min_time_interval=0, ignore_bars_under=0)
Bases:
ProgressBarLogger
- bar_is_ignored(bar)
- class proglog.ProgressBarLogger(init_state=None, bars=None, ignored_bars=None, logged_bars='all', min_time_interval=0, ignore_bars_under=0)
Bases:
ProgressLogger
Generic class for progress loggers.
A progress logger contains a “state” dictionary.
- Parameters:
init_state (dict) – Initial state of the logger.
bars (None, list, tuple, or dict, optional) – Either None (will be initialized with no bar) or a list/tuple of bar names (e.g., [‘main’, ‘sub’]) which will be initialized with index -1 and no total, or a dictionary (possibly ordered) of bars, of the form {bar_1: {title: ‘bar1’, index: 2, total: 23}, bar_2: {…}}.
ignored_bars (None, list of str, or 'all_others', optional) – Either None (newly met bars will be added) or a list of blacklisted bar names, or ‘all_others’ to signify that all bar names not already in self.bars will be ignored.
logged_bars
min_time_interval (int or float) – Time in seconds between progress bar updates.
ignore_bars_under (int)
- bar_indent = 2
- bar_is_ignored(bar)
- bar_is_logged(bar)
- property bars
Return
self.state['bars'].
- bars_callback(bar, attr, value, old_value=None)
Execute a custom action after the progress bars are updated.
- Parameters:
bar – Name/ID of the bar to be modified.
attr – Attribute of the bar attribute to be modified
value – New value of the attribute
old_value – Previous value of this bar’s attribute.
nothing (This default callback does)
subclassing. (overwrite it by)
- iter_bar(bar_prefix='', **kw)
Iterate through a list while updating a state bar.
- Parameters:
bar_prefix (str) – Bar prefix.
Examples
>>> for username in logger.iter_bar(user=['tom', 'tim', 'lea']): >>> # At every loop, logger.state['bars']['user'] is updated >>> # to {index: i, total: 3, title:'user'} >>> print (username)
- iterable_is_too_short(iterable)
- class proglog.ProgressLogger(init_state=None)
Bases:
object
Generic class for progress loggers.
A progress logger contains a “state” dictionary.
- Parameters:
init_state (dict) – Dictionary representing the initial state.
- callback(**kw)
Execute something after the state has been updated by the given state elements.
This default callback does nothing, overwrite it by subclassing.
- dump_logs(filepath=None)
- iter(**kw)
Iterate through a list while updating the state.
Examples
>>> for username in logger.iter(user=['tom', 'tim', 'lea']): >>> # At every loop, logger.state['user'] is updated >>> print(username)
- log(message)
- store(**kw)
Store objects in the logger and trigger
self.store_callback
.This works exactly like
logger()
, but the later is meant for simple data objects (text, numbers) that will be sent over the network or written to a file. Thestore
method expects rather large objects which are not necessarily serializable, and will be used eg to draw plots on the fly.
- store_callback(**kw)
Execute something after the store has been updated by the given state elements.
This default callback does nothing, overwrite it by subclassing
- class proglog.RqWorkerBarLogger(job, init_state=None, bars=None, ignored_bars=(), logged_bars='all', min_time_interval=0)
- class proglog.TqdmProgressBarLogger(init_state=None, bars=None, leave_bars=False, ignored_bars=None, logged_bars='all', notebook='default', print_messages=True, min_time_interval=0, ignore_bars_under=0)
Bases:
ProgressBarLogger
Tqdm-powered progress bar for console or Notebooks.
- Parameters:
init_state (dict) – Initial state of the logger.
bars (None, list, tuple, or dict, optional) – Either None (will be initialized with no bar) or a list/tuple of bar names (e.g., [‘main’, ‘sub’]) which will be initialized with index -1 and no total, or a dictionary (possibly ordered) of bars, of the form {bar_1: {title: ‘bar1’, index: 2, total: 23}, bar_2: {…}}.
leave_bars (bool, optional) – Whether to leave the progress bars displayed upon completion.
ignored_bars (None, list of str, or 'all_others', optional) – Either None (newly met bars will be added) or a list of blacklisted bar names, or ‘all_others’ to signify that all bar names not already in self.bars will be ignored.
notebook (bool, optional) – True will make the bars look nice (HTML) in the Jupyter notebook. It is advised to leave to ‘default’ as the default can be globally set from inside a notebook with import proglog; proglog.notebook_mode().
print_messages (bool) – If True, every logger(message=’something’) will print a message in the console or notebook.
min_time_interval (int or float) – Time in seconds between progress bar updates.
ignore_bars_under (int)
- bars_callback(bar, attr, value, old_value)
Execute a custom action after the progress bars are updated.
- Parameters:
bar – Name/ID of the bar to be modified.
attr – Attribute of the bar attribute to be modified
value – New value of the attribute
old_value – Previous value of this bar’s attribute.
nothing (This default callback does)
subclassing. (overwrite it by)
- callback(**kw)
Execute something after the state has been updated by the given state elements.
This default callback does nothing, overwrite it by subclassing.
- close_tqdm_bar(bar)
Close and erase the tqdm bar.
- new_tqdm_bar(bar)
Create a new tqdm bar, possibly replacing an existing one.
- proglog.default_bar_logger(logger, bars=None, ignored_bars=None, logged_bars='all', min_time_interval=0, ignore_bars_under=0)
- proglog.notebook(turn='on')
- proglog.troncate_string(s, max_length=25)