You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

953 lines
34 KiB

4 years ago
  1. Metadata-Version: 2.1
  2. Name: tqdm
  3. Version: 4.28.1
  4. Summary: Fast, Extensible Progress Meter
  5. Home-page: https://github.com/tqdm/tqdm
  6. Author: Noam Yorav-Raphael
  7. Author-email: noamraph@gmail.com
  8. Maintainer: tqdm developers
  9. Maintainer-email: python.tqdm@gmail.com
  10. License: MPLv2.0, MIT Licences
  11. Keywords: progressbar progressmeter progress bar meter rate eta console terminal time
  12. Platform: any
  13. Classifier: Development Status :: 5 - Production/Stable
  14. Classifier: Environment :: Console
  15. Classifier: Environment :: MacOS X
  16. Classifier: Environment :: Other Environment
  17. Classifier: Environment :: Win32 (MS Windows)
  18. Classifier: Environment :: X11 Applications
  19. Classifier: Framework :: IPython
  20. Classifier: Intended Audience :: Developers
  21. Classifier: Intended Audience :: Education
  22. Classifier: Intended Audience :: End Users/Desktop
  23. Classifier: Intended Audience :: Other Audience
  24. Classifier: Intended Audience :: System Administrators
  25. Classifier: License :: OSI Approved :: MIT License
  26. Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
  27. Classifier: Operating System :: MacOS :: MacOS X
  28. Classifier: Operating System :: Microsoft :: Windows
  29. Classifier: Operating System :: POSIX
  30. Classifier: Operating System :: POSIX :: BSD
  31. Classifier: Operating System :: POSIX :: BSD :: FreeBSD
  32. Classifier: Operating System :: POSIX :: Linux
  33. Classifier: Operating System :: POSIX :: SunOS/Solaris
  34. Classifier: Programming Language :: Python
  35. Classifier: Programming Language :: Python :: 2
  36. Classifier: Programming Language :: Python :: 2.6
  37. Classifier: Programming Language :: Python :: 2.7
  38. Classifier: Programming Language :: Python :: 3
  39. Classifier: Programming Language :: Python :: 3.2
  40. Classifier: Programming Language :: Python :: 3.3
  41. Classifier: Programming Language :: Python :: 3.4
  42. Classifier: Programming Language :: Python :: 3.5
  43. Classifier: Programming Language :: Python :: 3.6
  44. Classifier: Programming Language :: Python :: 3.7
  45. Classifier: Programming Language :: Python :: Implementation
  46. Classifier: Programming Language :: Python :: Implementation :: IronPython
  47. Classifier: Programming Language :: Python :: Implementation :: PyPy
  48. Classifier: Topic :: Desktop Environment
  49. Classifier: Topic :: Education :: Testing
  50. Classifier: Topic :: Office/Business
  51. Classifier: Topic :: Other/Nonlisted Topic
  52. Classifier: Topic :: Software Development :: Libraries
  53. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  54. Classifier: Topic :: Software Development :: User Interfaces
  55. Classifier: Topic :: System :: Logging
  56. Classifier: Topic :: System :: Monitoring
  57. Classifier: Topic :: System :: Shells
  58. Classifier: Topic :: Terminals
  59. Classifier: Topic :: Utilities
  60. Requires-Python: >=2.6, !=3.0.*, !=3.1.*
  61. |Logo|
  62. tqdm
  63. ====
  64. |PyPI-Status| |PyPI-Versions| |Conda-Forge-Status|
  65. |Build-Status| |Coverage-Status| |Branch-Coverage-Status| |Codacy-Grade|
  66. |DOI-URI| |LICENCE| |OpenHub-Status|
  67. ``tqdm`` means "progress" in Arabic (taqadum, تقدّم)
  68. and is an abbreviation for "I love you so much" in Spanish (te quiero demasiado).
  69. Instantly make your loops show a smart progress meter - just wrap any
  70. iterable with ``tqdm(iterable)``, and you're done!
  71. .. code:: python
  72. from tqdm import tqdm
  73. for i in tqdm(range(10000)):
  74. ...
  75. ``76%|████████████████████████████         | 7568/10000 [00:33<00:10, 229.00it/s]``
  76. ``trange(N)`` can be also used as a convenient shortcut for
  77. ``tqdm(xrange(N))``.
  78. |Screenshot|
  79. REPL: `ptpython <https://github.com/jonathanslenders/ptpython>`__
  80. It can also be executed as a module with pipes:
  81. .. code:: sh
  82. $ seq 9999999 | tqdm --unit_scale | wc -l
  83. 10.0Mit [00:02, 3.58Mit/s]
  84. 9999999
  85. $ 7z a -bd -r backup.7z docs/ | grep Compressing | \
  86. tqdm --total $(find docs/ -type f | wc -l) --unit files >> backup.log
  87. 100%|███████████████████████████████▉| 8014/8014 [01:37<00:00, 82.29files/s]
  88. Overhead is low -- about 60ns per iteration (80ns with ``tqdm_gui``), and is
  89. unit tested against performance regression.
  90. By comparison, the well-established
  91. `ProgressBar <https://github.com/niltonvolpato/python-progressbar>`__ has
  92. an 800ns/iter overhead.
  93. In addition to its low overhead, ``tqdm`` uses smart algorithms to predict
  94. the remaining time and to skip unnecessary iteration displays, which allows
  95. for a negligible overhead in most cases.
  96. ``tqdm`` works on any platform
  97. (Linux, Windows, Mac, FreeBSD, NetBSD, Solaris/SunOS),
  98. in any console or in a GUI, and is also friendly with IPython/Jupyter notebooks.
  99. ``tqdm`` does not require any dependencies (not even ``curses``!), just
  100. Python and an environment supporting ``carriage return \r`` and
  101. ``line feed \n`` control characters.
  102. ------------------------------------------
  103. .. contents:: Table of contents
  104. :backlinks: top
  105. :local:
  106. Installation
  107. ------------
  108. Latest PyPI stable release
  109. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  110. |PyPI-Status|
  111. .. code:: sh
  112. pip install tqdm
  113. Latest development release on GitHub
  114. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  115. |GitHub-Status| |GitHub-Stars| |GitHub-Commits| |GitHub-Forks|
  116. Pull and install in the current directory:
  117. .. code:: sh
  118. pip install -e git+https://github.com/tqdm/tqdm.git@master#egg=tqdm
  119. Latest Conda release
  120. ~~~~~~~~~~~~~~~~~~~~
  121. |Conda-Forge-Status|
  122. .. code:: sh
  123. conda install -c conda-forge tqdm
  124. Changelog
  125. ---------
  126. The list of all changes is available either on GitHub's Releases:
  127. |GitHub-Status|, on the
  128. `wiki <https://github.com/tqdm/tqdm/wiki/Releases>`__ or on crawlers such as
  129. `allmychanges.com <https://allmychanges.com/p/python/tqdm/>`_.
  130. Usage
  131. -----
  132. ``tqdm`` is very versatile and can be used in a number of ways.
  133. The three main ones are given below.
  134. Iterable-based
  135. ~~~~~~~~~~~~~~
  136. Wrap ``tqdm()`` around any iterable:
  137. .. code:: python
  138. text = ""
  139. for char in tqdm(["a", "b", "c", "d"]):
  140. text = text + char
  141. ``trange(i)`` is a special optimised instance of ``tqdm(range(i))``:
  142. .. code:: python
  143. for i in trange(100):
  144. pass
  145. Instantiation outside of the loop allows for manual control over ``tqdm()``:
  146. .. code:: python
  147. pbar = tqdm(["a", "b", "c", "d"])
  148. for char in pbar:
  149. pbar.set_description("Processing %s" % char)
  150. Manual
  151. ~~~~~~
  152. Manual control on ``tqdm()`` updates by using a ``with`` statement:
  153. .. code:: python
  154. with tqdm(total=100) as pbar:
  155. for i in range(10):
  156. pbar.update(10)
  157. If the optional variable ``total`` (or an iterable with ``len()``) is
  158. provided, predictive stats are displayed.
  159. ``with`` is also optional (you can just assign ``tqdm()`` to a variable,
  160. but in this case don't forget to ``del`` or ``close()`` at the end:
  161. .. code:: python
  162. pbar = tqdm(total=100)
  163. for i in range(10):
  164. pbar.update(10)
  165. pbar.close()
  166. Module
  167. ~~~~~~
  168. Perhaps the most wonderful use of ``tqdm`` is in a script or on the command
  169. line. Simply inserting ``tqdm`` (or ``python -m tqdm``) between pipes will pass
  170. through all ``stdin`` to ``stdout`` while printing progress to ``stderr``.
  171. The example below demonstrated counting the number of lines in all Python files
  172. in the current directory, with timing information included.
  173. .. code:: sh
  174. $ time find . -name '*.py' -exec cat \{} \; | wc -l
  175. 857365
  176. real 0m3.458s
  177. user 0m0.274s
  178. sys 0m3.325s
  179. $ time find . -name '*.py' -exec cat \{} \; | tqdm | wc -l
  180. 857366it [00:03, 246471.31it/s]
  181. 857365
  182. real 0m3.585s
  183. user 0m0.862s
  184. sys 0m3.358s
  185. Note that the usual arguments for ``tqdm`` can also be specified.
  186. .. code:: sh
  187. $ find . -name '*.py' -exec cat \{} \; |
  188. tqdm --unit loc --unit_scale --total 857366 >> /dev/null
  189. 100%|███████████████████████████████████| 857K/857K [00:04<00:00, 246Kloc/s]
  190. Backing up a large directory?
  191. .. code:: sh
  192. $ 7z a -bd -r backup.7z docs/ | grep Compressing |
  193. tqdm --total $(find docs/ -type f | wc -l) --unit files >> backup.log
  194. 100%|███████████████████████████████▉| 8014/8014 [01:37<00:00, 82.29files/s]
  195. FAQ and Known Issues
  196. --------------------
  197. |GitHub-Issues|
  198. The most common issues relate to excessive output on multiple lines, instead
  199. of a neat one-line progress bar.
  200. - Consoles in general: require support for carriage return (``CR``, ``\r``).
  201. - Nested progress bars:
  202. * Consoles in general: require support for moving cursors up to the
  203. previous line. For example,
  204. `IDLE <https://github.com/tqdm/tqdm/issues/191#issuecomment-230168030>`__,
  205. `ConEmu <https://github.com/tqdm/tqdm/issues/254>`__ and
  206. `PyCharm <https://github.com/tqdm/tqdm/issues/203>`__ (also
  207. `here <https://github.com/tqdm/tqdm/issues/208>`__,
  208. `here <https://github.com/tqdm/tqdm/issues/307>`__, and
  209. `here <https://github.com/tqdm/tqdm/issues/454#issuecomment-335416815>`__)
  210. lack full support.
  211. * Windows: additionally may require the Python module ``colorama``
  212. to ensure nested bars stay within their respective lines.
  213. - Unicode:
  214. * Environments which report that they support unicode will have solid smooth
  215. progressbars. The fallback is an `ascii`-only bar.
  216. * Windows consoles often only partially support unicode and thus
  217. `often require explicit ascii=True <https://github.com/tqdm/tqdm/issues/454#issuecomment-335416815>`__
  218. (also `here <https://github.com/tqdm/tqdm/issues/499>`__). This is due to
  219. either normal-width unicode characters being incorrectly displayed as
  220. "wide", or some unicode characters not rendering.
  221. - Wrapping enumerated iterables: use ``enumerate(tqdm(...))`` instead of
  222. ``tqdm(enumerate(...))``. The same applies to ``numpy.ndenumerate``.
  223. This is because enumerate functions tend to hide the length of iterables.
  224. ``tqdm`` does not.
  225. - Wrapping zipped iterables has similar issues due to internal optimisations.
  226. ``tqdm(zip(a, b))`` should be replaced with ``zip(tqdm(a), b)`` or even
  227. ``zip(tqdm(a), tqdm(b))``.
  228. If you come across any other difficulties, browse and file |GitHub-Issues|.
  229. Documentation
  230. -------------
  231. |PyPI-Versions| |README-Hits| (Since 19 May 2016)
  232. .. code:: python
  233. class tqdm(object):
  234. """
  235. Decorate an iterable object, returning an iterator which acts exactly
  236. like the original iterable, but prints a dynamically updating
  237. progressbar every time a value is requested.
  238. """
  239. def __init__(self, iterable=None, desc=None, total=None, leave=True,
  240. file=None, ncols=None, mininterval=0.1,
  241. maxinterval=10.0, miniters=None, ascii=None, disable=False,
  242. unit='it', unit_scale=False, dynamic_ncols=False,
  243. smoothing=0.3, bar_format=None, initial=0, position=None,
  244. postfix=None, unit_divisor=1000):
  245. Parameters
  246. ~~~~~~~~~~
  247. * iterable : iterable, optional
  248. Iterable to decorate with a progressbar.
  249. Leave blank to manually manage the updates.
  250. * desc : str, optional
  251. Prefix for the progressbar.
  252. * total : int, optional
  253. The number of expected iterations. If unspecified,
  254. len(iterable) is used if possible. As a last resort, only basic
  255. progress statistics are displayed (no ETA, no progressbar).
  256. If ``gui`` is True and this parameter needs subsequent updating,
  257. specify an initial arbitrary large positive integer,
  258. e.g. int(9e9).
  259. * leave : bool, optional
  260. If [default: True], keeps all traces of the progressbar
  261. upon termination of iteration.
  262. * file : ``io.TextIOWrapper`` or ``io.StringIO``, optional
  263. Specifies where to output the progress messages
  264. (default: sys.stderr). Uses ``file.write(str)`` and ``file.flush()``
  265. methods.
  266. * ncols : int, optional
  267. The width of the entire output message. If specified,
  268. dynamically resizes the progressbar to stay within this bound.
  269. If unspecified, attempts to use environment width. The
  270. fallback is a meter width of 10 and no limit for the counter and
  271. statistics. If 0, will not print any meter (only stats).
  272. * mininterval : float, optional
  273. Minimum progress display update interval [default: 0.1] seconds.
  274. * maxinterval : float, optional
  275. Maximum progress display update interval [default: 10] seconds.
  276. Automatically adjusts ``miniters`` to correspond to ``mininterval``
  277. after long display update lag. Only works if ``dynamic_miniters``
  278. or monitor thread is enabled.
  279. * miniters : int, optional
  280. Minimum progress display update interval, in iterations.
  281. If 0 and ``dynamic_miniters``, will automatically adjust to equal
  282. ``mininterval`` (more CPU efficient, good for tight loops).
  283. If > 0, will skip display of specified number of iterations.
  284. Tweak this and ``mininterval`` to get very efficient loops.
  285. If your progress is erratic with both fast and slow iterations
  286. (network, skipping items, etc) you should set miniters=1.
  287. * ascii : bool, optional
  288. If unspecified or False, use unicode (smooth blocks) to fill
  289. the meter. The fallback is to use ASCII characters ``1-9 #``.
  290. * disable : bool, optional
  291. Whether to disable the entire progressbar wrapper
  292. [default: False]. If set to None, disable on non-TTY.
  293. * unit : str, optional
  294. String that will be used to define the unit of each iteration
  295. [default: it].
  296. * unit_scale : bool or int or float, optional
  297. If 1 or True, the number of iterations will be reduced/scaled
  298. automatically and a metric prefix following the
  299. International System of Units standard will be added
  300. (kilo, mega, etc.) [default: False]. If any other non-zero
  301. number, will scale `total` and `n`.
  302. * dynamic_ncols : bool, optional
  303. If set, constantly alters ``ncols`` to the environment (allowing
  304. for window resizes) [default: False].
  305. * smoothing : float, optional
  306. Exponential moving average smoothing factor for speed estimates
  307. (ignored in GUI mode). Ranges from 0 (average speed) to 1
  308. (current/instantaneous speed) [default: 0.3].
  309. * bar_format : str, optional
  310. Specify a custom bar string formatting. May impact performance.
  311. [default: '{l_bar}{bar}{r_bar}'], where
  312. l_bar='{desc}: {percentage:3.0f}%|' and
  313. r_bar='| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, '
  314. '{rate_fmt}{postfix}]'
  315. Possible vars: l_bar, bar, r_bar, n, n_fmt, total, total_fmt,
  316. percentage, rate, rate_fmt, rate_noinv, rate_noinv_fmt,
  317. rate_inv, rate_inv_fmt, elapsed, remaining, desc, postfix.
  318. Note that a trailing ": " is automatically removed after {desc}
  319. if the latter is empty.
  320. * initial : int, optional
  321. The initial counter value. Useful when restarting a progress
  322. bar [default: 0].
  323. * position : int, optional
  324. Specify the line offset to print this bar (starting from 0)
  325. Automatic if unspecified.
  326. Useful to manage multiple bars at once (eg, from threads).
  327. * postfix : dict or ``*``, optional
  328. Specify additional stats to display at the end of the bar.
  329. Calls ``set_postfix(**postfix)`` if possible (dict).
  330. * unit_divisor : float, optional
  331. [default: 1000], ignored unless `unit_scale` is True.
  332. Extra CLI Options
  333. ~~~~~~~~~~~~~~~~~
  334. * delim : chr, optional
  335. Delimiting character [default: '\n']. Use '\0' for null.
  336. N.B.: on Windows systems, Python converts '\n' to '\r\n'.
  337. * buf_size : int, optional
  338. String buffer size in bytes [default: 256]
  339. used when ``delim`` is specified.
  340. * bytes : bool, optional
  341. If true, will count bytes and ignore ``delim``.
  342. Returns
  343. ~~~~~~~
  344. * out : decorated iterator.
  345. .. code:: python
  346. def update(self, n=1):
  347. """
  348. Manually update the progress bar, useful for streams
  349. such as reading files.
  350. E.g.:
  351. >>> t = tqdm(total=filesize) # Initialise
  352. >>> for current_buffer in stream:
  353. ... ...
  354. ... t.update(len(current_buffer))
  355. >>> t.close()
  356. The last line is highly recommended, but possibly not necessary if
  357. ``t.update()`` will be called in such a way that ``filesize`` will be
  358. exactly reached and printed.
  359. Parameters
  360. ----------
  361. n : int, optional
  362. Increment to add to the internal counter of iterations
  363. [default: 1].
  364. """
  365. def close(self):
  366. """
  367. Cleanup and (if leave=False) close the progressbar.
  368. """
  369. def unpause(self):
  370. """
  371. Restart tqdm timer from last print time.
  372. """
  373. def clear(self, nomove=False):
  374. """
  375. Clear current bar display
  376. """
  377. def refresh(self):
  378. """
  379. Force refresh the display of this bar
  380. """
  381. def write(cls, s, file=sys.stdout, end="\n"):
  382. """
  383. Print a message via tqdm (without overlap with bars)
  384. """
  385. def set_description(self, desc=None, refresh=True):
  386. """
  387. Set/modify description of the progress bar.
  388. Parameters
  389. ----------
  390. desc : str, optional
  391. refresh : bool, optional
  392. Forces refresh [default: True].
  393. """
  394. def set_postfix(self, ordered_dict=None, refresh=True, **kwargs):
  395. """
  396. Set/modify postfix (additional stats)
  397. with automatic formatting based on datatype.
  398. Parameters
  399. ----------
  400. refresh : bool, optional
  401. Forces refresh [default: True].
  402. """
  403. def trange(*args, **kwargs):
  404. """
  405. A shortcut for tqdm(xrange(*args), **kwargs).
  406. On Python3+ range is used instead of xrange.
  407. """
  408. class tqdm_gui(tqdm):
  409. """
  410. Experimental GUI version of tqdm!
  411. """
  412. def tgrange(*args, **kwargs):
  413. """
  414. Experimental GUI version of trange!
  415. """
  416. class tqdm_notebook(tqdm):
  417. """
  418. Experimental IPython/Jupyter Notebook widget using tqdm!
  419. """
  420. def tnrange(*args, **kwargs):
  421. """
  422. Experimental IPython/Jupyter Notebook widget using tqdm!
  423. """
  424. Examples and Advanced Usage
  425. ---------------------------
  426. - See the `examples <https://github.com/tqdm/tqdm/tree/master/examples>`__
  427. folder;
  428. - import the module and run ``help()``, or
  429. - consult the `wiki <https://github.com/tqdm/tqdm/wiki>`__.
  430. - this has an
  431. `excellent article <https://github.com/tqdm/tqdm/wiki/How-to-make-a-great-Progress-Bar>`__
  432. on how to make a **great** progressbar.
  433. Description and additional stats
  434. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  435. Custom information can be displayed and updated dynamically on ``tqdm`` bars
  436. with the ``desc`` and ``postfix`` arguments:
  437. .. code:: python
  438. from tqdm import trange
  439. from random import random, randint
  440. from time import sleep
  441. with trange(100) as t:
  442. for i in t:
  443. # Description will be displayed on the left
  444. t.set_description('GEN %i' % i)
  445. # Postfix will be displayed on the right,
  446. # formatted automatically based on argument's datatype
  447. t.set_postfix(loss=random(), gen=randint(1,999), str='h',
  448. lst=[1, 2])
  449. sleep(0.1)
  450. with tqdm(total=10, bar_format="{postfix[0]} {postfix[1][value]:>8.2g}",
  451. postfix=["Batch", dict(value=0)]) as t:
  452. for i in range(10):
  453. sleep(0.1)
  454. t.postfix[1]["value"] = i / 2
  455. t.update()
  456. Points to remember when using ``{postfix[...]}`` in the ``bar_format`` string:
  457. - ``postfix`` also needs to be passed as an initial argument in a compatible
  458. format, and
  459. - ``postfix`` will be auto-converted to a string if it is a ``dict``-like
  460. object. To prevent this behaviour, insert an extra item into the dictionary
  461. where the key is not a string.
  462. Nested progress bars
  463. ~~~~~~~~~~~~~~~~~~~~
  464. ``tqdm`` supports nested progress bars. Here's an example:
  465. .. code:: python
  466. from tqdm import trange
  467. from time import sleep
  468. for i in trange(10, desc='1st loop'):
  469. for j in trange(5, desc='2nd loop', leave=False):
  470. for k in trange(100, desc='3nd loop'):
  471. sleep(0.01)
  472. On Windows `colorama <https://github.com/tartley/colorama>`__ will be used if
  473. available to keep nested bars on their respective lines.
  474. For manual control over positioning (e.g. for multi-threaded use),
  475. you may specify ``position=n`` where ``n=0`` for the outermost bar,
  476. ``n=1`` for the next, and so on:
  477. .. code:: python
  478. from time import sleep
  479. from tqdm import trange, tqdm
  480. from multiprocessing import Pool, freeze_support, RLock
  481. L = list(range(9))
  482. def progresser(n):
  483. interval = 0.001 / (n + 2)
  484. total = 5000
  485. text = "#{}, est. {:<04.2}s".format(n, interval * total)
  486. for i in trange(total, desc=text, position=n):
  487. sleep(interval)
  488. if __name__ == '__main__':
  489. freeze_support() # for Windows support
  490. p = Pool(len(L),
  491. # again, for Windows support
  492. initializer=tqdm.set_lock, initargs=(RLock(),))
  493. p.map(progresser, L)
  494. print("\n" * (len(L) - 2))
  495. Hooks and callbacks
  496. ~~~~~~~~~~~~~~~~~~~
  497. ``tqdm`` can easily support callbacks/hooks and manual updates.
  498. Here's an example with ``urllib``:
  499. **urllib.urlretrieve documentation**
  500. | [...]
  501. | If present, the hook function will be called once
  502. | on establishment of the network connection and once after each block read
  503. | thereafter. The hook will be passed three arguments; a count of blocks
  504. | transferred so far, a block size in bytes, and the total size of the file.
  505. | [...]
  506. .. code:: python
  507. import urllib, os
  508. from tqdm import tqdm
  509. class TqdmUpTo(tqdm):
  510. """Provides `update_to(n)` which uses `tqdm.update(delta_n)`."""
  511. def update_to(self, b=1, bsize=1, tsize=None):
  512. """
  513. b : int, optional
  514. Number of blocks transferred so far [default: 1].
  515. bsize : int, optional
  516. Size of each block (in tqdm units) [default: 1].
  517. tsize : int, optional
  518. Total size (in tqdm units). If [default: None] remains unchanged.
  519. """
  520. if tsize is not None:
  521. self.total = tsize
  522. self.update(b * bsize - self.n) # will also set self.n = b * bsize
  523. eg_link = "https://caspersci.uk.to/matryoshka.zip"
  524. with TqdmUpTo(unit='B', unit_scale=True, miniters=1,
  525. desc=eg_link.split('/')[-1]) as t: # all optional kwargs
  526. urllib.urlretrieve(eg_link, filename=os.devnull,
  527. reporthook=t.update_to, data=None)
  528. Inspired by `twine#242 <https://github.com/pypa/twine/pull/242>`__.
  529. Functional alternative in
  530. `examples/tqdm_wget.py <https://github.com/tqdm/tqdm/blob/master/examples/tqdm_wget.py>`__.
  531. It is recommend to use ``miniters=1`` whenever there is potentially
  532. large differences in iteration speed (e.g. downloading a file over
  533. a patchy connection).
  534. Pandas Integration
  535. ~~~~~~~~~~~~~~~~~~
  536. Due to popular demand we've added support for ``pandas`` -- here's an example
  537. for ``DataFrame.progress_apply`` and ``DataFrameGroupBy.progress_apply``:
  538. .. code:: python
  539. import pandas as pd
  540. import numpy as np
  541. from tqdm import tqdm
  542. df = pd.DataFrame(np.random.randint(0, 100, (100000, 6)))
  543. # Register `pandas.progress_apply` and `pandas.Series.map_apply` with `tqdm`
  544. # (can use `tqdm_gui`, `tqdm_notebook`, optional kwargs, etc.)
  545. tqdm.pandas(desc="my bar!")
  546. # Now you can use `progress_apply` instead of `apply`
  547. # and `progress_map` instead of `map`
  548. df.progress_apply(lambda x: x**2)
  549. # can also groupby:
  550. # df.groupby(0).progress_apply(lambda x: x**2)
  551. In case you're interested in how this works (and how to modify it for your
  552. own callbacks), see the
  553. `examples <https://github.com/tqdm/tqdm/tree/master/examples>`__
  554. folder or import the module and run ``help()``.
  555. IPython/Jupyter Integration
  556. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  557. IPython/Jupyter is supported via the ``tqdm_notebook`` submodule:
  558. .. code:: python
  559. from tqdm import tnrange, tqdm_notebook
  560. from time import sleep
  561. for i in tnrange(10, desc='1st loop'):
  562. for j in tqdm_notebook(xrange(100), desc='2nd loop'):
  563. sleep(0.01)
  564. In addition to ``tqdm`` features, the submodule provides a native Jupyter
  565. widget (compatible with IPython v1-v4 and Jupyter), fully working nested bars
  566. and color hints (blue: normal, green: completed, red: error/interrupt,
  567. light blue: no ETA); as demonstrated below.
  568. |Screenshot-Jupyter1|
  569. |Screenshot-Jupyter2|
  570. |Screenshot-Jupyter3|
  571. It is also possible to let ``tqdm`` automatically choose between
  572. console or notebook versions by using the ``autonotebook`` submodule:
  573. .. code:: python
  574. from tqdm.autonotebook import tqdm
  575. tqdm.pandas()
  576. Note that this will issue a ``TqdmExperimentalWarning`` if run in a notebook
  577. since it is not meant to be possible to distinguish between ``jupyter notebook``
  578. and ``jupyter console``. Use ``auto`` instead of ``autonotebook`` to suppress
  579. this warning.
  580. Writing messages
  581. ~~~~~~~~~~~~~~~~
  582. Since ``tqdm`` uses a simple printing mechanism to display progress bars,
  583. you should not write any message in the terminal using ``print()`` while
  584. a progressbar is open.
  585. To write messages in the terminal without any collision with ``tqdm`` bar
  586. display, a ``.write()`` method is provided:
  587. .. code:: python
  588. from tqdm import tqdm, trange
  589. from time import sleep
  590. bar = trange(10)
  591. for i in bar:
  592. # Print using tqdm class method .write()
  593. sleep(0.1)
  594. if not (i % 3):
  595. tqdm.write("Done task %i" % i)
  596. # Can also use bar.write()
  597. By default, this will print to standard output ``sys.stdout``. but you can
  598. specify any file-like object using the ``file`` argument. For example, this
  599. can be used to redirect the messages writing to a log file or class.
  600. Redirecting writing
  601. ~~~~~~~~~~~~~~~~~~~
  602. If using a library that can print messages to the console, editing the library
  603. by replacing ``print()`` with ``tqdm.write()`` may not be desirable.
  604. In that case, redirecting ``sys.stdout`` to ``tqdm.write()`` is an option.
  605. To redirect ``sys.stdout``, create a file-like class that will write
  606. any input string to ``tqdm.write()``, and supply the arguments
  607. ``file=sys.stdout, dynamic_ncols=True``.
  608. A reusable canonical example is given below:
  609. .. code:: python
  610. from time import sleep
  611. import contextlib
  612. import sys
  613. from tqdm import tqdm
  614. class DummyTqdmFile(object):
  615. """Dummy file-like that will write to tqdm"""
  616. file = None
  617. def __init__(self, file):
  618. self.file = file
  619. def write(self, x):
  620. # Avoid print() second call (useless \n)
  621. if len(x.rstrip()) > 0:
  622. tqdm.write(x, file=self.file)
  623. def flush(self):
  624. return getattr(self.file, "flush", lambda: None)()
  625. @contextlib.contextmanager
  626. def std_out_err_redirect_tqdm():
  627. orig_out_err = sys.stdout, sys.stderr
  628. try:
  629. sys.stdout, sys.stderr = map(DummyTqdmFile, orig_out_err)
  630. yield orig_out_err[0]
  631. # Relay exceptions
  632. except Exception as exc:
  633. raise exc
  634. # Always restore sys.stdout/err if necessary
  635. finally:
  636. sys.stdout, sys.stderr = orig_out_err
  637. def some_fun(i):
  638. print("Fee, fi, fo,".split()[i])
  639. # Redirect stdout to tqdm.write() (don't forget the `as save_stdout`)
  640. with std_out_err_redirect_tqdm() as orig_stdout:
  641. # tqdm needs the original stdout
  642. # and dynamic_ncols=True to autodetect console width
  643. for i in tqdm(range(3), file=orig_stdout, dynamic_ncols=True):
  644. sleep(.5)
  645. some_fun(i)
  646. # After the `with`, printing is restored
  647. print("Done!")
  648. Monitoring thread, intervals and miniters
  649. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  650. ``tqdm`` implements a few tricks to to increase efficiency and reduce overhead.
  651. - Avoid unnecessary frequent bar refreshing: ``mininterval`` defines how long
  652. to wait between each refresh. ``tqdm`` always gets updated in the background,
  653. but it will diplay only every ``mininterval``.
  654. - Reduce number of calls to check system clock/time.
  655. - ``mininterval`` is more intuitive to configure than ``miniters``.
  656. A clever adjustment system ``dynamic_miniters`` will automatically adjust
  657. ``miniters`` to the amount of iterations that fit into time ``mininterval``.
  658. Essentially, ``tqdm`` will check if it's time to print without actually
  659. checking time. This behaviour can be still be bypassed by manually setting
  660. ``miniters``.
  661. However, consider a case with a combination of fast and slow iterations.
  662. After a few fast iterations, ``dynamic_miniters`` will set ``miniters`` to a
  663. large number. When iteration rate subsequently slows, ``miniters`` will
  664. remain large and thus reduce display update frequency. To address this:
  665. - ``maxinterval`` defines the maximum time between display refreshes.
  666. A concurrent monitoring thread checks for overdue updates and forces one
  667. where necessary.
  668. The monitoring thread should not have a noticeable overhead, and guarantees
  669. updates at least every 10 seconds by default.
  670. This value can be directly changed by setting the ``monitor_interval`` of
  671. any ``tqdm`` instance (i.e. ``t = tqdm.tqdm(...); t.monitor_interval = 2``).
  672. The monitor thread may be disabled application-wide by setting
  673. ``tqdm.tqdm.monitor_interval = 0`` before instantiatiation of any ``tqdm`` bar.
  674. Contributions
  675. -------------
  676. |GitHub-Commits| |GitHub-Issues| |GitHub-PRs| |OpenHub-Status|
  677. All source code is hosted on `GitHub <https://github.com/tqdm/tqdm>`__.
  678. Contributions are welcome.
  679. See the
  680. `CONTRIBUTING <https://raw.githubusercontent.com/tqdm/tqdm/master/CONTRIBUTING.md>`__
  681. file for more information.
  682. Ports to Other Languages
  683. ~~~~~~~~~~~~~~~~~~~~~~~~
  684. A list is available on
  685. `this wiki page <https://github.com/tqdm/tqdm/wiki/tqdm-ports>`__.
  686. LICENCE
  687. -------
  688. Open Source (OSI approved): |LICENCE|
  689. Citation information: |DOI-URI|
  690. Authors
  691. -------
  692. The main developers, ranked by surviving lines of code
  693. (`git fame -wMC <https://github.com/casperdcl/git-fame>`__), are:
  694. - Casper da Costa-Luis (`casperdcl <https://github.com/casperdcl>`__, ~2/3, |Gift-Casper|)
  695. - Stephen Larroque (`lrq3000 <https://github.com/lrq3000>`__, ~1/5)
  696. - Hadrien Mary (`hadim <https://github.com/hadim>`__, ~2%)
  697. - Guangshuo Chen (`chengs <https://github.com/chengs>`__, ~1%)
  698. - Noam Yorav-Raphael (`noamraph <https://github.com/noamraph>`__, ~1%, original author)
  699. - Mikhail Korobov (`kmike <https://github.com/kmike>`__, ~1%)
  700. There are also many |GitHub-Contributions| which we are grateful for.
  701. |README-Hits| (Since 19 May 2016)
  702. .. |Logo| image:: https://raw.githubusercontent.com/tqdm/tqdm/master/images/logo.gif
  703. .. |Screenshot| image:: https://raw.githubusercontent.com/tqdm/tqdm/master/images/tqdm.gif
  704. .. |Build-Status| image:: https://travis-ci.org/tqdm/tqdm.svg?branch=master
  705. :target: https://travis-ci.org/tqdm/tqdm
  706. .. |Coverage-Status| image:: https://coveralls.io/repos/tqdm/tqdm/badge.svg?branch=master
  707. :target: https://coveralls.io/github/tqdm/tqdm
  708. .. |Branch-Coverage-Status| image:: https://codecov.io/gh/tqdm/tqdm/branch/master/graph/badge.svg
  709. :target: https://codecov.io/gh/tqdm/tqdm
  710. .. |Codacy-Grade| image:: https://api.codacy.com/project/badge/Grade/3f965571598f44549c7818f29cdcf177
  711. :target: https://www.codacy.com/app/tqdm/tqdm?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=tqdm/tqdm&amp;utm_campaign=Badge_Grade
  712. .. |GitHub-Status| image:: https://img.shields.io/github/tag/tqdm/tqdm.svg?maxAge=86400
  713. :target: https://github.com/tqdm/tqdm/releases
  714. .. |GitHub-Forks| image:: https://img.shields.io/github/forks/tqdm/tqdm.svg
  715. :target: https://github.com/tqdm/tqdm/network
  716. .. |GitHub-Stars| image:: https://img.shields.io/github/stars/tqdm/tqdm.svg
  717. :target: https://github.com/tqdm/tqdm/stargazers
  718. .. |GitHub-Commits| image:: https://img.shields.io/github/commit-activity/y/tqdm/tqdm.svg
  719. :target: https://github.com/tqdm/tqdm/graphs/commit-activity
  720. .. |GitHub-Issues| image:: https://img.shields.io/github/issues-closed/tqdm/tqdm.svg
  721. :target: https://github.com/tqdm/tqdm/issues
  722. .. |GitHub-PRs| image:: https://img.shields.io/github/issues-pr-closed/tqdm/tqdm.svg
  723. :target: https://github.com/tqdm/tqdm/pulls
  724. .. |GitHub-Contributions| image:: https://img.shields.io/github/contributors/tqdm/tqdm.svg
  725. :target: https://github.com/tqdm/tqdm/graphs/contributors
  726. .. |Gift-Casper| image:: https://img.shields.io/badge/gift-donate-ff69b4.svg
  727. :target: https://caspersci.uk.to/donate.html
  728. .. |PyPI-Status| image:: https://img.shields.io/pypi/v/tqdm.svg
  729. :target: https://pypi.org/project/tqdm
  730. .. |PyPI-Downloads| image:: https://img.shields.io/pypi/dm/tqdm.svg
  731. :target: https://pypi.org/project/tqdm
  732. .. |PyPI-Versions| image:: https://img.shields.io/pypi/pyversions/tqdm.svg
  733. :target: https://pypi.org/project/tqdm
  734. .. |Conda-Forge-Status| image:: https://anaconda.org/conda-forge/tqdm/badges/version.svg
  735. :target: https://anaconda.org/conda-forge/tqdm
  736. .. |OpenHub-Status| image:: https://www.openhub.net/p/tqdm/widgets/project_thin_badge?format=gif
  737. :target: https://www.openhub.net/p/tqdm?ref=Thin+badge
  738. .. |LICENCE| image:: https://img.shields.io/pypi/l/tqdm.svg
  739. :target: https://raw.githubusercontent.com/tqdm/tqdm/master/LICENCE
  740. .. |DOI-URI| image:: https://zenodo.org/badge/21637/tqdm/tqdm.svg
  741. :target: https://zenodo.org/badge/latestdoi/21637/tqdm/tqdm
  742. .. |Screenshot-Jupyter1| image:: https://raw.githubusercontent.com/tqdm/tqdm/master/images/tqdm-jupyter-1.gif
  743. .. |Screenshot-Jupyter2| image:: https://raw.githubusercontent.com/tqdm/tqdm/master/images/tqdm-jupyter-2.gif
  744. .. |Screenshot-Jupyter3| image:: https://raw.githubusercontent.com/tqdm/tqdm/master/images/tqdm-jupyter-3.gif
  745. .. |README-Hits| image:: https://caspersci.uk.to/cgi-bin/hits.cgi?q=tqdm&style=social&r=https://github.com/tqdm/tqdm&l=https://caspersci.uk.to/images/tqdm.png&f=https://raw.githubusercontent.com/tqdm/tqdm/master/images/logo.gif
  746. :target: https://caspersci.uk.to/cgi-bin/hits.cgi?q=tqdm&a=plot&r=https://github.com/tqdm/tqdm&l=https://caspersci.uk.to/images/tqdm.png&f=https://raw.githubusercontent.com/tqdm/tqdm/master/images/logo.gif&style=social