METADATA 56 KB

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