tqdm.std.tqdm โ Decorate an iterable object, returning an iterator which acts exactly like the original iterable, but prints a dynamically updating progress bar every time a value is requested.
| Use Case | Command | Description |
|---|---|---|
| ๐ Basic iterable | for i in tqdm(range(100)): | Wrap any iterable with a progress bar |
| ๐ก Manual update | t = tqdm(total=filesize); t.update(len(buf)) | Manually advance the bar (e.g., streaming) |
| ๐งต Context manager | with tqdm(total=100) as pbar: | Auto-cleanup on exit |
| ๐ผ pandas integration | tqdm.pandas(); df.progress_apply(func) | Progress bars for pandas apply methods |
| ๐ Write messages | tqdm.write('Log message') | Print without overlapping the bar |
| โฑ๏ธ Reset bar | pbar.reset(total=200) | Reuse a progress bar with a new total |
iterable : iterable, optionaldesc : str, optionaltotal : int or float, optionallen(iterable) is used if possible. If float("inf") or as a last resort, only basic statistics are displayed (no ETA, no progress bar). If gui is True and this needs later updating, specify an initial large positive number, e.g. 9e9.leave : bool, optionalTrue], keeps all traces of the progress bar upon termination. If None, will leave only if position is 0.file : io.TextIOWrapper or io.StringIO, optionalsys.stderr). Uses file.write(str) and file.flush(). For encoding, see write_bytes.ncols : int, optional0, only stats are printed (no bar).mininterval : float, optional0.1] seconds.maxinterval : float, optional10] seconds. Automatically adjusts miniters after long lag. Only works if dynamic_miniters or monitor thread is enabled.miniters : int or float, optional0 and dynamic_miniters, will automatically adjust to equal mininterval (more CPU efficient). If > 0, skips display of that many iterations. For erratic loops (network, skipping items), set miniters=1.ascii : bool or str, optional" 123456789#".disable : bool, optionalFalse]. If None, disable on non-TTY.unit : str, optional'it'].unit_scale : bool or int or float, optional1 or True, the number of iterations is scaled automatically with SI prefixes (kilo, mega, etc.) [default: False]. If any other non-zero number, scales total and n.dynamic_ncols : bool, optionalncols and nrows to the environment (allowing for window resizes) [default: False].smoothing : float, optional0.3]. Ignored in GUI mode.bar_format : str, optional'{l_bar}{bar}{r_bar}'. Possible variables: l_bar, bar, r_bar, n, n_fmt, total, total_fmt, percentage, elapsed, elapsed_s, ncols, nrows, desc, unit, rate, rate_fmt, rate_noinv, rate_noinv_fmt, rate_inv, rate_inv_fmt, postfix, unit_divisor, remaining, remaining_s, eta. A trailing ": " is removed after {desc} if empty.initial : int or float, optional0]. Useful when restarting a bar. If using float, consider {n:.3f} in bar_format or unit_scale.position : int, optionalpostfix : dict or *, optionalset_postfix(**postfix) if dict.unit_divisor : float, optional1000], ignored unless unit_scale is True.write_bytes : bool, optionalFalse) writes unicode.lock_args : tuple, optionalrefresh for intermediate output (initialisation, iterating, updating).nrows : int, optionalcolour : str, optional'green', '#00ff00').delay : float, optional0] seconds have elapsed.gui : bool, optionaltqdm.gui.tqdm(...) instead. If set, attempts to use matplotlib animations.out : decorated iterator.
tqdmtqdm.utils.Comparablebuiltins.object__bool__(self)__contains__(self, item)__del__(self)__enter__(self)__exit__(self, exc_type, exc_value, traceback)__hash__(self) โ Return hash(self).__init__(self, iterable=None, desc=None, total=None, leave=True, file=None, ncols=None, mininterval=0.1, maxinterval=10.0, miniters=None, ascii=None, disable=False, unit='it', unit_scale=False, dynamic_ncols=False, smoothing=0.3, bar_format=None, initial=0, position=None, postfix=None, unit_divisor=1000, write_bytes=False, lock_args=None, nrows=None, colour=None, delay=0.0, gui=False, **kwargs)__iter__(self) โ Backward-compatibility to use: for x in tqdm(iterable)__len__(self)__reversed__(self)__str__(self) โ Return str(self).clear(self, nolock=False) โ Clear current bar display.close(self) โ Cleanup and (if leave=False) close the progress bar.display(self, msg=None, pos=None) โ Use self.sp to display msg in the specified pos. Consider overloading when inheriting. Parameters:
msg : str, optional. What to display (default: repr(self)).pos : int, optional. Position to moveto (default: abs(self.pos)).moveto(self, n)refresh(self, nolock=False, lock_args=None) โ Force refresh the display of this bar. Parameters:
nolock : bool, optional. If True, does not lock. Default: False calls acquire() on internal lock.lock_args : tuple, optional. Passed to internal lock's acquire(). If specified, will only display() if acquire() returns True.reset(self, total=None) โ Resets to 0 iterations for repeated use. Consider combining with leave=True. Parameters:
total : int or float, optional. Total to use for the new bar.set_description(self, desc=None, refresh=True) โ Set/modify description of the progress bar. Parameters:
desc : str, optionalrefresh : bool, optional. Forces refresh [default: True].set_description_str(self, desc=None, refresh=True) โ Set/modify description without ': ' appended.set_postfix(self, ordered_dict=None, refresh=True, **kwargs) โ Set/modify postfix (additional stats) with automatic formatting based on datatype. Parameters:
ordered_dict : dict or OrderedDict, optionalrefresh : bool, optional. Forces refresh [default: True].kwargs : dict, optionalset_postfix_str(self, s='', refresh=True) โ Postfix without dictionary expansion, similar to prefix handling.unpause(self) โ Restart tqdm timer from last print time.update(self, n=1) โ Manually update the progress bar, useful for streams such as reading files.
>>> t = tqdm(total=filesize) # Initialise
>>> for current_buffer in stream:
... ...
... t.update(len(current_buffer))
>>> t.close()
The last line is highly recommended, but possibly not necessary if t.update() will exactly reach filesize and print. Parameters:
n : int or float, optional. Increment to add to the internal counter [default: 1]. If using float, consider {n:.3f} in bar_format or unit_scale.out : bool or None โ True if a display() was triggered.
external_write_mode(file=None, nolock=False) โ Disable tqdm within context and refresh tqdm when exits. Useful when writing to standard output stream.get_lock() โ Get the global lock. Construct it if it does not exist.pandas(**tqdm_kwargs) โ Registers the current tqdm class with pandas.core (DataFrame, Series, GroupBy) progress_apply. A new instance is created every time progress_apply is called, and each instance will automatically close() upon completion. Parameters: tqdm_kwargs : arguments for the tqdm instance.
>>> import pandas as pd
>>> import numpy as np
>>> from tqdm import tqdm
>>> from tqdm.gui import tqdm as tqdm_gui
>>>
>>> df = pd.DataFrame(np.random.randint(0, 100, (100000, 6)))
>>> tqdm.pandas(ncols=50) # can use tqdm_gui, optional kwargs, etc
>>> # Now you can use `progress_apply` instead of `apply`
>>> df.groupby(0).progress_apply(lambda x: x**2)
References: https://stackoverflow.com/questions/18603270/ progress-indicator-during-pandas-operations-pythonset_lock(lock) โ Set the global lock.wrapattr(stream, method, total=None, bytes=True, **tqdm_kwargs) โ stream : file-like object. method : str, "read" or "write". The result of read() and the first argument of write() should have a len().
>>> with tqdm.wrapattr(file_obj, "read", total=file_obj.size) as fobj:
... while True:
... chunk = fobj.read(chunk_size)
... if not chunk:
... break
write(s, file=None, end='\n', nolock=False) โ Print a message via tqdm (without overlap with bars).__new__(cls, *_, **__) โ Create and return a new object. See help(type) for accurate signature.format_interval(t) โ Formats a number of seconds as a clock time, [H:]MM:SS. Parameters: t : int, number of seconds. Returns: out : str, [H:]MM:SS.format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False, unit='it', unit_scale=False, rate=None, bar_format=None, postfix=None, unit_divisor=1000, initial=0, colour=None, **extra_kwargs) โ Return a string-based progress bar. Parameters:
n : int or float, finished iterationstotal : int or float, expected total. If None, only basic stats (no ETA)elapsed : float, seconds since startncols : int, optional. Width of the output message. 0 suppresses barprefix : str, optional. Prefix message (included in total width)ascii : bool or str, optional. Use unicode blocks or ASCII fallbackunit : str, optional. Iteration unit [default: 'it']unit_scale : bool or int or float, optional. SI prefix scalingrate : float, optional. Manual override for iteration ratebar_format : str, optional. Custom bar string formattingpostfix : *, optional. Additional stats at the endunit_divisor : float, optional. Default 1000initial : int or float, optional. Initial counter valuecolour : str, optional. Bar colourformat_num(n) โ Intelligent scientific notation (.3g). Parameters: n : int or float or Numeric. Returns: formatted number string.format_sizeof(num, suffix='', divisor=1000) โ Formats a number (>= 1) with SI Order of Magnitude prefixes. Parameters: num : float, number to format; suffix : str, optional; divisor : float, optional. Returns: formatted string.status_printer(file) โ Manage the printing and in-place updating of a line of characters. Note that if the string is longer than a line, in-place updating may not work (it will print a new line at each refresh).format_dict โ Public API for read-only member access.monitor = Nonemonitor_interval = 10tqdm.utils.Comparable)__eq__(self, other) โ Return self==value.__ge__(self, other) โ Return self>=value.__gt__(self, other) โ Return self>value.__le__(self, other) โ Return self<=value.__lt__(self, other) โ Return self<value.__ne__(self, other) โ Return self!=value.__dict__ โ dictionary for instance variables__weakref__ โ list of weak references to the objectGenerated by phpman v4.9.27 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-18 14:59 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format