METADATA 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594
  1. Metadata-Version: 2.1
  2. Name: tqdm
  3. Version: 4.67.1
  4. Summary: Fast, Extensible Progress Meter
  5. Maintainer-email: tqdm developers <devs@tqdm.ml>
  6. License: MPL-2.0 AND MIT
  7. Project-URL: homepage, https://tqdm.github.io
  8. Project-URL: repository, https://github.com/tqdm/tqdm
  9. Project-URL: changelog, https://tqdm.github.io/releases
  10. Project-URL: wiki, https://github.com/tqdm/tqdm/wiki
  11. Keywords: progressbar,progressmeter,progress,bar,meter,rate,eta,console,terminal,time
  12. Classifier: Development Status :: 5 - Production/Stable
  13. Classifier: Environment :: Console
  14. Classifier: Environment :: MacOS X
  15. Classifier: Environment :: Other Environment
  16. Classifier: Environment :: Win32 (MS Windows)
  17. Classifier: Environment :: X11 Applications
  18. Classifier: Framework :: IPython
  19. Classifier: Framework :: Jupyter
  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
  28. Classifier: Operating System :: MacOS :: MacOS X
  29. Classifier: Operating System :: Microsoft
  30. Classifier: Operating System :: Microsoft :: MS-DOS
  31. Classifier: Operating System :: Microsoft :: Windows
  32. Classifier: Operating System :: POSIX
  33. Classifier: Operating System :: POSIX :: BSD
  34. Classifier: Operating System :: POSIX :: BSD :: FreeBSD
  35. Classifier: Operating System :: POSIX :: Linux
  36. Classifier: Operating System :: POSIX :: SunOS/Solaris
  37. Classifier: Operating System :: Unix
  38. Classifier: Programming Language :: Python
  39. Classifier: Programming Language :: Python :: 3
  40. Classifier: Programming Language :: Python :: 3.7
  41. Classifier: Programming Language :: Python :: 3.8
  42. Classifier: Programming Language :: Python :: 3.9
  43. Classifier: Programming Language :: Python :: 3.10
  44. Classifier: Programming Language :: Python :: 3.11
  45. Classifier: Programming Language :: Python :: 3.12
  46. Classifier: Programming Language :: Python :: 3 :: Only
  47. Classifier: Programming Language :: Python :: Implementation
  48. Classifier: Programming Language :: Python :: Implementation :: IronPython
  49. Classifier: Programming Language :: Python :: Implementation :: PyPy
  50. Classifier: Programming Language :: Unix Shell
  51. Classifier: Topic :: Desktop Environment
  52. Classifier: Topic :: Education :: Computer Aided Instruction (CAI)
  53. Classifier: Topic :: Education :: Testing
  54. Classifier: Topic :: Office/Business
  55. Classifier: Topic :: Other/Nonlisted Topic
  56. Classifier: Topic :: Software Development :: Build Tools
  57. Classifier: Topic :: Software Development :: Libraries
  58. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  59. Classifier: Topic :: Software Development :: Pre-processors
  60. Classifier: Topic :: Software Development :: User Interfaces
  61. Classifier: Topic :: System :: Installation/Setup
  62. Classifier: Topic :: System :: Logging
  63. Classifier: Topic :: System :: Monitoring
  64. Classifier: Topic :: System :: Shells
  65. Classifier: Topic :: Terminals
  66. Classifier: Topic :: Utilities
  67. Requires-Python: >=3.7
  68. Description-Content-Type: text/x-rst
  69. License-File: LICENCE
  70. Requires-Dist: colorama; platform_system == "Windows"
  71. Provides-Extra: dev
  72. Requires-Dist: pytest>=6; extra == "dev"
  73. Requires-Dist: pytest-cov; extra == "dev"
  74. Requires-Dist: pytest-timeout; extra == "dev"
  75. Requires-Dist: pytest-asyncio>=0.24; extra == "dev"
  76. Requires-Dist: nbval; extra == "dev"
  77. Provides-Extra: discord
  78. Requires-Dist: requests; extra == "discord"
  79. Provides-Extra: slack
  80. Requires-Dist: slack-sdk; extra == "slack"
  81. Provides-Extra: telegram
  82. Requires-Dist: requests; extra == "telegram"
  83. Provides-Extra: notebook
  84. Requires-Dist: ipywidgets>=6; extra == "notebook"
  85. |Logo|
  86. tqdm
  87. ====
  88. |Py-Versions| |Versions| |Conda-Forge-Status| |Docker| |Snapcraft|
  89. |Build-Status| |Coverage-Status| |Branch-Coverage-Status| |Codacy-Grade| |Libraries-Rank| |PyPI-Downloads|
  90. |LICENCE| |OpenHub-Status| |binder-demo| |awesome-python|
  91. ``tqdm`` derives from the Arabic word *taqaddum* (تقدّم) which can mean "progress,"
  92. and is an abbreviation for "I love you so much" in Spanish (*te quiero demasiado*).
  93. Instantly make your loops show a smart progress meter - just wrap any
  94. iterable with ``tqdm(iterable)``, and you're done!
  95. .. code:: python
  96. from tqdm import tqdm
  97. for i in tqdm(range(10000)):
  98. ...
  99. ``76%|████████████████████████        | 7568/10000 [00:33<00:10, 229.00it/s]``
  100. ``trange(N)`` can be also used as a convenient shortcut for
  101. ``tqdm(range(N))``.
  102. |Screenshot|
  103. |Video| |Slides| |Merch|
  104. It can also be executed as a module with pipes:
  105. .. code:: sh
  106. $ seq 9999999 | tqdm --bytes | wc -l
  107. 75.2MB [00:00, 217MB/s]
  108. 9999999
  109. $ tar -zcf - docs/ | tqdm --bytes --total `du -sb docs/ | cut -f1` \
  110. > backup.tgz
  111. 32%|██████████▍ | 8.89G/27.9G [00:42<01:31, 223MB/s]
  112. Overhead is low -- about 60ns per iteration (80ns with ``tqdm.gui``), and is
  113. unit tested against performance regression.
  114. By comparison, the well-established
  115. `ProgressBar <https://github.com/niltonvolpato/python-progressbar>`__ has
  116. an 800ns/iter overhead.
  117. In addition to its low overhead, ``tqdm`` uses smart algorithms to predict
  118. the remaining time and to skip unnecessary iteration displays, which allows
  119. for a negligible overhead in most cases.
  120. ``tqdm`` works on any platform
  121. (Linux, Windows, Mac, FreeBSD, NetBSD, Solaris/SunOS),
  122. in any console or in a GUI, and is also friendly with IPython/Jupyter notebooks.
  123. ``tqdm`` does not require any dependencies (not even ``curses``!), just
  124. Python and an environment supporting ``carriage return \r`` and
  125. ``line feed \n`` control characters.
  126. ------------------------------------------
  127. .. contents:: Table of contents
  128. :backlinks: top
  129. :local:
  130. Installation
  131. ------------
  132. Latest PyPI stable release
  133. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  134. |Versions| |PyPI-Downloads| |Libraries-Dependents|
  135. .. code:: sh
  136. pip install tqdm
  137. Latest development release on GitHub
  138. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  139. |GitHub-Status| |GitHub-Stars| |GitHub-Commits| |GitHub-Forks| |GitHub-Updated|
  140. Pull and install pre-release ``devel`` branch:
  141. .. code:: sh
  142. pip install "git+https://github.com/tqdm/tqdm.git@devel#egg=tqdm"
  143. Latest Conda release
  144. ~~~~~~~~~~~~~~~~~~~~
  145. |Conda-Forge-Status|
  146. .. code:: sh
  147. conda install -c conda-forge tqdm
  148. Latest Snapcraft release
  149. ~~~~~~~~~~~~~~~~~~~~~~~~
  150. |Snapcraft|
  151. There are 3 channels to choose from:
  152. .. code:: sh
  153. snap install tqdm # implies --stable, i.e. latest tagged release
  154. snap install tqdm --candidate # master branch
  155. snap install tqdm --edge # devel branch
  156. Note that ``snap`` binaries are purely for CLI use (not ``import``-able), and
  157. automatically set up ``bash`` tab-completion.
  158. Latest Docker release
  159. ~~~~~~~~~~~~~~~~~~~~~
  160. |Docker|
  161. .. code:: sh
  162. docker pull tqdm/tqdm
  163. docker run -i --rm tqdm/tqdm --help
  164. Other
  165. ~~~~~
  166. There are other (unofficial) places where ``tqdm`` may be downloaded, particularly for CLI use:
  167. |Repology|
  168. .. |Repology| image:: https://repology.org/badge/tiny-repos/python:tqdm.svg
  169. :target: https://repology.org/project/python:tqdm/versions
  170. Changelog
  171. ---------
  172. The list of all changes is available either on GitHub's Releases:
  173. |GitHub-Status|, on the
  174. `wiki <https://github.com/tqdm/tqdm/wiki/Releases>`__, or on the
  175. `website <https://tqdm.github.io/releases>`__.
  176. Usage
  177. -----
  178. ``tqdm`` is very versatile and can be used in a number of ways.
  179. The three main ones are given below.
  180. Iterable-based
  181. ~~~~~~~~~~~~~~
  182. Wrap ``tqdm()`` around any iterable:
  183. .. code:: python
  184. from tqdm import tqdm
  185. from time import sleep
  186. text = ""
  187. for char in tqdm(["a", "b", "c", "d"]):
  188. sleep(0.25)
  189. text = text + char
  190. ``trange(i)`` is a special optimised instance of ``tqdm(range(i))``:
  191. .. code:: python
  192. from tqdm import trange
  193. for i in trange(100):
  194. sleep(0.01)
  195. Instantiation outside of the loop allows for manual control over ``tqdm()``:
  196. .. code:: python
  197. pbar = tqdm(["a", "b", "c", "d"])
  198. for char in pbar:
  199. sleep(0.25)
  200. pbar.set_description("Processing %s" % char)
  201. Manual
  202. ~~~~~~
  203. Manual control of ``tqdm()`` updates using a ``with`` statement:
  204. .. code:: python
  205. with tqdm(total=100) as pbar:
  206. for i in range(10):
  207. sleep(0.1)
  208. pbar.update(10)
  209. If the optional variable ``total`` (or an iterable with ``len()``) is
  210. provided, predictive stats are displayed.
  211. ``with`` is also optional (you can just assign ``tqdm()`` to a variable,
  212. but in this case don't forget to ``del`` or ``close()`` at the end:
  213. .. code:: python
  214. pbar = tqdm(total=100)
  215. for i in range(10):
  216. sleep(0.1)
  217. pbar.update(10)
  218. pbar.close()
  219. Module
  220. ~~~~~~
  221. Perhaps the most wonderful use of ``tqdm`` is in a script or on the command
  222. line. Simply inserting ``tqdm`` (or ``python -m tqdm``) between pipes will pass
  223. through all ``stdin`` to ``stdout`` while printing progress to ``stderr``.
  224. The example below demonstrate counting the number of lines in all Python files
  225. in the current directory, with timing information included.
  226. .. code:: sh
  227. $ time find . -name '*.py' -type f -exec cat \{} \; | wc -l
  228. 857365
  229. real 0m3.458s
  230. user 0m0.274s
  231. sys 0m3.325s
  232. $ time find . -name '*.py' -type f -exec cat \{} \; | tqdm | wc -l
  233. 857366it [00:03, 246471.31it/s]
  234. 857365
  235. real 0m3.585s
  236. user 0m0.862s
  237. sys 0m3.358s
  238. Note that the usual arguments for ``tqdm`` can also be specified.
  239. .. code:: sh
  240. $ find . -name '*.py' -type f -exec cat \{} \; |
  241. tqdm --unit loc --unit_scale --total 857366 >> /dev/null
  242. 100%|█████████████████████████████████| 857K/857K [00:04<00:00, 246Kloc/s]
  243. Backing up a large directory?
  244. .. code:: sh
  245. $ tar -zcf - docs/ | tqdm --bytes --total `du -sb docs/ | cut -f1` \
  246. > backup.tgz
  247. 44%|██████████████▊ | 153M/352M [00:14<00:18, 11.0MB/s]
  248. This can be beautified further:
  249. .. code:: sh
  250. $ BYTES=$(du -sb docs/ | cut -f1)
  251. $ tar -cf - docs/ \
  252. | tqdm --bytes --total "$BYTES" --desc Processing | gzip \
  253. | tqdm --bytes --total "$BYTES" --desc Compressed --position 1 \
  254. > ~/backup.tgz
  255. Processing: 100%|██████████████████████| 352M/352M [00:14<00:00, 30.2MB/s]
  256. Compressed: 42%|█████████▎ | 148M/352M [00:14<00:19, 10.9MB/s]
  257. Or done on a file level using 7-zip:
  258. .. code:: sh
  259. $ 7z a -bd -r backup.7z docs/ | grep Compressing \
  260. | tqdm --total $(find docs/ -type f | wc -l) --unit files \
  261. | grep -v Compressing
  262. 100%|██████████████████████████▉| 15327/15327 [01:00<00:00, 712.96files/s]
  263. Pre-existing CLI programs already outputting basic progress information will
  264. benefit from ``tqdm``'s ``--update`` and ``--update_to`` flags:
  265. .. code:: sh
  266. $ seq 3 0.1 5 | tqdm --total 5 --update_to --null
  267. 100%|████████████████████████████████████| 5.0/5 [00:00<00:00, 9673.21it/s]
  268. $ seq 10 | tqdm --update --null # 1 + 2 + ... + 10 = 55 iterations
  269. 55it [00:00, 90006.52it/s]
  270. FAQ and Known Issues
  271. --------------------
  272. |GitHub-Issues|
  273. The most common issues relate to excessive output on multiple lines, instead
  274. of a neat one-line progress bar.
  275. - Consoles in general: require support for carriage return (``CR``, ``\r``).
  276. * Some cloud logging consoles which don't support ``\r`` properly
  277. (`cloudwatch <https://github.com/tqdm/tqdm/issues/966>`__,
  278. `K8s <https://github.com/tqdm/tqdm/issues/1319>`__) may benefit from
  279. ``export TQDM_POSITION=-1``.
  280. - Nested progress bars:
  281. * Consoles in general: require support for moving cursors up to the
  282. previous line. For example,
  283. `IDLE <https://github.com/tqdm/tqdm/issues/191#issuecomment-230168030>`__,
  284. `ConEmu <https://github.com/tqdm/tqdm/issues/254>`__ and
  285. `PyCharm <https://github.com/tqdm/tqdm/issues/203>`__ (also
  286. `here <https://github.com/tqdm/tqdm/issues/208>`__,
  287. `here <https://github.com/tqdm/tqdm/issues/307>`__, and
  288. `here <https://github.com/tqdm/tqdm/issues/454#issuecomment-335416815>`__)
  289. lack full support.
  290. * Windows: additionally may require the Python module ``colorama``
  291. to ensure nested bars stay within their respective lines.
  292. - Unicode:
  293. * Environments which report that they support unicode will have solid smooth
  294. progressbars. The fallback is an ``ascii``-only bar.
  295. * Windows consoles often only partially support unicode and thus
  296. `often require explicit ascii=True <https://github.com/tqdm/tqdm/issues/454#issuecomment-335416815>`__
  297. (also `here <https://github.com/tqdm/tqdm/issues/499>`__). This is due to
  298. either normal-width unicode characters being incorrectly displayed as
  299. "wide", or some unicode characters not rendering.
  300. - Wrapping generators:
  301. * Generator wrapper functions tend to hide the length of iterables.
  302. ``tqdm`` does not.
  303. * Replace ``tqdm(enumerate(...))`` with ``enumerate(tqdm(...))`` or
  304. ``tqdm(enumerate(x), total=len(x), ...)``.
  305. The same applies to ``numpy.ndenumerate``.
  306. * Replace ``tqdm(zip(a, b))`` with ``zip(tqdm(a), b)`` or even
  307. ``zip(tqdm(a), tqdm(b))``.
  308. * The same applies to ``itertools``.
  309. * Some useful convenience functions can be found under ``tqdm.contrib``.
  310. - `No intermediate output in docker-compose <https://github.com/tqdm/tqdm/issues/771>`__:
  311. use ``docker-compose run`` instead of ``docker-compose up`` and ``tty: true``.
  312. - Overriding defaults via environment variables:
  313. e.g. in CI/cloud jobs, ``export TQDM_MININTERVAL=5`` to avoid log spam.
  314. This override logic is handled by the ``tqdm.utils.envwrap`` decorator
  315. (useful independent of ``tqdm``).
  316. If you come across any other difficulties, browse and file |GitHub-Issues|.
  317. Documentation
  318. -------------
  319. |Py-Versions| |README-Hits| (Since 19 May 2016)
  320. .. code:: python
  321. class tqdm():
  322. """
  323. Decorate an iterable object, returning an iterator which acts exactly
  324. like the original iterable, but prints a dynamically updating
  325. progressbar every time a value is requested.
  326. """
  327. @envwrap("TQDM_") # override defaults via env vars
  328. def __init__(self, iterable=None, desc=None, total=None, leave=True,
  329. file=None, ncols=None, mininterval=0.1,
  330. maxinterval=10.0, miniters=None, ascii=None, disable=False,
  331. unit='it', unit_scale=False, dynamic_ncols=False,
  332. smoothing=0.3, bar_format=None, initial=0, position=None,
  333. postfix=None, unit_divisor=1000, write_bytes=False,
  334. lock_args=None, nrows=None, colour=None, delay=0):
  335. Parameters
  336. ~~~~~~~~~~
  337. * iterable : iterable, optional
  338. Iterable to decorate with a progressbar.
  339. Leave blank to manually manage the updates.
  340. * desc : str, optional
  341. Prefix for the progressbar.
  342. * total : int or float, optional
  343. The number of expected iterations. If unspecified,
  344. len(iterable) is used if possible. If float("inf") or as a last
  345. resort, only basic progress statistics are displayed
  346. (no ETA, no progressbar).
  347. If ``gui`` is True and this parameter needs subsequent updating,
  348. specify an initial arbitrary large positive number,
  349. e.g. 9e9.
  350. * leave : bool, optional
  351. If [default: True], keeps all traces of the progressbar
  352. upon termination of iteration.
  353. If ``None``, will leave only if ``position`` is ``0``.
  354. * file : ``io.TextIOWrapper`` or ``io.StringIO``, optional
  355. Specifies where to output the progress messages
  356. (default: sys.stderr). Uses ``file.write(str)`` and ``file.flush()``
  357. methods. For encoding, see ``write_bytes``.
  358. * ncols : int, optional
  359. The width of the entire output message. If specified,
  360. dynamically resizes the progressbar to stay within this bound.
  361. If unspecified, attempts to use environment width. The
  362. fallback is a meter width of 10 and no limit for the counter and
  363. statistics. If 0, will not print any meter (only stats).
  364. * mininterval : float, optional
  365. Minimum progress display update interval [default: 0.1] seconds.
  366. * maxinterval : float, optional
  367. Maximum progress display update interval [default: 10] seconds.
  368. Automatically adjusts ``miniters`` to correspond to ``mininterval``
  369. after long display update lag. Only works if ``dynamic_miniters``
  370. or monitor thread is enabled.
  371. * miniters : int or float, optional
  372. Minimum progress display update interval, in iterations.
  373. If 0 and ``dynamic_miniters``, will automatically adjust to equal
  374. ``mininterval`` (more CPU efficient, good for tight loops).
  375. If > 0, will skip display of specified number of iterations.
  376. Tweak this and ``mininterval`` to get very efficient loops.
  377. If your progress is erratic with both fast and slow iterations
  378. (network, skipping items, etc) you should set miniters=1.
  379. * ascii : bool or str, optional
  380. If unspecified or False, use unicode (smooth blocks) to fill
  381. the meter. The fallback is to use ASCII characters " 123456789#".
  382. * disable : bool, optional
  383. Whether to disable the entire progressbar wrapper
  384. [default: False]. If set to None, disable on non-TTY.
  385. * unit : str, optional
  386. String that will be used to define the unit of each iteration
  387. [default: it].
  388. * unit_scale : bool or int or float, optional
  389. If 1 or True, the number of iterations will be reduced/scaled
  390. automatically and a metric prefix following the
  391. International System of Units standard will be added
  392. (kilo, mega, etc.) [default: False]. If any other non-zero
  393. number, will scale ``total`` and ``n``.
  394. * dynamic_ncols : bool, optional
  395. If set, constantly alters ``ncols`` and ``nrows`` to the
  396. environment (allowing for window resizes) [default: False].
  397. * smoothing : float, optional
  398. Exponential moving average smoothing factor for speed estimates
  399. (ignored in GUI mode). Ranges from 0 (average speed) to 1
  400. (current/instantaneous speed) [default: 0.3].
  401. * bar_format : str, optional
  402. Specify a custom bar string formatting. May impact performance.
  403. [default: '{l_bar}{bar}{r_bar}'], where
  404. l_bar='{desc}: {percentage:3.0f}%|' and
  405. r_bar='| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, '
  406. '{rate_fmt}{postfix}]'
  407. Possible vars: l_bar, bar, r_bar, n, n_fmt, total, total_fmt,
  408. percentage, elapsed, elapsed_s, ncols, nrows, desc, unit,
  409. rate, rate_fmt, rate_noinv, rate_noinv_fmt,
  410. rate_inv, rate_inv_fmt, postfix, unit_divisor,
  411. remaining, remaining_s, eta.
  412. Note that a trailing ": " is automatically removed after {desc}
  413. if the latter is empty.
  414. * initial : int or float, optional
  415. The initial counter value. Useful when restarting a progress
  416. bar [default: 0]. If using float, consider specifying ``{n:.3f}``
  417. or similar in ``bar_format``, or specifying ``unit_scale``.
  418. * position : int, optional
  419. Specify the line offset to print this bar (starting from 0)
  420. Automatic if unspecified.
  421. Useful to manage multiple bars at once (eg, from threads).
  422. * postfix : dict or ``*``, optional
  423. Specify additional stats to display at the end of the bar.
  424. Calls ``set_postfix(**postfix)`` if possible (dict).
  425. * unit_divisor : float, optional
  426. [default: 1000], ignored unless ``unit_scale`` is True.
  427. * write_bytes : bool, optional
  428. Whether to write bytes. If (default: False) will write unicode.
  429. * lock_args : tuple, optional
  430. Passed to ``refresh`` for intermediate output
  431. (initialisation, iterating, and updating).
  432. * nrows : int, optional
  433. The screen height. If specified, hides nested bars outside this
  434. bound. If unspecified, attempts to use environment height.
  435. The fallback is 20.
  436. * colour : str, optional
  437. Bar colour (e.g. 'green', '#00ff00').
  438. * delay : float, optional
  439. Don't display until [default: 0] seconds have elapsed.
  440. Extra CLI Options
  441. ~~~~~~~~~~~~~~~~~
  442. * delim : chr, optional
  443. Delimiting character [default: '\n']. Use '\0' for null.
  444. N.B.: on Windows systems, Python converts '\n' to '\r\n'.
  445. * buf_size : int, optional
  446. String buffer size in bytes [default: 256]
  447. used when ``delim`` is specified.
  448. * bytes : bool, optional
  449. If true, will count bytes, ignore ``delim``, and default
  450. ``unit_scale`` to True, ``unit_divisor`` to 1024, and ``unit`` to 'B'.
  451. * tee : bool, optional
  452. If true, passes ``stdin`` to both ``stderr`` and ``stdout``.
  453. * update : bool, optional
  454. If true, will treat input as newly elapsed iterations,
  455. i.e. numbers to pass to ``update()``. Note that this is slow
  456. (~2e5 it/s) since every input must be decoded as a number.
  457. * update_to : bool, optional
  458. If true, will treat input as total elapsed iterations,
  459. i.e. numbers to assign to ``self.n``. Note that this is slow
  460. (~2e5 it/s) since every input must be decoded as a number.
  461. * null : bool, optional
  462. If true, will discard input (no stdout).
  463. * manpath : str, optional
  464. Directory in which to install tqdm man pages.
  465. * comppath : str, optional
  466. Directory in which to place tqdm completion.
  467. * log : str, optional
  468. CRITICAL|FATAL|ERROR|WARN(ING)|[default: 'INFO']|DEBUG|NOTSET.
  469. Returns
  470. ~~~~~~~
  471. * out : decorated iterator.
  472. .. code:: python
  473. class tqdm():
  474. def update(self, n=1):
  475. """
  476. Manually update the progress bar, useful for streams
  477. such as reading files.
  478. E.g.:
  479. >>> t = tqdm(total=filesize) # Initialise
  480. >>> for current_buffer in stream:
  481. ... ...
  482. ... t.update(len(current_buffer))
  483. >>> t.close()
  484. The last line is highly recommended, but possibly not necessary if
  485. ``t.update()`` will be called in such a way that ``filesize`` will be
  486. exactly reached and printed.
  487. Parameters
  488. ----------
  489. n : int or float, optional
  490. Increment to add to the internal counter of iterations
  491. [default: 1]. If using float, consider specifying ``{n:.3f}``
  492. or similar in ``bar_format``, or specifying ``unit_scale``.
  493. Returns
  494. -------
  495. out : bool or None
  496. True if a ``display()`` was triggered.
  497. """
  498. def close(self):
  499. """Cleanup and (if leave=False) close the progressbar."""
  500. def clear(self, nomove=False):
  501. """Clear current bar display."""
  502. def refresh(self):
  503. """
  504. Force refresh the display of this bar.
  505. Parameters
  506. ----------
  507. nolock : bool, optional
  508. If ``True``, does not lock.
  509. If [default: ``False``]: calls ``acquire()`` on internal lock.
  510. lock_args : tuple, optional
  511. Passed to internal lock's ``acquire()``.
  512. If specified, will only ``display()`` if ``acquire()`` returns ``True``.
  513. """
  514. def unpause(self):
  515. """Restart tqdm timer from last print time."""
  516. def reset(self, total=None):
  517. """
  518. Resets to 0 iterations for repeated use.
  519. Consider combining with ``leave=True``.
  520. Parameters
  521. ----------
  522. total : int or float, optional. Total to use for the new bar.
  523. """
  524. def set_description(self, desc=None, refresh=True):
  525. """
  526. Set/modify description of the progress bar.
  527. Parameters
  528. ----------
  529. desc : str, optional
  530. refresh : bool, optional
  531. Forces refresh [default: True].
  532. """
  533. def set_postfix(self, ordered_dict=None, refresh=True, **tqdm_kwargs):
  534. """
  535. Set/modify postfix (additional stats)
  536. with automatic formatting based on datatype.
  537. Parameters
  538. ----------
  539. ordered_dict : dict or OrderedDict, optional
  540. refresh : bool, optional
  541. Forces refresh [default: True].
  542. kwargs : dict, optional
  543. """
  544. @classmethod
  545. def write(cls, s, file=sys.stdout, end="\n"):
  546. """Print a message via tqdm (without overlap with bars)."""
  547. @property
  548. def format_dict(self):
  549. """Public API for read-only member access."""
  550. def display(self, msg=None, pos=None):
  551. """
  552. Use ``self.sp`` to display ``msg`` in the specified ``pos``.
  553. Consider overloading this function when inheriting to use e.g.:
  554. ``self.some_frontend(**self.format_dict)`` instead of ``self.sp``.
  555. Parameters
  556. ----------
  557. msg : str, optional. What to display (default: ``repr(self)``).
  558. pos : int, optional. Position to ``moveto``
  559. (default: ``abs(self.pos)``).
  560. """
  561. @classmethod
  562. @contextmanager
  563. def wrapattr(cls, stream, method, total=None, bytes=True, **tqdm_kwargs):
  564. """
  565. stream : file-like object.
  566. method : str, "read" or "write". The result of ``read()`` and
  567. the first argument of ``write()`` should have a ``len()``.
  568. >>> with tqdm.wrapattr(file_obj, "read", total=file_obj.size) as fobj:
  569. ... while True:
  570. ... chunk = fobj.read(chunk_size)
  571. ... if not chunk:
  572. ... break
  573. """
  574. @classmethod
  575. def pandas(cls, *targs, **tqdm_kwargs):
  576. """Registers the current `tqdm` class with `pandas`."""
  577. def trange(*args, **tqdm_kwargs):
  578. """Shortcut for `tqdm(range(*args), **tqdm_kwargs)`."""
  579. Convenience Functions
  580. ~~~~~~~~~~~~~~~~~~~~~
  581. .. code:: python
  582. def tqdm.contrib.tenumerate(iterable, start=0, total=None,
  583. tqdm_class=tqdm.auto.tqdm, **tqdm_kwargs):
  584. """Equivalent of `numpy.ndenumerate` or builtin `enumerate`."""
  585. def tqdm.contrib.tzip(iter1, *iter2plus, **tqdm_kwargs):
  586. """Equivalent of builtin `zip`."""
  587. def tqdm.contrib.tmap(function, *sequences, **tqdm_kwargs):
  588. """Equivalent of builtin `map`."""
  589. Submodules
  590. ~~~~~~~~~~
  591. .. code:: python
  592. class tqdm.notebook.tqdm(tqdm.tqdm):
  593. """IPython/Jupyter Notebook widget."""
  594. class tqdm.auto.tqdm(tqdm.tqdm):
  595. """Automatically chooses beween `tqdm.notebook` and `tqdm.tqdm`."""
  596. class tqdm.asyncio.tqdm(tqdm.tqdm):
  597. """Asynchronous version."""
  598. @classmethod
  599. def as_completed(cls, fs, *, loop=None, timeout=None, total=None,
  600. **tqdm_kwargs):
  601. """Wrapper for `asyncio.as_completed`."""
  602. class tqdm.gui.tqdm(tqdm.tqdm):
  603. """Matplotlib GUI version."""
  604. class tqdm.tk.tqdm(tqdm.tqdm):
  605. """Tkinter GUI version."""
  606. class tqdm.rich.tqdm(tqdm.tqdm):
  607. """`rich.progress` version."""
  608. class tqdm.keras.TqdmCallback(keras.callbacks.Callback):
  609. """Keras callback for epoch and batch progress."""
  610. class tqdm.dask.TqdmCallback(dask.callbacks.Callback):
  611. """Dask callback for task progress."""
  612. ``contrib``
  613. +++++++++++
  614. The ``tqdm.contrib`` package also contains experimental modules:
  615. - ``tqdm.contrib.itertools``: Thin wrappers around ``itertools``
  616. - ``tqdm.contrib.concurrent``: Thin wrappers around ``concurrent.futures``
  617. - ``tqdm.contrib.slack``: Posts to `Slack <https://slack.com>`__ bots
  618. - ``tqdm.contrib.discord``: Posts to `Discord <https://discord.com>`__ bots
  619. - ``tqdm.contrib.telegram``: Posts to `Telegram <https://telegram.org>`__ bots
  620. - ``tqdm.contrib.bells``: Automagically enables all optional features
  621. * ``auto``, ``pandas``, ``slack``, ``discord``, ``telegram``
  622. Examples and Advanced Usage
  623. ---------------------------
  624. - See the `examples <https://github.com/tqdm/tqdm/tree/master/examples>`__
  625. folder;
  626. - import the module and run ``help()``;
  627. - consult the `wiki <https://github.com/tqdm/tqdm/wiki>`__;
  628. * this has an
  629. `excellent article <https://github.com/tqdm/tqdm/wiki/How-to-make-a-great-Progress-Bar>`__
  630. on how to make a **great** progressbar;
  631. - check out the `slides from PyData London <https://tqdm.github.io/PyData2019/slides.html>`__, or
  632. - run the |binder-demo|.
  633. Description and additional stats
  634. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  635. Custom information can be displayed and updated dynamically on ``tqdm`` bars
  636. with the ``desc`` and ``postfix`` arguments:
  637. .. code:: python
  638. from tqdm import tqdm, trange
  639. from random import random, randint
  640. from time import sleep
  641. with trange(10) as t:
  642. for i in t:
  643. # Description will be displayed on the left
  644. t.set_description('GEN %i' % i)
  645. # Postfix will be displayed on the right,
  646. # formatted automatically based on argument's datatype
  647. t.set_postfix(loss=random(), gen=randint(1,999), str='h',
  648. lst=[1, 2])
  649. sleep(0.1)
  650. with tqdm(total=10, bar_format="{postfix[0]} {postfix[1][value]:>8.2g}",
  651. postfix=["Batch", {"value": 0}]) as t:
  652. for i in range(10):
  653. sleep(0.1)
  654. t.postfix[1]["value"] = i / 2
  655. t.update()
  656. Points to remember when using ``{postfix[...]}`` in the ``bar_format`` string:
  657. - ``postfix`` also needs to be passed as an initial argument in a compatible
  658. format, and
  659. - ``postfix`` will be auto-converted to a string if it is a ``dict``-like
  660. object. To prevent this behaviour, insert an extra item into the dictionary
  661. where the key is not a string.
  662. Additional ``bar_format`` parameters may also be defined by overriding
  663. ``format_dict``, and the bar itself may be modified using ``ascii``:
  664. .. code:: python
  665. from tqdm import tqdm
  666. class TqdmExtraFormat(tqdm):
  667. """Provides a `total_time` format parameter"""
  668. @property
  669. def format_dict(self):
  670. d = super().format_dict
  671. total_time = d["elapsed"] * (d["total"] or 0) / max(d["n"], 1)
  672. d.update(total_time=self.format_interval(total_time) + " in total")
  673. return d
  674. for i in TqdmExtraFormat(
  675. range(9), ascii=" .oO0",
  676. bar_format="{total_time}: {percentage:.0f}%|{bar}{r_bar}"):
  677. if i == 4:
  678. break
  679. .. code::
  680. 00:00 in total: 44%|0000. | 4/9 [00:00<00:00, 962.93it/s]
  681. Note that ``{bar}`` also supports a format specifier ``[width][type]``.
  682. - ``width``
  683. * unspecified (default): automatic to fill ``ncols``
  684. * ``int >= 0``: fixed width overriding ``ncols`` logic
  685. * ``int < 0``: subtract from the automatic default
  686. - ``type``
  687. * ``a``: ascii (``ascii=True`` override)
  688. * ``u``: unicode (``ascii=False`` override)
  689. * ``b``: blank (``ascii=" "`` override)
  690. This means a fixed bar with right-justified text may be created by using:
  691. ``bar_format="{l_bar}{bar:10}|{bar:-10b}right-justified"``
  692. Nested progress bars
  693. ~~~~~~~~~~~~~~~~~~~~
  694. ``tqdm`` supports nested progress bars. Here's an example:
  695. .. code:: python
  696. from tqdm.auto import trange
  697. from time import sleep
  698. for i in trange(4, desc='1st loop'):
  699. for j in trange(5, desc='2nd loop'):
  700. for k in trange(50, desc='3rd loop', leave=False):
  701. sleep(0.01)
  702. For manual control over positioning (e.g. for multi-processing use),
  703. you may specify ``position=n`` where ``n=0`` for the outermost bar,
  704. ``n=1`` for the next, and so on.
  705. However, it's best to check if ``tqdm`` can work without manual ``position``
  706. first.
  707. .. code:: python
  708. from time import sleep
  709. from tqdm import trange, tqdm
  710. from multiprocessing import Pool, RLock, freeze_support
  711. L = list(range(9))
  712. def progresser(n):
  713. interval = 0.001 / (n + 2)
  714. total = 5000
  715. text = f"#{n}, est. {interval * total:<04.2}s"
  716. for _ in trange(total, desc=text, position=n):
  717. sleep(interval)
  718. if __name__ == '__main__':
  719. freeze_support() # for Windows support
  720. tqdm.set_lock(RLock()) # for managing output contention
  721. p = Pool(initializer=tqdm.set_lock, initargs=(tqdm.get_lock(),))
  722. p.map(progresser, L)
  723. Note that in Python 3, ``tqdm.write`` is thread-safe:
  724. .. code:: python
  725. from time import sleep
  726. from tqdm import tqdm, trange
  727. from concurrent.futures import ThreadPoolExecutor
  728. L = list(range(9))
  729. def progresser(n):
  730. interval = 0.001 / (n + 2)
  731. total = 5000
  732. text = f"#{n}, est. {interval * total:<04.2}s"
  733. for _ in trange(total, desc=text):
  734. sleep(interval)
  735. if n == 6:
  736. tqdm.write("n == 6 completed.")
  737. tqdm.write("`tqdm.write()` is thread-safe in py3!")
  738. if __name__ == '__main__':
  739. with ThreadPoolExecutor() as p:
  740. p.map(progresser, L)
  741. Hooks and callbacks
  742. ~~~~~~~~~~~~~~~~~~~
  743. ``tqdm`` can easily support callbacks/hooks and manual updates.
  744. Here's an example with ``urllib``:
  745. **``urllib.urlretrieve`` documentation**
  746. | [...]
  747. | If present, the hook function will be called once
  748. | on establishment of the network connection and once after each block read
  749. | thereafter. The hook will be passed three arguments; a count of blocks
  750. | transferred so far, a block size in bytes, and the total size of the file.
  751. | [...]
  752. .. code:: python
  753. import urllib, os
  754. from tqdm import tqdm
  755. urllib = getattr(urllib, 'request', urllib)
  756. class TqdmUpTo(tqdm):
  757. """Provides `update_to(n)` which uses `tqdm.update(delta_n)`."""
  758. def update_to(self, b=1, bsize=1, tsize=None):
  759. """
  760. b : int, optional
  761. Number of blocks transferred so far [default: 1].
  762. bsize : int, optional
  763. Size of each block (in tqdm units) [default: 1].
  764. tsize : int, optional
  765. Total size (in tqdm units). If [default: None] remains unchanged.
  766. """
  767. if tsize is not None:
  768. self.total = tsize
  769. return self.update(b * bsize - self.n) # also sets self.n = b * bsize
  770. eg_link = "https://caspersci.uk.to/matryoshka.zip"
  771. with TqdmUpTo(unit='B', unit_scale=True, unit_divisor=1024, miniters=1,
  772. desc=eg_link.split('/')[-1]) as t: # all optional kwargs
  773. urllib.urlretrieve(eg_link, filename=os.devnull,
  774. reporthook=t.update_to, data=None)
  775. t.total = t.n
  776. Inspired by `twine#242 <https://github.com/pypa/twine/pull/242>`__.
  777. Functional alternative in
  778. `examples/tqdm_wget.py <https://github.com/tqdm/tqdm/blob/master/examples/tqdm_wget.py>`__.
  779. It is recommend to use ``miniters=1`` whenever there is potentially
  780. large differences in iteration speed (e.g. downloading a file over
  781. a patchy connection).
  782. **Wrapping read/write methods**
  783. To measure throughput through a file-like object's ``read`` or ``write``
  784. methods, use ``CallbackIOWrapper``:
  785. .. code:: python
  786. from tqdm.auto import tqdm
  787. from tqdm.utils import CallbackIOWrapper
  788. with tqdm(total=file_obj.size,
  789. unit='B', unit_scale=True, unit_divisor=1024) as t:
  790. fobj = CallbackIOWrapper(t.update, file_obj, "read")
  791. while True:
  792. chunk = fobj.read(chunk_size)
  793. if not chunk:
  794. break
  795. t.reset()
  796. # ... continue to use `t` for something else
  797. Alternatively, use the even simpler ``wrapattr`` convenience function,
  798. which would condense both the ``urllib`` and ``CallbackIOWrapper`` examples
  799. down to:
  800. .. code:: python
  801. import urllib, os
  802. from tqdm import tqdm
  803. eg_link = "https://caspersci.uk.to/matryoshka.zip"
  804. response = getattr(urllib, 'request', urllib).urlopen(eg_link)
  805. with tqdm.wrapattr(open(os.devnull, "wb"), "write",
  806. miniters=1, desc=eg_link.split('/')[-1],
  807. total=getattr(response, 'length', None)) as fout:
  808. for chunk in response:
  809. fout.write(chunk)
  810. The ``requests`` equivalent is nearly identical:
  811. .. code:: python
  812. import requests, os
  813. from tqdm import tqdm
  814. eg_link = "https://caspersci.uk.to/matryoshka.zip"
  815. response = requests.get(eg_link, stream=True)
  816. with tqdm.wrapattr(open(os.devnull, "wb"), "write",
  817. miniters=1, desc=eg_link.split('/')[-1],
  818. total=int(response.headers.get('content-length', 0))) as fout:
  819. for chunk in response.iter_content(chunk_size=4096):
  820. fout.write(chunk)
  821. **Custom callback**
  822. ``tqdm`` is known for intelligently skipping unnecessary displays. To make a
  823. custom callback take advantage of this, simply use the return value of
  824. ``update()``. This is set to ``True`` if a ``display()`` was triggered.
  825. .. code:: python
  826. from tqdm.auto import tqdm as std_tqdm
  827. def external_callback(*args, **kwargs):
  828. ...
  829. class TqdmExt(std_tqdm):
  830. def update(self, n=1):
  831. displayed = super().update(n)
  832. if displayed:
  833. external_callback(**self.format_dict)
  834. return displayed
  835. ``asyncio``
  836. ~~~~~~~~~~~
  837. Note that ``break`` isn't currently caught by asynchronous iterators.
  838. This means that ``tqdm`` cannot clean up after itself in this case:
  839. .. code:: python
  840. from tqdm.asyncio import tqdm
  841. async for i in tqdm(range(9)):
  842. if i == 2:
  843. break
  844. Instead, either call ``pbar.close()`` manually or use the context manager syntax:
  845. .. code:: python
  846. from tqdm.asyncio import tqdm
  847. with tqdm(range(9)) as pbar:
  848. async for i in pbar:
  849. if i == 2:
  850. break
  851. Pandas Integration
  852. ~~~~~~~~~~~~~~~~~~
  853. Due to popular demand we've added support for ``pandas`` -- here's an example
  854. for ``DataFrame.progress_apply`` and ``DataFrameGroupBy.progress_apply``:
  855. .. code:: python
  856. import pandas as pd
  857. import numpy as np
  858. from tqdm import tqdm
  859. df = pd.DataFrame(np.random.randint(0, 100, (100000, 6)))
  860. # Register `pandas.progress_apply` and `pandas.Series.map_apply` with `tqdm`
  861. # (can use `tqdm.gui.tqdm`, `tqdm.notebook.tqdm`, optional kwargs, etc.)
  862. tqdm.pandas(desc="my bar!")
  863. # Now you can use `progress_apply` instead of `apply`
  864. # and `progress_map` instead of `map`
  865. df.progress_apply(lambda x: x**2)
  866. # can also groupby:
  867. # df.groupby(0).progress_apply(lambda x: x**2)
  868. In case you're interested in how this works (and how to modify it for your
  869. own callbacks), see the
  870. `examples <https://github.com/tqdm/tqdm/tree/master/examples>`__
  871. folder or import the module and run ``help()``.
  872. Keras Integration
  873. ~~~~~~~~~~~~~~~~~
  874. A ``keras`` callback is also available:
  875. .. code:: python
  876. from tqdm.keras import TqdmCallback
  877. ...
  878. model.fit(..., verbose=0, callbacks=[TqdmCallback()])
  879. Dask Integration
  880. ~~~~~~~~~~~~~~~~
  881. A ``dask`` callback is also available:
  882. .. code:: python
  883. from tqdm.dask import TqdmCallback
  884. with TqdmCallback(desc="compute"):
  885. ...
  886. arr.compute()
  887. # or use callback globally
  888. cb = TqdmCallback(desc="global")
  889. cb.register()
  890. arr.compute()
  891. IPython/Jupyter Integration
  892. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  893. IPython/Jupyter is supported via the ``tqdm.notebook`` submodule:
  894. .. code:: python
  895. from tqdm.notebook import trange, tqdm
  896. from time import sleep
  897. for i in trange(3, desc='1st loop'):
  898. for j in tqdm(range(100), desc='2nd loop'):
  899. sleep(0.01)
  900. In addition to ``tqdm`` features, the submodule provides a native Jupyter
  901. widget (compatible with IPython v1-v4 and Jupyter), fully working nested bars
  902. and colour hints (blue: normal, green: completed, red: error/interrupt,
  903. light blue: no ETA); as demonstrated below.
  904. |Screenshot-Jupyter1|
  905. |Screenshot-Jupyter2|
  906. |Screenshot-Jupyter3|
  907. The ``notebook`` version supports percentage or pixels for overall width
  908. (e.g.: ``ncols='100%'`` or ``ncols='480px'``).
  909. It is also possible to let ``tqdm`` automatically choose between
  910. console or notebook versions by using the ``autonotebook`` submodule:
  911. .. code:: python
  912. from tqdm.autonotebook import tqdm
  913. tqdm.pandas()
  914. Note that this will issue a ``TqdmExperimentalWarning`` if run in a notebook
  915. since it is not meant to be possible to distinguish between ``jupyter notebook``
  916. and ``jupyter console``. Use ``auto`` instead of ``autonotebook`` to suppress
  917. this warning.
  918. Note that notebooks will display the bar in the cell where it was created.
  919. This may be a different cell from the one where it is used.
  920. If this is not desired, either
  921. - delay the creation of the bar to the cell where it must be displayed, or
  922. - create the bar with ``display=False``, and in a later cell call
  923. ``display(bar.container)``:
  924. .. code:: python
  925. from tqdm.notebook import tqdm
  926. pbar = tqdm(..., display=False)
  927. .. code:: python
  928. # different cell
  929. display(pbar.container)
  930. The ``keras`` callback has a ``display()`` method which can be used likewise:
  931. .. code:: python
  932. from tqdm.keras import TqdmCallback
  933. cbk = TqdmCallback(display=False)
  934. .. code:: python
  935. # different cell
  936. cbk.display()
  937. model.fit(..., verbose=0, callbacks=[cbk])
  938. Another possibility is to have a single bar (near the top of the notebook)
  939. which is constantly re-used (using ``reset()`` rather than ``close()``).
  940. For this reason, the notebook version (unlike the CLI version) does not
  941. automatically call ``close()`` upon ``Exception``.
  942. .. code:: python
  943. from tqdm.notebook import tqdm
  944. pbar = tqdm()
  945. .. code:: python
  946. # different cell
  947. iterable = range(100)
  948. pbar.reset(total=len(iterable)) # initialise with new `total`
  949. for i in iterable:
  950. pbar.update()
  951. pbar.refresh() # force print final status but don't `close()`
  952. Custom Integration
  953. ~~~~~~~~~~~~~~~~~~
  954. To change the default arguments (such as making ``dynamic_ncols=True``),
  955. simply use built-in Python magic:
  956. .. code:: python
  957. from functools import partial
  958. from tqdm import tqdm as std_tqdm
  959. tqdm = partial(std_tqdm, dynamic_ncols=True)
  960. For further customisation,
  961. ``tqdm`` may be inherited from to create custom callbacks (as with the
  962. ``TqdmUpTo`` example `above <#hooks-and-callbacks>`__) or for custom frontends
  963. (e.g. GUIs such as notebook or plotting packages). In the latter case:
  964. 1. ``def __init__()`` to call ``super().__init__(..., gui=True)`` to disable
  965. terminal ``status_printer`` creation.
  966. 2. Redefine: ``close()``, ``clear()``, ``display()``.
  967. Consider overloading ``display()`` to use e.g.
  968. ``self.frontend(**self.format_dict)`` instead of ``self.sp(repr(self))``.
  969. Some submodule examples of inheritance:
  970. - `tqdm/notebook.py <https://github.com/tqdm/tqdm/blob/master/tqdm/notebook.py>`__
  971. - `tqdm/gui.py <https://github.com/tqdm/tqdm/blob/master/tqdm/gui.py>`__
  972. - `tqdm/tk.py <https://github.com/tqdm/tqdm/blob/master/tqdm/tk.py>`__
  973. - `tqdm/contrib/slack.py <https://github.com/tqdm/tqdm/blob/master/tqdm/contrib/slack.py>`__
  974. - `tqdm/contrib/discord.py <https://github.com/tqdm/tqdm/blob/master/tqdm/contrib/discord.py>`__
  975. - `tqdm/contrib/telegram.py <https://github.com/tqdm/tqdm/blob/master/tqdm/contrib/telegram.py>`__
  976. Dynamic Monitor/Meter
  977. ~~~~~~~~~~~~~~~~~~~~~
  978. You can use a ``tqdm`` as a meter which is not monotonically increasing.
  979. This could be because ``n`` decreases (e.g. a CPU usage monitor) or ``total``
  980. changes.
  981. One example would be recursively searching for files. The ``total`` is the
  982. number of objects found so far, while ``n`` is the number of those objects which
  983. are files (rather than folders):
  984. .. code:: python
  985. from tqdm import tqdm
  986. import os.path
  987. def find_files_recursively(path, show_progress=True):
  988. files = []
  989. # total=1 assumes `path` is a file
  990. t = tqdm(total=1, unit="file", disable=not show_progress)
  991. if not os.path.exists(path):
  992. raise IOError("Cannot find:" + path)
  993. def append_found_file(f):
  994. files.append(f)
  995. t.update()
  996. def list_found_dir(path):
  997. """returns os.listdir(path) assuming os.path.isdir(path)"""
  998. listing = os.listdir(path)
  999. # subtract 1 since a "file" we found was actually this directory
  1000. t.total += len(listing) - 1
  1001. # fancy way to give info without forcing a refresh
  1002. t.set_postfix(dir=path[-10:], refresh=False)
  1003. t.update(0) # may trigger a refresh
  1004. return listing
  1005. def recursively_search(path):
  1006. if os.path.isdir(path):
  1007. for f in list_found_dir(path):
  1008. recursively_search(os.path.join(path, f))
  1009. else:
  1010. append_found_file(path)
  1011. recursively_search(path)
  1012. t.set_postfix(dir=path)
  1013. t.close()
  1014. return files
  1015. Using ``update(0)`` is a handy way to let ``tqdm`` decide when to trigger a
  1016. display refresh to avoid console spamming.
  1017. Writing messages
  1018. ~~~~~~~~~~~~~~~~
  1019. This is a work in progress (see
  1020. `#737 <https://github.com/tqdm/tqdm/issues/737>`__).
  1021. Since ``tqdm`` uses a simple printing mechanism to display progress bars,
  1022. you should not write any message in the terminal using ``print()`` while
  1023. a progressbar is open.
  1024. To write messages in the terminal without any collision with ``tqdm`` bar
  1025. display, a ``.write()`` method is provided:
  1026. .. code:: python
  1027. from tqdm.auto import tqdm, trange
  1028. from time import sleep
  1029. bar = trange(10)
  1030. for i in bar:
  1031. # Print using tqdm class method .write()
  1032. sleep(0.1)
  1033. if not (i % 3):
  1034. tqdm.write("Done task %i" % i)
  1035. # Can also use bar.write()
  1036. By default, this will print to standard output ``sys.stdout``. but you can
  1037. specify any file-like object using the ``file`` argument. For example, this
  1038. can be used to redirect the messages writing to a log file or class.
  1039. Redirecting writing
  1040. ~~~~~~~~~~~~~~~~~~~
  1041. If using a library that can print messages to the console, editing the library
  1042. by replacing ``print()`` with ``tqdm.write()`` may not be desirable.
  1043. In that case, redirecting ``sys.stdout`` to ``tqdm.write()`` is an option.
  1044. To redirect ``sys.stdout``, create a file-like class that will write
  1045. any input string to ``tqdm.write()``, and supply the arguments
  1046. ``file=sys.stdout, dynamic_ncols=True``.
  1047. A reusable canonical example is given below:
  1048. .. code:: python
  1049. from time import sleep
  1050. import contextlib
  1051. import sys
  1052. from tqdm import tqdm
  1053. from tqdm.contrib import DummyTqdmFile
  1054. @contextlib.contextmanager
  1055. def std_out_err_redirect_tqdm():
  1056. orig_out_err = sys.stdout, sys.stderr
  1057. try:
  1058. sys.stdout, sys.stderr = map(DummyTqdmFile, orig_out_err)
  1059. yield orig_out_err[0]
  1060. # Relay exceptions
  1061. except Exception as exc:
  1062. raise exc
  1063. # Always restore sys.stdout/err if necessary
  1064. finally:
  1065. sys.stdout, sys.stderr = orig_out_err
  1066. def some_fun(i):
  1067. print("Fee, fi, fo,".split()[i])
  1068. # Redirect stdout to tqdm.write() (don't forget the `as save_stdout`)
  1069. with std_out_err_redirect_tqdm() as orig_stdout:
  1070. # tqdm needs the original stdout
  1071. # and dynamic_ncols=True to autodetect console width
  1072. for i in tqdm(range(3), file=orig_stdout, dynamic_ncols=True):
  1073. sleep(.5)
  1074. some_fun(i)
  1075. # After the `with`, printing is restored
  1076. print("Done!")
  1077. Redirecting ``logging``
  1078. ~~~~~~~~~~~~~~~~~~~~~~~
  1079. Similar to ``sys.stdout``/``sys.stderr`` as detailed above, console ``logging``
  1080. may also be redirected to ``tqdm.write()``.
  1081. Warning: if also redirecting ``sys.stdout``/``sys.stderr``, make sure to
  1082. redirect ``logging`` first if needed.
  1083. Helper methods are available in ``tqdm.contrib.logging``. For example:
  1084. .. code:: python
  1085. import logging
  1086. from tqdm import trange
  1087. from tqdm.contrib.logging import logging_redirect_tqdm
  1088. LOG = logging.getLogger(__name__)
  1089. if __name__ == '__main__':
  1090. logging.basicConfig(level=logging.INFO)
  1091. with logging_redirect_tqdm():
  1092. for i in trange(9):
  1093. if i == 4:
  1094. LOG.info("console logging redirected to `tqdm.write()`")
  1095. # logging restored
  1096. Monitoring thread, intervals and miniters
  1097. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1098. ``tqdm`` implements a few tricks to increase efficiency and reduce overhead.
  1099. - Avoid unnecessary frequent bar refreshing: ``mininterval`` defines how long
  1100. to wait between each refresh. ``tqdm`` always gets updated in the background,
  1101. but it will display only every ``mininterval``.
  1102. - Reduce number of calls to check system clock/time.
  1103. - ``mininterval`` is more intuitive to configure than ``miniters``.
  1104. A clever adjustment system ``dynamic_miniters`` will automatically adjust
  1105. ``miniters`` to the amount of iterations that fit into time ``mininterval``.
  1106. Essentially, ``tqdm`` will check if it's time to print without actually
  1107. checking time. This behaviour can be still be bypassed by manually setting
  1108. ``miniters``.
  1109. However, consider a case with a combination of fast and slow iterations.
  1110. After a few fast iterations, ``dynamic_miniters`` will set ``miniters`` to a
  1111. large number. When iteration rate subsequently slows, ``miniters`` will
  1112. remain large and thus reduce display update frequency. To address this:
  1113. - ``maxinterval`` defines the maximum time between display refreshes.
  1114. A concurrent monitoring thread checks for overdue updates and forces one
  1115. where necessary.
  1116. The monitoring thread should not have a noticeable overhead, and guarantees
  1117. updates at least every 10 seconds by default.
  1118. This value can be directly changed by setting the ``monitor_interval`` of
  1119. any ``tqdm`` instance (i.e. ``t = tqdm.tqdm(...); t.monitor_interval = 2``).
  1120. The monitor thread may be disabled application-wide by setting
  1121. ``tqdm.tqdm.monitor_interval = 0`` before instantiation of any ``tqdm`` bar.
  1122. Merch
  1123. -----
  1124. You can buy `tqdm branded merch <https://tqdm.github.io/merch>`__ now!
  1125. Contributions
  1126. -------------
  1127. |GitHub-Commits| |GitHub-Issues| |GitHub-PRs| |OpenHub-Status| |GitHub-Contributions| |CII Best Practices|
  1128. All source code is hosted on `GitHub <https://github.com/tqdm/tqdm>`__.
  1129. Contributions are welcome.
  1130. See the
  1131. `CONTRIBUTING <https://github.com/tqdm/tqdm/blob/master/CONTRIBUTING.md>`__
  1132. file for more information.
  1133. Developers who have made significant contributions, ranked by *SLoC*
  1134. (surviving lines of code,
  1135. `git fame <https://github.com/casperdcl/git-fame>`__ ``-wMC --excl '\.(png|gif|jpg)$'``),
  1136. are:
  1137. ==================== ======================================================== ==== ================================
  1138. Name ID SLoC Notes
  1139. ==================== ======================================================== ==== ================================
  1140. Casper da Costa-Luis `casperdcl <https://github.com/casperdcl>`__ ~80% primary maintainer |Gift-Casper|
  1141. Stephen Larroque `lrq3000 <https://github.com/lrq3000>`__ ~9% team member
  1142. Martin Zugnoni `martinzugnoni <https://github.com/martinzugnoni>`__ ~3%
  1143. Daniel Ecer `de-code <https://github.com/de-code>`__ ~2%
  1144. Richard Sheridan `richardsheridan <https://github.com/richardsheridan>`__ ~1%
  1145. Guangshuo Chen `chengs <https://github.com/chengs>`__ ~1%
  1146. Helio Machado `0x2b3bfa0 <https://github.com/0x2b3bfa0>`__ ~1%
  1147. Kyle Altendorf `altendky <https://github.com/altendky>`__ <1%
  1148. Noam Yorav-Raphael `noamraph <https://github.com/noamraph>`__ <1% original author
  1149. Matthew Stevens `mjstevens777 <https://github.com/mjstevens777>`__ <1%
  1150. Hadrien Mary `hadim <https://github.com/hadim>`__ <1% team member
  1151. Mikhail Korobov `kmike <https://github.com/kmike>`__ <1% team member
  1152. ==================== ======================================================== ==== ================================
  1153. Ports to Other Languages
  1154. ~~~~~~~~~~~~~~~~~~~~~~~~
  1155. A list is available on
  1156. `this wiki page <https://github.com/tqdm/tqdm/wiki/tqdm-ports>`__.
  1157. LICENCE
  1158. -------
  1159. Open Source (OSI approved): |LICENCE|
  1160. Citation information: |DOI|
  1161. |README-Hits| (Since 19 May 2016)
  1162. .. |Logo| image:: https://tqdm.github.io/img/logo.gif
  1163. .. |Screenshot| image:: https://tqdm.github.io/img/tqdm.gif
  1164. .. |Video| image:: https://tqdm.github.io/img/video.jpg
  1165. :target: https://tqdm.github.io/video
  1166. .. |Slides| image:: https://tqdm.github.io/img/slides.jpg
  1167. :target: https://tqdm.github.io/PyData2019/slides.html
  1168. .. |Merch| image:: https://tqdm.github.io/img/merch.jpg
  1169. :target: https://tqdm.github.io/merch
  1170. .. |Build-Status| image:: https://img.shields.io/github/actions/workflow/status/tqdm/tqdm/test.yml?branch=master&label=tqdm&logo=GitHub
  1171. :target: https://github.com/tqdm/tqdm/actions/workflows/test.yml
  1172. .. |Coverage-Status| image:: https://img.shields.io/coveralls/github/tqdm/tqdm/master?logo=coveralls
  1173. :target: https://coveralls.io/github/tqdm/tqdm
  1174. .. |Branch-Coverage-Status| image:: https://codecov.io/gh/tqdm/tqdm/branch/master/graph/badge.svg
  1175. :target: https://codecov.io/gh/tqdm/tqdm
  1176. .. |Codacy-Grade| image:: https://app.codacy.com/project/badge/Grade/3f965571598f44549c7818f29cdcf177
  1177. :target: https://www.codacy.com/gh/tqdm/tqdm/dashboard
  1178. .. |CII Best Practices| image:: https://bestpractices.coreinfrastructure.org/projects/3264/badge
  1179. :target: https://bestpractices.coreinfrastructure.org/projects/3264
  1180. .. |GitHub-Status| image:: https://img.shields.io/github/tag/tqdm/tqdm.svg?maxAge=86400&logo=github&logoColor=white
  1181. :target: https://github.com/tqdm/tqdm/releases
  1182. .. |GitHub-Forks| image:: https://img.shields.io/github/forks/tqdm/tqdm.svg?logo=github&logoColor=white
  1183. :target: https://github.com/tqdm/tqdm/network
  1184. .. |GitHub-Stars| image:: https://img.shields.io/github/stars/tqdm/tqdm.svg?logo=github&logoColor=white
  1185. :target: https://github.com/tqdm/tqdm/stargazers
  1186. .. |GitHub-Commits| image:: https://img.shields.io/github/commit-activity/y/tqdm/tqdm.svg?logo=git&logoColor=white
  1187. :target: https://github.com/tqdm/tqdm/graphs/commit-activity
  1188. .. |GitHub-Issues| image:: https://img.shields.io/github/issues-closed/tqdm/tqdm.svg?logo=github&logoColor=white
  1189. :target: https://github.com/tqdm/tqdm/issues?q=
  1190. .. |GitHub-PRs| image:: https://img.shields.io/github/issues-pr-closed/tqdm/tqdm.svg?logo=github&logoColor=white
  1191. :target: https://github.com/tqdm/tqdm/pulls
  1192. .. |GitHub-Contributions| image:: https://img.shields.io/github/contributors/tqdm/tqdm.svg?logo=github&logoColor=white
  1193. :target: https://github.com/tqdm/tqdm/graphs/contributors
  1194. .. |GitHub-Updated| image:: https://img.shields.io/github/last-commit/tqdm/tqdm/master.svg?logo=github&logoColor=white&label=pushed
  1195. :target: https://github.com/tqdm/tqdm/pulse
  1196. .. |Gift-Casper| image:: https://img.shields.io/badge/dynamic/json.svg?color=ff69b4&label=gifts%20received&prefix=%C2%A3&query=%24..sum&url=https%3A%2F%2Fcaspersci.uk.to%2Fgifts.json
  1197. :target: https://cdcl.ml/sponsor
  1198. .. |Versions| image:: https://img.shields.io/pypi/v/tqdm.svg
  1199. :target: https://tqdm.github.io/releases
  1200. .. |PyPI-Downloads| image:: https://img.shields.io/pypi/dm/tqdm.svg?label=pypi%20downloads&logo=PyPI&logoColor=white
  1201. :target: https://pepy.tech/project/tqdm
  1202. .. |Py-Versions| image:: https://img.shields.io/pypi/pyversions/tqdm.svg?logo=python&logoColor=white
  1203. :target: https://pypi.org/project/tqdm
  1204. .. |Conda-Forge-Status| image:: https://img.shields.io/conda/v/conda-forge/tqdm.svg?label=conda-forge&logo=conda-forge
  1205. :target: https://anaconda.org/conda-forge/tqdm
  1206. .. |Snapcraft| image:: https://img.shields.io/badge/snap-install-82BEA0.svg?logo=snapcraft
  1207. :target: https://snapcraft.io/tqdm
  1208. .. |Docker| image:: https://img.shields.io/badge/docker-pull-blue.svg?logo=docker&logoColor=white
  1209. :target: https://hub.docker.com/r/tqdm/tqdm
  1210. .. |Libraries-Rank| image:: https://img.shields.io/librariesio/sourcerank/pypi/tqdm.svg?logo=koding&logoColor=white
  1211. :target: https://libraries.io/pypi/tqdm
  1212. .. |Libraries-Dependents| image:: https://img.shields.io/librariesio/dependent-repos/pypi/tqdm.svg?logo=koding&logoColor=white
  1213. :target: https://github.com/tqdm/tqdm/network/dependents
  1214. .. |OpenHub-Status| image:: https://www.openhub.net/p/tqdm/widgets/project_thin_badge?format=gif
  1215. :target: https://www.openhub.net/p/tqdm?ref=Thin+badge
  1216. .. |awesome-python| image:: https://awesome.re/mentioned-badge.svg
  1217. :target: https://github.com/vinta/awesome-python
  1218. .. |LICENCE| image:: https://img.shields.io/pypi/l/tqdm.svg
  1219. :target: https://raw.githubusercontent.com/tqdm/tqdm/master/LICENCE
  1220. .. |DOI| image:: https://img.shields.io/badge/DOI-10.5281/zenodo.595120-blue.svg
  1221. :target: https://doi.org/10.5281/zenodo.595120
  1222. .. |binder-demo| image:: https://mybinder.org/badge_logo.svg
  1223. :target: https://mybinder.org/v2/gh/tqdm/tqdm/master?filepath=DEMO.ipynb
  1224. .. |Screenshot-Jupyter1| image:: https://tqdm.github.io/img/jupyter-1.gif
  1225. .. |Screenshot-Jupyter2| image:: https://tqdm.github.io/img/jupyter-2.gif
  1226. .. |Screenshot-Jupyter3| image:: https://tqdm.github.io/img/jupyter-3.gif
  1227. .. |README-Hits| image:: https://cgi.cdcl.ml/hits?q=tqdm&style=social&r=https://github.com/tqdm/tqdm&l=https://tqdm.github.io/img/favicon.png&f=https://tqdm.github.io/img/logo.gif
  1228. :target: https://cgi.cdcl.ml/hits?q=tqdm&a=plot&r=https://github.com/tqdm/tqdm&l=https://tqdm.github.io/img/favicon.png&f=https://tqdm.github.io/img/logo.gif&style=social