Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .cache/pip/http-v2/3/2/2/c/b/322cb2d2fa9c18feda7312c66e98b038ca0bb7446362e84c4a580aa3.body +169 -0
- .cache/pip/http-v2/3/3/a/d/7/33ad7fe31489f80e15fea42300adbfc4d75c0efc76d75cfab7d2e5b0.body +0 -0
- .cache/pip/http-v2/3/8/6/0/e/3860e4de9ae53c79d2fd61419e9049df314ccc8b640782c02c6e2e2d.body +0 -0
- .cache/pip/http-v2/6/0/1/a/a/601aa27698da49f5bed3bc91bb41d8245b8316b66bd86059ef3b929e +0 -0
- .cache/pip/http-v2/6/1/4/f/4/614f46c6d1c16fa5b0800dfd0497e41c5b320e16ee8c9d943d4dd341 +0 -0
- .cache/pip/http-v2/6/1/6/7/8/61678d682a1ea716fb4acccebc1350da197d2251a96e4b9220061051.body +0 -0
- .cache/pip/http-v2/6/4/6/e/5/646e5ac002367fdec50dea7e9d47599302e4790e77000da2571c33e8.body +0 -0
- .cache/pip/http-v2/6/5/0/7/2/65072c35290c429df2e84cb69eba045284d50944561efa156675456a.body +0 -0
- .cache/pip/http-v2/6/6/b/a/b/66bab8cde451822060c031dc988659e1fe4348c71c2fbd112ca75eca +0 -0
- .cache/pip/http-v2/6/6/b/a/b/66bab8cde451822060c031dc988659e1fe4348c71c2fbd112ca75eca.body +0 -0
- .cache/pip/http-v2/6/6/e/c/7/66ec76a7b6ed4081044f5c7821af293b63c17bc2ac523ff93d5ca7d5.body +0 -0
- .cache/pip/http-v2/8/1/1/c/d/811cdc5b0df1a4862e5588ed7d10948f806b064e30962a3f3e310c26 +0 -0
- .cache/pip/http-v2/8/1/1/c/d/811cdc5b0df1a4862e5588ed7d10948f806b064e30962a3f3e310c26.body +650 -0
- .cache/pip/http-v2/8/1/3/c/c/813cc7096c25ba43edba14a4ab40832db33af638c43e975795995aec +0 -0
- .cache/pip/http-v2/8/7/3/3/b/8733b40e52a573d98e55534434c69a8765ca0cd71166704a3188ddb3 +0 -0
- .cache/pip/http-v2/8/7/9/e/a/879eab407895dd6690258943fd9ec2bee9d83a6d395dfe3e4bf6ce4f +0 -0
- .cache/pip/http-v2/8/7/9/e/a/879eab407895dd6690258943fd9ec2bee9d83a6d395dfe3e4bf6ce4f.body +212 -0
- .cache/pip/http-v2/8/9/2/3/0/89230ee5375192cd78aff8dee73d946e2bcfcfb4c3ec4374132fe597 +0 -0
- .cache/pip/http-v2/8/9/3/a/9/893a9178010858cecf72b523725b46ddedbe6c23406a020810080ab3 +0 -0
- .cache/pip/http-v2/8/9/3/a/9/893a9178010858cecf72b523725b46ddedbe6c23406a020810080ab3.body +0 -0
- .cache/pip/http-v2/8/f/4/1/0/8f410bbfc5d1848453018f07fdeb351a0d0ae8a3bcdc5a16f937935c +0 -0
- .cache/pip/http-v2/c/4/2/0/3/c4203c5060d0f778eafd521050eab23e6aaa0f9eefa17eb1e671212c.body +0 -0
- .cache/pip/http-v2/c/5/4/0/3/c5403a101bbaf526810b4c472004bc3b03b96b7c8118e06c7a081e63 +0 -0
- .cache/pip/http-v2/c/d/5/d/e/cd5de44b899cbe1869765c21b55cffc53c0c0ffa9d3c6f1fd40a42a2 +0 -0
- .cache/pip/http-v2/e/0/2/d/2/e02d204cdd3b7d268ee1e9bbce86143c099522474d7852833cd72d7a.body +0 -0
- .cache/pip/http-v2/e/1/b/5/5/e1b55fb53084fd5cce9225f16241fc71d928894827c254f9bf6a38ba.body +0 -0
- .cache/pip/http-v2/e/2/1/8/e/e218e159f80d2bf1828c7fd77e9bd5d91b70e0dc57d3760ff21315f2 +0 -0
- .cache/pip/http-v2/e/2/1/8/e/e218e159f80d2bf1828c7fd77e9bd5d91b70e0dc57d3760ff21315f2.body +0 -0
- .cache/pip/http-v2/e/9/6/f/6/e96f6a0f641ba82c2185cbd0cd572ff721b2be1fc873c69faf0ff627 +0 -0
- .cache/pip/http-v2/e/9/6/f/6/e96f6a0f641ba82c2185cbd0cd572ff721b2be1fc873c69faf0ff627.body +0 -0
- .cache/pip/http-v2/e/9/9/d/2/e99d273763b5a9911259ba7015a44152ddf05aec2016679f6c849a2a.body +103 -0
- .cache/pip/http-v2/e/a/c/6/1/eac61126daf80149d2a016f12a54eab5e3b5c1dbc77410ff1a97edc4 +0 -0
- .cache/pip/http-v2/f/3/c/4/d/f3c4dedd1435641845fe96a7938402191795947fd69de9d823bd65e1 +0 -0
- .cache/pip/http-v2/f/4/3/c/e/f43ce2cb74a8c7ad77da70314e043a539a7f01416550c3167312132b +0 -0
- .cache/pip/http-v2/f/4/4/1/e/f441e9f50c61e41b200d99c506edae810953f5810bcb8a4e8bae463c.body +0 -0
- .cache/pip/http-v2/f/6/8/9/5/f689581dbe86ea3c1a14226c252116f97e87dde2c835d7d60fd42b59 +0 -0
- .cache/pip/http-v2/f/a/0/e/b/fa0eb94064e725636a09e766c68812661f1423e7568ddc8b81c74949 +0 -0
- .cache/pip/http-v2/f/a/0/e/b/fa0eb94064e725636a09e766c68812661f1423e7568ddc8b81c74949.body +1591 -0
- .cache/pip/http-v2/f/b/e/3/a/fbe3a5eb3735a745707ab3bf39e17d76ea29c7cd1eaa7763f11e1766 +0 -0
- .cache/pip/selfcheck/241e69162522ccf5846a2f42ebc24b17464915a155679666b89a9f31 +1 -0
- .jupyter/jupyter_nbconvert_config.json +13 -0
- .jupyter/jupyter_notebook_config.json +7 -0
- .jupyter/lab/workspaces/default-37a8.jupyterlab-workspace +1 -0
- .local/share/jupyter/nbextensions/autoscroll/main.js +130 -0
- .local/share/jupyter/nbextensions/cell_filter/cell_filter.js +133 -0
- .local/share/jupyter/nbextensions/code_font_size/code_font_size.yaml +7 -0
- .local/share/jupyter/nbextensions/code_prettify/2to3.yaml +65 -0
- .local/share/jupyter/nbextensions/code_prettify/README_2to3.md +139 -0
- .local/share/jupyter/nbextensions/code_prettify/README_isort.md +44 -0
- .local/share/jupyter/nbextensions/code_prettify/autopep8.js +36 -0
.cache/pip/http-v2/3/2/2/c/b/322cb2d2fa9c18feda7312c66e98b038ca0bb7446362e84c4a580aa3.body
ADDED
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Metadata-Version: 2.1
|
2 |
+
Name: tiktoken
|
3 |
+
Version: 0.7.0
|
4 |
+
Summary: tiktoken is a fast BPE tokeniser for use with OpenAI's models
|
5 |
+
Author: Shantanu Jain
|
6 |
+
Author-email: [email protected]
|
7 |
+
License: MIT License
|
8 |
+
|
9 |
+
Copyright (c) 2022 OpenAI, Shantanu Jain
|
10 |
+
|
11 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
12 |
+
of this software and associated documentation files (the "Software"), to deal
|
13 |
+
in the Software without restriction, including without limitation the rights
|
14 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
15 |
+
copies of the Software, and to permit persons to whom the Software is
|
16 |
+
furnished to do so, subject to the following conditions:
|
17 |
+
|
18 |
+
The above copyright notice and this permission notice shall be included in all
|
19 |
+
copies or substantial portions of the Software.
|
20 |
+
|
21 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
22 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
23 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
24 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
25 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
26 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
27 |
+
SOFTWARE.
|
28 |
+
|
29 |
+
Project-URL: homepage, https://github.com/openai/tiktoken
|
30 |
+
Project-URL: repository, https://github.com/openai/tiktoken
|
31 |
+
Project-URL: changelog, https://github.com/openai/tiktoken/blob/main/CHANGELOG.md
|
32 |
+
Requires-Python: >=3.8
|
33 |
+
Description-Content-Type: text/markdown
|
34 |
+
License-File: LICENSE
|
35 |
+
Requires-Dist: regex >=2022.1.18
|
36 |
+
Requires-Dist: requests >=2.26.0
|
37 |
+
Provides-Extra: blobfile
|
38 |
+
Requires-Dist: blobfile >=2 ; extra == 'blobfile'
|
39 |
+
|
40 |
+
# ⏳ tiktoken
|
41 |
+
|
42 |
+
tiktoken is a fast [BPE](https://en.wikipedia.org/wiki/Byte_pair_encoding) tokeniser for use with
|
43 |
+
OpenAI's models.
|
44 |
+
|
45 |
+
```python
|
46 |
+
import tiktoken
|
47 |
+
enc = tiktoken.get_encoding("cl100k_base")
|
48 |
+
assert enc.decode(enc.encode("hello world")) == "hello world"
|
49 |
+
|
50 |
+
# To get the tokeniser corresponding to a specific model in the OpenAI API:
|
51 |
+
enc = tiktoken.encoding_for_model("gpt-4")
|
52 |
+
```
|
53 |
+
|
54 |
+
The open source version of `tiktoken` can be installed from PyPI:
|
55 |
+
```
|
56 |
+
pip install tiktoken
|
57 |
+
```
|
58 |
+
|
59 |
+
The tokeniser API is documented in `tiktoken/core.py`.
|
60 |
+
|
61 |
+
Example code using `tiktoken` can be found in the
|
62 |
+
[OpenAI Cookbook](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb).
|
63 |
+
|
64 |
+
|
65 |
+
## Performance
|
66 |
+
|
67 |
+
`tiktoken` is between 3-6x faster than a comparable open source tokeniser:
|
68 |
+
|
69 |
+
![image](https://raw.githubusercontent.com/openai/tiktoken/main/perf.svg)
|
70 |
+
|
71 |
+
Performance measured on 1GB of text using the GPT-2 tokeniser, using `GPT2TokenizerFast` from
|
72 |
+
`tokenizers==0.13.2`, `transformers==4.24.0` and `tiktoken==0.2.0`.
|
73 |
+
|
74 |
+
|
75 |
+
## Getting help
|
76 |
+
|
77 |
+
Please post questions in the [issue tracker](https://github.com/openai/tiktoken/issues).
|
78 |
+
|
79 |
+
If you work at OpenAI, make sure to check the internal documentation or feel free to contact
|
80 |
+
@shantanu.
|
81 |
+
|
82 |
+
## What is BPE anyway?
|
83 |
+
|
84 |
+
Language models don't see text like you and I, instead they see a sequence of numbers (known as tokens).
|
85 |
+
Byte pair encoding (BPE) is a way of converting text into tokens. It has a couple desirable
|
86 |
+
properties:
|
87 |
+
1) It's reversible and lossless, so you can convert tokens back into the original text
|
88 |
+
2) It works on arbitrary text, even text that is not in the tokeniser's training data
|
89 |
+
3) It compresses the text: the token sequence is shorter than the bytes corresponding to the
|
90 |
+
original text. On average, in practice, each token corresponds to about 4 bytes.
|
91 |
+
4) It attempts to let the model see common subwords. For instance, "ing" is a common subword in
|
92 |
+
English, so BPE encodings will often split "encoding" into tokens like "encod" and "ing"
|
93 |
+
(instead of e.g. "enc" and "oding"). Because the model will then see the "ing" token again and
|
94 |
+
again in different contexts, it helps models generalise and better understand grammar.
|
95 |
+
|
96 |
+
`tiktoken` contains an educational submodule that is friendlier if you want to learn more about
|
97 |
+
the details of BPE, including code that helps visualise the BPE procedure:
|
98 |
+
```python
|
99 |
+
from tiktoken._educational import *
|
100 |
+
|
101 |
+
# Train a BPE tokeniser on a small amount of text
|
102 |
+
enc = train_simple_encoding()
|
103 |
+
|
104 |
+
# Visualise how the GPT-4 encoder encodes text
|
105 |
+
enc = SimpleBytePairEncoding.from_tiktoken("cl100k_base")
|
106 |
+
enc.encode("hello world aaaaaaaaaaaa")
|
107 |
+
```
|
108 |
+
|
109 |
+
|
110 |
+
## Extending tiktoken
|
111 |
+
|
112 |
+
You may wish to extend `tiktoken` to support new encodings. There are two ways to do this.
|
113 |
+
|
114 |
+
|
115 |
+
**Create your `Encoding` object exactly the way you want and simply pass it around.**
|
116 |
+
|
117 |
+
```python
|
118 |
+
cl100k_base = tiktoken.get_encoding("cl100k_base")
|
119 |
+
|
120 |
+
# In production, load the arguments directly instead of accessing private attributes
|
121 |
+
# See openai_public.py for examples of arguments for specific encodings
|
122 |
+
enc = tiktoken.Encoding(
|
123 |
+
# If you're changing the set of special tokens, make sure to use a different name
|
124 |
+
# It should be clear from the name what behaviour to expect.
|
125 |
+
name="cl100k_im",
|
126 |
+
pat_str=cl100k_base._pat_str,
|
127 |
+
mergeable_ranks=cl100k_base._mergeable_ranks,
|
128 |
+
special_tokens={
|
129 |
+
**cl100k_base._special_tokens,
|
130 |
+
"<|im_start|>": 100264,
|
131 |
+
"<|im_end|>": 100265,
|
132 |
+
}
|
133 |
+
)
|
134 |
+
```
|
135 |
+
|
136 |
+
**Use the `tiktoken_ext` plugin mechanism to register your `Encoding` objects with `tiktoken`.**
|
137 |
+
|
138 |
+
This is only useful if you need `tiktoken.get_encoding` to find your encoding, otherwise prefer
|
139 |
+
option 1.
|
140 |
+
|
141 |
+
To do this, you'll need to create a namespace package under `tiktoken_ext`.
|
142 |
+
|
143 |
+
Layout your project like this, making sure to omit the `tiktoken_ext/__init__.py` file:
|
144 |
+
```
|
145 |
+
my_tiktoken_extension
|
146 |
+
├── tiktoken_ext
|
147 |
+
│ └── my_encodings.py
|
148 |
+
└── setup.py
|
149 |
+
```
|
150 |
+
|
151 |
+
`my_encodings.py` should be a module that contains a variable named `ENCODING_CONSTRUCTORS`.
|
152 |
+
This is a dictionary from an encoding name to a function that takes no arguments and returns
|
153 |
+
arguments that can be passed to `tiktoken.Encoding` to construct that encoding. For an example, see
|
154 |
+
`tiktoken_ext/openai_public.py`. For precise details, see `tiktoken/registry.py`.
|
155 |
+
|
156 |
+
Your `setup.py` should look something like this:
|
157 |
+
```python
|
158 |
+
from setuptools import setup, find_namespace_packages
|
159 |
+
|
160 |
+
setup(
|
161 |
+
name="my_tiktoken_extension",
|
162 |
+
packages=find_namespace_packages(include=['tiktoken_ext*']),
|
163 |
+
install_requires=["tiktoken"],
|
164 |
+
...
|
165 |
+
)
|
166 |
+
```
|
167 |
+
|
168 |
+
Then simply `pip install ./my_tiktoken_extension` and you should be able to use your
|
169 |
+
custom encodings! Make sure **not** to use an editable install.
|
.cache/pip/http-v2/3/3/a/d/7/33ad7fe31489f80e15fea42300adbfc4d75c0efc76d75cfab7d2e5b0.body
ADDED
Binary file (22.7 kB). View file
|
|
.cache/pip/http-v2/3/8/6/0/e/3860e4de9ae53c79d2fd61419e9049df314ccc8b640782c02c6e2e2d.body
ADDED
Binary file (40.7 kB). View file
|
|
.cache/pip/http-v2/6/0/1/a/a/601aa27698da49f5bed3bc91bb41d8245b8316b66bd86059ef3b929e
ADDED
Binary file (1.19 kB). View file
|
|
.cache/pip/http-v2/6/1/4/f/4/614f46c6d1c16fa5b0800dfd0497e41c5b320e16ee8c9d943d4dd341
ADDED
Binary file (1.81 kB). View file
|
|
.cache/pip/http-v2/6/1/6/7/8/61678d682a1ea716fb4acccebc1350da197d2251a96e4b9220061051.body
ADDED
Binary file (68.9 kB). View file
|
|
.cache/pip/http-v2/6/4/6/e/5/646e5ac002367fdec50dea7e9d47599302e4790e77000da2571c33e8.body
ADDED
Binary file (116 kB). View file
|
|
.cache/pip/http-v2/6/5/0/7/2/65072c35290c429df2e84cb69eba045284d50944561efa156675456a.body
ADDED
Binary file (5.89 kB). View file
|
|
.cache/pip/http-v2/6/6/b/a/b/66bab8cde451822060c031dc988659e1fe4348c71c2fbd112ca75eca
ADDED
Binary file (1.81 kB). View file
|
|
.cache/pip/http-v2/6/6/b/a/b/66bab8cde451822060c031dc988659e1fe4348c71c2fbd112ca75eca.body
ADDED
Binary file (7.74 kB). View file
|
|
.cache/pip/http-v2/6/6/e/c/7/66ec76a7b6ed4081044f5c7821af293b63c17bc2ac523ff93d5ca7d5.body
ADDED
Binary file (216 kB). View file
|
|
.cache/pip/http-v2/8/1/1/c/d/811cdc5b0df1a4862e5588ed7d10948f806b064e30962a3f3e310c26
ADDED
Binary file (1.2 kB). View file
|
|
.cache/pip/http-v2/8/1/1/c/d/811cdc5b0df1a4862e5588ed7d10948f806b064e30962a3f3e310c26.body
ADDED
@@ -0,0 +1,650 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Metadata-Version: 2.1
|
2 |
+
Name: pytz
|
3 |
+
Version: 2024.2
|
4 |
+
Summary: World timezone definitions, modern and historical
|
5 |
+
Home-page: http://pythonhosted.org/pytz
|
6 |
+
Author: Stuart Bishop
|
7 |
+
Author-email: [email protected]
|
8 |
+
Maintainer: Stuart Bishop
|
9 |
+
Maintainer-email: [email protected]
|
10 |
+
License: MIT
|
11 |
+
Download-URL: https://pypi.org/project/pytz/
|
12 |
+
Keywords: timezone,tzinfo,datetime,olson,time
|
13 |
+
Platform: Independent
|
14 |
+
Classifier: Development Status :: 6 - Mature
|
15 |
+
Classifier: Intended Audience :: Developers
|
16 |
+
Classifier: License :: OSI Approved :: MIT License
|
17 |
+
Classifier: Natural Language :: English
|
18 |
+
Classifier: Operating System :: OS Independent
|
19 |
+
Classifier: Programming Language :: Python
|
20 |
+
Classifier: Programming Language :: Python :: 2
|
21 |
+
Classifier: Programming Language :: Python :: 2.4
|
22 |
+
Classifier: Programming Language :: Python :: 2.5
|
23 |
+
Classifier: Programming Language :: Python :: 2.6
|
24 |
+
Classifier: Programming Language :: Python :: 2.7
|
25 |
+
Classifier: Programming Language :: Python :: 3
|
26 |
+
Classifier: Programming Language :: Python :: 3.1
|
27 |
+
Classifier: Programming Language :: Python :: 3.2
|
28 |
+
Classifier: Programming Language :: Python :: 3.3
|
29 |
+
Classifier: Programming Language :: Python :: 3.4
|
30 |
+
Classifier: Programming Language :: Python :: 3.5
|
31 |
+
Classifier: Programming Language :: Python :: 3.6
|
32 |
+
Classifier: Programming Language :: Python :: 3.7
|
33 |
+
Classifier: Programming Language :: Python :: 3.8
|
34 |
+
Classifier: Programming Language :: Python :: 3.9
|
35 |
+
Classifier: Programming Language :: Python :: 3.10
|
36 |
+
Classifier: Programming Language :: Python :: 3.11
|
37 |
+
Classifier: Programming Language :: Python :: 3.12
|
38 |
+
Classifier: Programming Language :: Python :: 3.13
|
39 |
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
40 |
+
License-File: LICENSE.txt
|
41 |
+
|
42 |
+
pytz - World Timezone Definitions for Python
|
43 |
+
============================================
|
44 |
+
|
45 |
+
:Author: Stuart Bishop <[email protected]>
|
46 |
+
|
47 |
+
Introduction
|
48 |
+
~~~~~~~~~~~~
|
49 |
+
|
50 |
+
pytz brings the Olson tz database into Python. This library allows
|
51 |
+
accurate and cross platform timezone calculations using Python 2.4
|
52 |
+
or higher. It also solves the issue of ambiguous times at the end
|
53 |
+
of daylight saving time, which you can read more about in the Python
|
54 |
+
Library Reference (``datetime.tzinfo``).
|
55 |
+
|
56 |
+
Almost all of the Olson timezones are supported.
|
57 |
+
|
58 |
+
.. note::
|
59 |
+
|
60 |
+
Projects using Python 3.9 or later should be using the support
|
61 |
+
now included as part of the standard library, and third party
|
62 |
+
packages work with it such as `tzdata <https://pypi.org/project/tzdata/>`_.
|
63 |
+
pytz offers no advantages beyond backwards compatibility with
|
64 |
+
code written for earlier versions of Python.
|
65 |
+
|
66 |
+
.. note::
|
67 |
+
|
68 |
+
This library differs from the documented Python API for
|
69 |
+
tzinfo implementations; if you want to create local wallclock
|
70 |
+
times you need to use the ``localize()`` method documented in this
|
71 |
+
document. In addition, if you perform date arithmetic on local
|
72 |
+
times that cross DST boundaries, the result may be in an incorrect
|
73 |
+
timezone (ie. subtract 1 minute from 2002-10-27 1:00 EST and you get
|
74 |
+
2002-10-27 0:59 EST instead of the correct 2002-10-27 1:59 EDT). A
|
75 |
+
``normalize()`` method is provided to correct this. Unfortunately these
|
76 |
+
issues cannot be resolved without modifying the Python datetime
|
77 |
+
implementation (see PEP-431).
|
78 |
+
|
79 |
+
|
80 |
+
Installation
|
81 |
+
~~~~~~~~~~~~
|
82 |
+
|
83 |
+
This package can either be installed using ``pip`` or from a tarball using the
|
84 |
+
standard Python distutils.
|
85 |
+
|
86 |
+
If you are installing using ``pip``, you don't need to download anything as the
|
87 |
+
latest version will be downloaded for you from PyPI::
|
88 |
+
|
89 |
+
pip install pytz
|
90 |
+
|
91 |
+
If you are installing from a tarball, run the following command as an
|
92 |
+
administrative user::
|
93 |
+
|
94 |
+
python setup.py install
|
95 |
+
|
96 |
+
|
97 |
+
pytz for Enterprise
|
98 |
+
~~~~~~~~~~~~~~~~~~~
|
99 |
+
|
100 |
+
Available as part of the Tidelift Subscription.
|
101 |
+
|
102 |
+
The maintainers of pytz and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. `Learn more. <https://tidelift.com/subscription/pkg/pypi-pytz?utm_source=pypi-pytz&utm_medium=referral&utm_campaign=enterprise&utm_term=repo>`_.
|
103 |
+
|
104 |
+
|
105 |
+
Example & Usage
|
106 |
+
~~~~~~~~~~~~~~~
|
107 |
+
|
108 |
+
Localized times and date arithmetic
|
109 |
+
-----------------------------------
|
110 |
+
|
111 |
+
>>> from datetime import datetime, timedelta
|
112 |
+
>>> from pytz import timezone
|
113 |
+
>>> import pytz
|
114 |
+
>>> utc = pytz.utc
|
115 |
+
>>> utc.zone
|
116 |
+
'UTC'
|
117 |
+
>>> eastern = timezone('US/Eastern')
|
118 |
+
>>> eastern.zone
|
119 |
+
'US/Eastern'
|
120 |
+
>>> amsterdam = timezone('Europe/Amsterdam')
|
121 |
+
>>> fmt = '%Y-%m-%d %H:%M:%S %Z%z'
|
122 |
+
|
123 |
+
This library only supports two ways of building a localized time. The
|
124 |
+
first is to use the ``localize()`` method provided by the pytz library.
|
125 |
+
This is used to localize a naive datetime (datetime with no timezone
|
126 |
+
information):
|
127 |
+
|
128 |
+
>>> loc_dt = eastern.localize(datetime(2002, 10, 27, 6, 0, 0))
|
129 |
+
>>> print(loc_dt.strftime(fmt))
|
130 |
+
2002-10-27 06:00:00 EST-0500
|
131 |
+
|
132 |
+
The second way of building a localized time is by converting an existing
|
133 |
+
localized time using the standard ``astimezone()`` method:
|
134 |
+
|
135 |
+
>>> ams_dt = loc_dt.astimezone(amsterdam)
|
136 |
+
>>> ams_dt.strftime(fmt)
|
137 |
+
'2002-10-27 12:00:00 CET+0100'
|
138 |
+
|
139 |
+
Unfortunately using the tzinfo argument of the standard datetime
|
140 |
+
constructors ''does not work'' with pytz for many timezones.
|
141 |
+
|
142 |
+
>>> datetime(2002, 10, 27, 12, 0, 0, tzinfo=amsterdam).strftime(fmt) # /!\ Does not work this way!
|
143 |
+
'2002-10-27 12:00:00 LMT+0018'
|
144 |
+
|
145 |
+
It is safe for timezones without daylight saving transitions though, such
|
146 |
+
as UTC:
|
147 |
+
|
148 |
+
>>> datetime(2002, 10, 27, 12, 0, 0, tzinfo=pytz.utc).strftime(fmt) # /!\ Not recommended except for UTC
|
149 |
+
'2002-10-27 12:00:00 UTC+0000'
|
150 |
+
|
151 |
+
The preferred way of dealing with times is to always work in UTC,
|
152 |
+
converting to localtime only when generating output to be read
|
153 |
+
by humans.
|
154 |
+
|
155 |
+
>>> utc_dt = datetime(2002, 10, 27, 6, 0, 0, tzinfo=utc)
|
156 |
+
>>> loc_dt = utc_dt.astimezone(eastern)
|
157 |
+
>>> loc_dt.strftime(fmt)
|
158 |
+
'2002-10-27 01:00:00 EST-0500'
|
159 |
+
|
160 |
+
This library also allows you to do date arithmetic using local
|
161 |
+
times, although it is more complicated than working in UTC as you
|
162 |
+
need to use the ``normalize()`` method to handle daylight saving time
|
163 |
+
and other timezone transitions. In this example, ``loc_dt`` is set
|
164 |
+
to the instant when daylight saving time ends in the US/Eastern
|
165 |
+
timezone.
|
166 |
+
|
167 |
+
>>> before = loc_dt - timedelta(minutes=10)
|
168 |
+
>>> before.strftime(fmt)
|
169 |
+
'2002-10-27 00:50:00 EST-0500'
|
170 |
+
>>> eastern.normalize(before).strftime(fmt)
|
171 |
+
'2002-10-27 01:50:00 EDT-0400'
|
172 |
+
>>> after = eastern.normalize(before + timedelta(minutes=20))
|
173 |
+
>>> after.strftime(fmt)
|
174 |
+
'2002-10-27 01:10:00 EST-0500'
|
175 |
+
|
176 |
+
Creating local times is also tricky, and the reason why working with
|
177 |
+
local times is not recommended. Unfortunately, you cannot just pass
|
178 |
+
a ``tzinfo`` argument when constructing a datetime (see the next
|
179 |
+
section for more details)
|
180 |
+
|
181 |
+
>>> dt = datetime(2002, 10, 27, 1, 30, 0)
|
182 |
+
>>> dt1 = eastern.localize(dt, is_dst=True)
|
183 |
+
>>> dt1.strftime(fmt)
|
184 |
+
'2002-10-27 01:30:00 EDT-0400'
|
185 |
+
>>> dt2 = eastern.localize(dt, is_dst=False)
|
186 |
+
>>> dt2.strftime(fmt)
|
187 |
+
'2002-10-27 01:30:00 EST-0500'
|
188 |
+
|
189 |
+
Converting between timezones is more easily done, using the
|
190 |
+
standard astimezone method.
|
191 |
+
|
192 |
+
>>> utc_dt = datetime.fromtimestamp(1143408899, tz=utc)
|
193 |
+
>>> utc_dt.strftime(fmt)
|
194 |
+
'2006-03-26 21:34:59 UTC+0000'
|
195 |
+
>>> au_tz = timezone('Australia/Sydney')
|
196 |
+
>>> au_dt = utc_dt.astimezone(au_tz)
|
197 |
+
>>> au_dt.strftime(fmt)
|
198 |
+
'2006-03-27 08:34:59 AEDT+1100'
|
199 |
+
>>> utc_dt2 = au_dt.astimezone(utc)
|
200 |
+
>>> utc_dt2.strftime(fmt)
|
201 |
+
'2006-03-26 21:34:59 UTC+0000'
|
202 |
+
>>> utc_dt == utc_dt2
|
203 |
+
True
|
204 |
+
|
205 |
+
You can take shortcuts when dealing with the UTC side of timezone
|
206 |
+
conversions. ``normalize()`` and ``localize()`` are not really
|
207 |
+
necessary when there are no daylight saving time transitions to
|
208 |
+
deal with.
|
209 |
+
|
210 |
+
>>> utc_dt = datetime.fromtimestamp(1143408899, tz=utc)
|
211 |
+
>>> utc_dt.strftime(fmt)
|
212 |
+
'2006-03-26 21:34:59 UTC+0000'
|
213 |
+
>>> au_tz = timezone('Australia/Sydney')
|
214 |
+
>>> au_dt = au_tz.normalize(utc_dt.astimezone(au_tz))
|
215 |
+
>>> au_dt.strftime(fmt)
|
216 |
+
'2006-03-27 08:34:59 AEDT+1100'
|
217 |
+
>>> utc_dt2 = au_dt.astimezone(utc)
|
218 |
+
>>> utc_dt2.strftime(fmt)
|
219 |
+
'2006-03-26 21:34:59 UTC+0000'
|
220 |
+
|
221 |
+
|
222 |
+
``tzinfo`` API
|
223 |
+
--------------
|
224 |
+
|
225 |
+
The ``tzinfo`` instances returned by the ``timezone()`` function have
|
226 |
+
been extended to cope with ambiguous times by adding an ``is_dst``
|
227 |
+
parameter to the ``utcoffset()``, ``dst()`` && ``tzname()`` methods.
|
228 |
+
|
229 |
+
>>> tz = timezone('America/St_Johns')
|
230 |
+
|
231 |
+
>>> normal = datetime(2009, 9, 1)
|
232 |
+
>>> ambiguous = datetime(2009, 10, 31, 23, 30)
|
233 |
+
|
234 |
+
The ``is_dst`` parameter is ignored for most timestamps. It is only used
|
235 |
+
during DST transition ambiguous periods to resolve that ambiguity.
|
236 |
+
|
237 |
+
>>> print(tz.utcoffset(normal, is_dst=True))
|
238 |
+
-1 day, 21:30:00
|
239 |
+
>>> print(tz.dst(normal, is_dst=True))
|
240 |
+
1:00:00
|
241 |
+
>>> tz.tzname(normal, is_dst=True)
|
242 |
+
'NDT'
|
243 |
+
|
244 |
+
>>> print(tz.utcoffset(ambiguous, is_dst=True))
|
245 |
+
-1 day, 21:30:00
|
246 |
+
>>> print(tz.dst(ambiguous, is_dst=True))
|
247 |
+
1:00:00
|
248 |
+
>>> tz.tzname(ambiguous, is_dst=True)
|
249 |
+
'NDT'
|
250 |
+
|
251 |
+
>>> print(tz.utcoffset(normal, is_dst=False))
|
252 |
+
-1 day, 21:30:00
|
253 |
+
>>> tz.dst(normal, is_dst=False).seconds
|
254 |
+
3600
|
255 |
+
>>> tz.tzname(normal, is_dst=False)
|
256 |
+
'NDT'
|
257 |
+
|
258 |
+
>>> print(tz.utcoffset(ambiguous, is_dst=False))
|
259 |
+
-1 day, 20:30:00
|
260 |
+
>>> tz.dst(ambiguous, is_dst=False)
|
261 |
+
datetime.timedelta(0)
|
262 |
+
>>> tz.tzname(ambiguous, is_dst=False)
|
263 |
+
'NST'
|
264 |
+
|
265 |
+
If ``is_dst`` is not specified, ambiguous timestamps will raise
|
266 |
+
an ``pytz.exceptions.AmbiguousTimeError`` exception.
|
267 |
+
|
268 |
+
>>> print(tz.utcoffset(normal))
|
269 |
+
-1 day, 21:30:00
|
270 |
+
>>> print(tz.dst(normal))
|
271 |
+
1:00:00
|
272 |
+
>>> tz.tzname(normal)
|
273 |
+
'NDT'
|
274 |
+
|
275 |
+
>>> import pytz.exceptions
|
276 |
+
>>> try:
|
277 |
+
... tz.utcoffset(ambiguous)
|
278 |
+
... except pytz.exceptions.AmbiguousTimeError:
|
279 |
+
... print('pytz.exceptions.AmbiguousTimeError: %s' % ambiguous)
|
280 |
+
pytz.exceptions.AmbiguousTimeError: 2009-10-31 23:30:00
|
281 |
+
>>> try:
|
282 |
+
... tz.dst(ambiguous)
|
283 |
+
... except pytz.exceptions.AmbiguousTimeError:
|
284 |
+
... print('pytz.exceptions.AmbiguousTimeError: %s' % ambiguous)
|
285 |
+
pytz.exceptions.AmbiguousTimeError: 2009-10-31 23:30:00
|
286 |
+
>>> try:
|
287 |
+
... tz.tzname(ambiguous)
|
288 |
+
... except pytz.exceptions.AmbiguousTimeError:
|
289 |
+
... print('pytz.exceptions.AmbiguousTimeError: %s' % ambiguous)
|
290 |
+
pytz.exceptions.AmbiguousTimeError: 2009-10-31 23:30:00
|
291 |
+
|
292 |
+
|
293 |
+
Problems with Localtime
|
294 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
295 |
+
|
296 |
+
The major problem we have to deal with is that certain datetimes
|
297 |
+
may occur twice in a year. For example, in the US/Eastern timezone
|
298 |
+
on the last Sunday morning in October, the following sequence
|
299 |
+
happens:
|
300 |
+
|
301 |
+
- 01:00 EDT occurs
|
302 |
+
- 1 hour later, instead of 2:00am the clock is turned back 1 hour
|
303 |
+
and 01:00 happens again (this time 01:00 EST)
|
304 |
+
|
305 |
+
In fact, every instant between 01:00 and 02:00 occurs twice. This means
|
306 |
+
that if you try and create a time in the 'US/Eastern' timezone
|
307 |
+
the standard datetime syntax, there is no way to specify if you meant
|
308 |
+
before of after the end-of-daylight-saving-time transition. Using the
|
309 |
+
pytz custom syntax, the best you can do is make an educated guess:
|
310 |
+
|
311 |
+
>>> loc_dt = eastern.localize(datetime(2002, 10, 27, 1, 30, 00))
|
312 |
+
>>> loc_dt.strftime(fmt)
|
313 |
+
'2002-10-27 01:30:00 EST-0500'
|
314 |
+
|
315 |
+
As you can see, the system has chosen one for you and there is a 50%
|
316 |
+
chance of it being out by one hour. For some applications, this does
|
317 |
+
not matter. However, if you are trying to schedule meetings with people
|
318 |
+
in different timezones or analyze log files it is not acceptable.
|
319 |
+
|
320 |
+
The best and simplest solution is to stick with using UTC. The pytz
|
321 |
+
package encourages using UTC for internal timezone representation by
|
322 |
+
including a special UTC implementation based on the standard Python
|
323 |
+
reference implementation in the Python documentation.
|
324 |
+
|
325 |
+
The UTC timezone unpickles to be the same instance, and pickles to a
|
326 |
+
smaller size than other pytz tzinfo instances. The UTC implementation
|
327 |
+
can be obtained as pytz.utc, pytz.UTC, or pytz.timezone('UTC').
|
328 |
+
|
329 |
+
>>> import pickle, pytz
|
330 |
+
>>> dt = datetime(2005, 3, 1, 14, 13, 21, tzinfo=utc)
|
331 |
+
>>> naive = dt.replace(tzinfo=None)
|
332 |
+
>>> p = pickle.dumps(dt, 1)
|
333 |
+
>>> naive_p = pickle.dumps(naive, 1)
|
334 |
+
>>> len(p) - len(naive_p)
|
335 |
+
17
|
336 |
+
>>> new = pickle.loads(p)
|
337 |
+
>>> new == dt
|
338 |
+
True
|
339 |
+
>>> new is dt
|
340 |
+
False
|
341 |
+
>>> new.tzinfo is dt.tzinfo
|
342 |
+
True
|
343 |
+
>>> pytz.utc is pytz.UTC is pytz.timezone('UTC')
|
344 |
+
True
|
345 |
+
|
346 |
+
Note that some other timezones are commonly thought of as the same (GMT,
|
347 |
+
Greenwich, Universal, etc.). The definition of UTC is distinct from these
|
348 |
+
other timezones, and they are not equivalent. For this reason, they will
|
349 |
+
not compare the same in Python.
|
350 |
+
|
351 |
+
>>> utc == pytz.timezone('GMT')
|
352 |
+
False
|
353 |
+
|
354 |
+
See the section `What is UTC`_, below.
|
355 |
+
|
356 |
+
If you insist on working with local times, this library provides a
|
357 |
+
facility for constructing them unambiguously:
|
358 |
+
|
359 |
+
>>> loc_dt = datetime(2002, 10, 27, 1, 30, 00)
|
360 |
+
>>> est_dt = eastern.localize(loc_dt, is_dst=True)
|
361 |
+
>>> edt_dt = eastern.localize(loc_dt, is_dst=False)
|
362 |
+
>>> print(est_dt.strftime(fmt) + ' / ' + edt_dt.strftime(fmt))
|
363 |
+
2002-10-27 01:30:00 EDT-0400 / 2002-10-27 01:30:00 EST-0500
|
364 |
+
|
365 |
+
If you pass None as the is_dst flag to localize(), pytz will refuse to
|
366 |
+
guess and raise exceptions if you try to build ambiguous or non-existent
|
367 |
+
times.
|
368 |
+
|
369 |
+
For example, 1:30am on 27th Oct 2002 happened twice in the US/Eastern
|
370 |
+
timezone when the clocks where put back at the end of Daylight Saving
|
371 |
+
Time:
|
372 |
+
|
373 |
+
>>> dt = datetime(2002, 10, 27, 1, 30, 00)
|
374 |
+
>>> try:
|
375 |
+
... eastern.localize(dt, is_dst=None)
|
376 |
+
... except pytz.exceptions.AmbiguousTimeError:
|
377 |
+
... print('pytz.exceptions.AmbiguousTimeError: %s' % dt)
|
378 |
+
pytz.exceptions.AmbiguousTimeError: 2002-10-27 01:30:00
|
379 |
+
|
380 |
+
Similarly, 2:30am on 7th April 2002 never happened at all in the
|
381 |
+
US/Eastern timezone, as the clocks where put forward at 2:00am skipping
|
382 |
+
the entire hour:
|
383 |
+
|
384 |
+
>>> dt = datetime(2002, 4, 7, 2, 30, 00)
|
385 |
+
>>> try:
|
386 |
+
... eastern.localize(dt, is_dst=None)
|
387 |
+
... except pytz.exceptions.NonExistentTimeError:
|
388 |
+
... print('pytz.exceptions.NonExistentTimeError: %s' % dt)
|
389 |
+
pytz.exceptions.NonExistentTimeError: 2002-04-07 02:30:00
|
390 |
+
|
391 |
+
Both of these exceptions share a common base class to make error handling
|
392 |
+
easier:
|
393 |
+
|
394 |
+
>>> isinstance(pytz.AmbiguousTimeError(), pytz.InvalidTimeError)
|
395 |
+
True
|
396 |
+
>>> isinstance(pytz.NonExistentTimeError(), pytz.InvalidTimeError)
|
397 |
+
True
|
398 |
+
|
399 |
+
|
400 |
+
A special case is where countries change their timezone definitions
|
401 |
+
with no daylight savings time switch. For example, in 1915 Warsaw
|
402 |
+
switched from Warsaw time to Central European time with no daylight savings
|
403 |
+
transition. So at the stroke of midnight on August 5th 1915 the clocks
|
404 |
+
were wound back 24 minutes creating an ambiguous time period that cannot
|
405 |
+
be specified without referring to the timezone abbreviation or the
|
406 |
+
actual UTC offset. In this case midnight happened twice, neither time
|
407 |
+
during a daylight saving time period. pytz handles this transition by
|
408 |
+
treating the ambiguous period before the switch as daylight savings
|
409 |
+
time, and the ambiguous period after as standard time.
|
410 |
+
|
411 |
+
|
412 |
+
>>> warsaw = pytz.timezone('Europe/Warsaw')
|
413 |
+
>>> amb_dt1 = warsaw.localize(datetime(1915, 8, 4, 23, 59, 59), is_dst=True)
|
414 |
+
>>> amb_dt1.strftime(fmt)
|
415 |
+
'1915-08-04 23:59:59 WMT+0124'
|
416 |
+
>>> amb_dt2 = warsaw.localize(datetime(1915, 8, 4, 23, 59, 59), is_dst=False)
|
417 |
+
>>> amb_dt2.strftime(fmt)
|
418 |
+
'1915-08-04 23:59:59 CET+0100'
|
419 |
+
>>> switch_dt = warsaw.localize(datetime(1915, 8, 5, 00, 00, 00), is_dst=False)
|
420 |
+
>>> switch_dt.strftime(fmt)
|
421 |
+
'1915-08-05 00:00:00 CET+0100'
|
422 |
+
>>> str(switch_dt - amb_dt1)
|
423 |
+
'0:24:01'
|
424 |
+
>>> str(switch_dt - amb_dt2)
|
425 |
+
'0:00:01'
|
426 |
+
|
427 |
+
The best way of creating a time during an ambiguous time period is
|
428 |
+
by converting from another timezone such as UTC:
|
429 |
+
|
430 |
+
>>> utc_dt = datetime(1915, 8, 4, 22, 36, tzinfo=pytz.utc)
|
431 |
+
>>> utc_dt.astimezone(warsaw).strftime(fmt)
|
432 |
+
'1915-08-04 23:36:00 CET+0100'
|
433 |
+
|
434 |
+
The standard Python way of handling all these ambiguities is not to
|
435 |
+
handle them, such as demonstrated in this example using the US/Eastern
|
436 |
+
timezone definition from the Python documentation (Note that this
|
437 |
+
implementation only works for dates between 1987 and 2006 - it is
|
438 |
+
included for tests only!):
|
439 |
+
|
440 |
+
>>> from pytz.reference import Eastern # pytz.reference only for tests
|
441 |
+
>>> dt = datetime(2002, 10, 27, 0, 30, tzinfo=Eastern)
|
442 |
+
>>> str(dt)
|
443 |
+
'2002-10-27 00:30:00-04:00'
|
444 |
+
>>> str(dt + timedelta(hours=1))
|
445 |
+
'2002-10-27 01:30:00-05:00'
|
446 |
+
>>> str(dt + timedelta(hours=2))
|
447 |
+
'2002-10-27 02:30:00-05:00'
|
448 |
+
>>> str(dt + timedelta(hours=3))
|
449 |
+
'2002-10-27 03:30:00-05:00'
|
450 |
+
|
451 |
+
Notice the first two results? At first glance you might think they are
|
452 |
+
correct, but taking the UTC offset into account you find that they are
|
453 |
+
actually two hours appart instead of the 1 hour we asked for.
|
454 |
+
|
455 |
+
>>> from pytz.reference import UTC # pytz.reference only for tests
|
456 |
+
>>> str(dt.astimezone(UTC))
|
457 |
+
'2002-10-27 04:30:00+00:00'
|
458 |
+
>>> str((dt + timedelta(hours=1)).astimezone(UTC))
|
459 |
+
'2002-10-27 06:30:00+00:00'
|
460 |
+
|
461 |
+
|
462 |
+
Country Information
|
463 |
+
~~~~~~~~~~~~~~~~~~~
|
464 |
+
|
465 |
+
A mechanism is provided to access the timezones commonly in use
|
466 |
+
for a particular country, looked up using the ISO 3166 country code.
|
467 |
+
It returns a list of strings that can be used to retrieve the relevant
|
468 |
+
tzinfo instance using ``pytz.timezone()``:
|
469 |
+
|
470 |
+
>>> print(' '.join(pytz.country_timezones['nz']))
|
471 |
+
Pacific/Auckland Pacific/Chatham
|
472 |
+
|
473 |
+
The Olson database comes with a ISO 3166 country code to English country
|
474 |
+
name mapping that pytz exposes as a dictionary:
|
475 |
+
|
476 |
+
>>> print(pytz.country_names['nz'])
|
477 |
+
New Zealand
|
478 |
+
|
479 |
+
|
480 |
+
What is UTC
|
481 |
+
~~~~~~~~~~~
|
482 |
+
|
483 |
+
'UTC' is `Coordinated Universal Time`_. It is a successor to, but distinct
|
484 |
+
from, Greenwich Mean Time (GMT) and the various definitions of Universal
|
485 |
+
Time. UTC is now the worldwide standard for regulating clocks and time
|
486 |
+
measurement.
|
487 |
+
|
488 |
+
All other timezones are defined relative to UTC, and include offsets like
|
489 |
+
UTC+0800 - hours to add or subtract from UTC to derive the local time. No
|
490 |
+
daylight saving time occurs in UTC, making it a useful timezone to perform
|
491 |
+
date arithmetic without worrying about the confusion and ambiguities caused
|
492 |
+
by daylight saving time transitions, your country changing its timezone, or
|
493 |
+
mobile computers that roam through multiple timezones.
|
494 |
+
|
495 |
+
.. _Coordinated Universal Time: https://en.wikipedia.org/wiki/Coordinated_Universal_Time
|
496 |
+
|
497 |
+
|
498 |
+
Helpers
|
499 |
+
~~~~~~~
|
500 |
+
|
501 |
+
There are two lists of timezones provided.
|
502 |
+
|
503 |
+
``all_timezones`` is the exhaustive list of the timezone names that can
|
504 |
+
be used.
|
505 |
+
|
506 |
+
>>> from pytz import all_timezones
|
507 |
+
>>> len(all_timezones) >= 500
|
508 |
+
True
|
509 |
+
>>> 'Etc/Greenwich' in all_timezones
|
510 |
+
True
|
511 |
+
|
512 |
+
``common_timezones`` is a list of useful, current timezones. It doesn't
|
513 |
+
contain deprecated zones or historical zones, except for a few I've
|
514 |
+
deemed in common usage, such as US/Eastern (open a bug report if you
|
515 |
+
think other timezones are deserving of being included here). It is also
|
516 |
+
a sequence of strings.
|
517 |
+
|
518 |
+
>>> from pytz import common_timezones
|
519 |
+
>>> len(common_timezones) < len(all_timezones)
|
520 |
+
True
|
521 |
+
>>> 'Etc/Greenwich' in common_timezones
|
522 |
+
False
|
523 |
+
>>> 'Australia/Melbourne' in common_timezones
|
524 |
+
True
|
525 |
+
>>> 'US/Eastern' in common_timezones
|
526 |
+
True
|
527 |
+
>>> 'Canada/Eastern' in common_timezones
|
528 |
+
True
|
529 |
+
>>> 'Australia/Yancowinna' in all_timezones
|
530 |
+
True
|
531 |
+
>>> 'Australia/Yancowinna' in common_timezones
|
532 |
+
False
|
533 |
+
|
534 |
+
Both ``common_timezones`` and ``all_timezones`` are alphabetically
|
535 |
+
sorted:
|
536 |
+
|
537 |
+
>>> common_timezones_dupe = common_timezones[:]
|
538 |
+
>>> common_timezones_dupe.sort()
|
539 |
+
>>> common_timezones == common_timezones_dupe
|
540 |
+
True
|
541 |
+
>>> all_timezones_dupe = all_timezones[:]
|
542 |
+
>>> all_timezones_dupe.sort()
|
543 |
+
>>> all_timezones == all_timezones_dupe
|
544 |
+
True
|
545 |
+
|
546 |
+
``all_timezones`` and ``common_timezones`` are also available as sets.
|
547 |
+
|
548 |
+
>>> from pytz import all_timezones_set, common_timezones_set
|
549 |
+
>>> 'US/Eastern' in all_timezones_set
|
550 |
+
True
|
551 |
+
>>> 'US/Eastern' in common_timezones_set
|
552 |
+
True
|
553 |
+
>>> 'Australia/Victoria' in common_timezones_set
|
554 |
+
False
|
555 |
+
|
556 |
+
You can also retrieve lists of timezones used by particular countries
|
557 |
+
using the ``country_timezones()`` function. It requires an ISO-3166
|
558 |
+
two letter country code.
|
559 |
+
|
560 |
+
>>> from pytz import country_timezones
|
561 |
+
>>> print(' '.join(country_timezones('ch')))
|
562 |
+
Europe/Zurich
|
563 |
+
>>> print(' '.join(country_timezones('CH')))
|
564 |
+
Europe/Zurich
|
565 |
+
|
566 |
+
|
567 |
+
Internationalization - i18n/l10n
|
568 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
569 |
+
|
570 |
+
Pytz is an interface to the IANA database, which uses ASCII names. The `Unicode Consortium's Unicode Locales (CLDR) <http://cldr.unicode.org>`_
|
571 |
+
project provides translations. Python packages such as
|
572 |
+
`Babel <https://babel.pocoo.org/en/latest/api/dates.html#timezone-functionality>`_
|
573 |
+
and Thomas Khyn's `l18n <https://pypi.org/project/l18n/>`_ package can be used
|
574 |
+
to access these translations from Python.
|
575 |
+
|
576 |
+
|
577 |
+
License
|
578 |
+
~~~~~~~
|
579 |
+
|
580 |
+
MIT license.
|
581 |
+
|
582 |
+
This code is also available as part of Zope 3 under the Zope Public
|
583 |
+
License, Version 2.1 (ZPL).
|
584 |
+
|
585 |
+
I'm happy to relicense this code if necessary for inclusion in other
|
586 |
+
open source projects.
|
587 |
+
|
588 |
+
|
589 |
+
Latest Versions
|
590 |
+
~~~~~~~~~~~~~~~
|
591 |
+
|
592 |
+
This package will be updated after releases of the Olson timezone
|
593 |
+
database. The latest version can be downloaded from the `Python Package
|
594 |
+
Index <https://pypi.org/project/pytz/>`_. The code that is used
|
595 |
+
to generate this distribution is hosted on Github and available
|
596 |
+
using git::
|
597 |
+
|
598 |
+
git clone https://github.com/stub42/pytz.git
|
599 |
+
|
600 |
+
Announcements of new releases are made on
|
601 |
+
`Launchpad <https://launchpad.net/pytz>`_, and the
|
602 |
+
`Atom feed <http://feeds.launchpad.net/pytz/announcements.atom>`_
|
603 |
+
hosted there.
|
604 |
+
|
605 |
+
|
606 |
+
Bugs, Feature Requests & Patches
|
607 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
608 |
+
|
609 |
+
Bugs should be reported on `Github <https://github.com/stub42/pytz/issues>`_.
|
610 |
+
Feature requests are unlikely to be considered, and efforts instead directed
|
611 |
+
to timezone support now built into Python or packages that work with it.
|
612 |
+
|
613 |
+
|
614 |
+
Security Issues
|
615 |
+
~~~~~~~~~~~~~~~
|
616 |
+
|
617 |
+
Reports about security issues can be made via `Tidelift <https://tidelift.com/security>`_.
|
618 |
+
|
619 |
+
|
620 |
+
Issues & Limitations
|
621 |
+
~~~~~~~~~~~~~~~~~~~~
|
622 |
+
|
623 |
+
- This project is in maintenance mode. Projects using Python 3.9 or later
|
624 |
+
are best served by using the timezone functionaly now included in core
|
625 |
+
Python and packages that work with it such as `tzdata <https://pypi.org/project/tzdata/>`_.
|
626 |
+
|
627 |
+
- Offsets from UTC are rounded to the nearest whole minute, so timezones
|
628 |
+
such as Europe/Amsterdam pre 1937 will be up to 30 seconds out. This
|
629 |
+
was a limitation of the Python datetime library.
|
630 |
+
|
631 |
+
- If you think a timezone definition is incorrect, I probably can't fix
|
632 |
+
it. pytz is a direct translation of the Olson timezone database, and
|
633 |
+
changes to the timezone definitions need to be made to this source.
|
634 |
+
If you find errors they should be reported to the time zone mailing
|
635 |
+
list, linked from http://www.iana.org/time-zones.
|
636 |
+
|
637 |
+
|
638 |
+
Further Reading
|
639 |
+
~~~~~~~~~~~~~~~
|
640 |
+
|
641 |
+
More info than you want to know about timezones:
|
642 |
+
https://data.iana.org/time-zones/tz-link.html
|
643 |
+
|
644 |
+
|
645 |
+
Contact
|
646 |
+
~~~~~~~
|
647 |
+
|
648 |
+
Stuart Bishop <[email protected]>
|
649 |
+
|
650 |
+
|
.cache/pip/http-v2/8/1/3/c/c/813cc7096c25ba43edba14a4ab40832db33af638c43e975795995aec
ADDED
Binary file (1.81 kB). View file
|
|
.cache/pip/http-v2/8/7/3/3/b/8733b40e52a573d98e55534434c69a8765ca0cd71166704a3188ddb3
ADDED
Binary file (1.2 kB). View file
|
|
.cache/pip/http-v2/8/7/9/e/a/879eab407895dd6690258943fd9ec2bee9d83a6d395dfe3e4bf6ce4f
ADDED
Binary file (1.16 kB). View file
|
|
.cache/pip/http-v2/8/7/9/e/a/879eab407895dd6690258943fd9ec2bee9d83a6d395dfe3e4bf6ce4f.body
ADDED
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Metadata-Version: 2.1
|
2 |
+
Name: wandb
|
3 |
+
Version: 0.18.1
|
4 |
+
Summary: A CLI and library for interacting with the Weights & Biases API.
|
5 |
+
Project-URL: Source, https://github.com/wandb/wandb
|
6 |
+
Project-URL: Bug Reports, https://github.com/wandb/wandb/issues
|
7 |
+
Project-URL: Documentation, https://docs.wandb.ai/
|
8 |
+
Author-email: Weights & Biases <[email protected]>
|
9 |
+
License: MIT License
|
10 |
+
|
11 |
+
Copyright (c) 2021 Weights and Biases, Inc.
|
12 |
+
|
13 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
14 |
+
of this software and associated documentation files (the "Software"), to deal
|
15 |
+
in the Software without restriction, including without limitation the rights
|
16 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
17 |
+
copies of the Software, and to permit persons to whom the Software is
|
18 |
+
furnished to do so, subject to the following conditions:
|
19 |
+
|
20 |
+
The above copyright notice and this permission notice shall be included in all
|
21 |
+
copies or substantial portions of the Software.
|
22 |
+
|
23 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
24 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
25 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
26 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
27 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
28 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
29 |
+
SOFTWARE.
|
30 |
+
License-File: LICENSE
|
31 |
+
Classifier: Development Status :: 5 - Production/Stable
|
32 |
+
Classifier: Intended Audience :: Developers
|
33 |
+
Classifier: Intended Audience :: Science/Research
|
34 |
+
Classifier: License :: OSI Approved :: MIT License
|
35 |
+
Classifier: Natural Language :: English
|
36 |
+
Classifier: Programming Language :: Python :: 3
|
37 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
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: Topic :: Scientific/Engineering :: Artificial Intelligence
|
45 |
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
46 |
+
Classifier: Topic :: System :: Logging
|
47 |
+
Classifier: Topic :: System :: Monitoring
|
48 |
+
Requires-Python: >=3.7
|
49 |
+
Requires-Dist: click!=8.0.0,>=7.1
|
50 |
+
Requires-Dist: docker-pycreds>=0.4.0
|
51 |
+
Requires-Dist: gitpython!=3.1.29,>=1.0.0
|
52 |
+
Requires-Dist: platformdirs
|
53 |
+
Requires-Dist: protobuf!=4.21.0,!=5.28.0,<6,>=3.12.0; python_version < '3.9' and sys_platform == 'linux'
|
54 |
+
Requires-Dist: protobuf!=4.21.0,!=5.28.0,<6,>=3.15.0; python_version == '3.9' and sys_platform == 'linux'
|
55 |
+
Requires-Dist: protobuf!=4.21.0,!=5.28.0,<6,>=3.19.0; python_version > '3.9' and sys_platform == 'linux'
|
56 |
+
Requires-Dist: protobuf!=4.21.0,!=5.28.0,<6,>=3.19.0; sys_platform != 'linux'
|
57 |
+
Requires-Dist: psutil>=5.0.0
|
58 |
+
Requires-Dist: pyyaml
|
59 |
+
Requires-Dist: requests<3,>=2.0.0
|
60 |
+
Requires-Dist: sentry-sdk>=1.0.0
|
61 |
+
Requires-Dist: setproctitle
|
62 |
+
Requires-Dist: setuptools
|
63 |
+
Requires-Dist: typing-extensions; python_version < '3.10'
|
64 |
+
Provides-Extra: aws
|
65 |
+
Requires-Dist: boto3; extra == 'aws'
|
66 |
+
Provides-Extra: azure
|
67 |
+
Requires-Dist: azure-identity; extra == 'azure'
|
68 |
+
Requires-Dist: azure-storage-blob; extra == 'azure'
|
69 |
+
Provides-Extra: gcp
|
70 |
+
Requires-Dist: google-cloud-storage; extra == 'gcp'
|
71 |
+
Provides-Extra: importers
|
72 |
+
Requires-Dist: filelock; extra == 'importers'
|
73 |
+
Requires-Dist: mlflow; extra == 'importers'
|
74 |
+
Requires-Dist: polars<=1.2.1; extra == 'importers'
|
75 |
+
Requires-Dist: rich; extra == 'importers'
|
76 |
+
Requires-Dist: tenacity; extra == 'importers'
|
77 |
+
Provides-Extra: kubeflow
|
78 |
+
Requires-Dist: google-cloud-storage; extra == 'kubeflow'
|
79 |
+
Requires-Dist: kubernetes; extra == 'kubeflow'
|
80 |
+
Requires-Dist: minio; extra == 'kubeflow'
|
81 |
+
Requires-Dist: sh; extra == 'kubeflow'
|
82 |
+
Provides-Extra: launch
|
83 |
+
Requires-Dist: awscli; extra == 'launch'
|
84 |
+
Requires-Dist: azure-containerregistry; extra == 'launch'
|
85 |
+
Requires-Dist: azure-identity; extra == 'launch'
|
86 |
+
Requires-Dist: azure-storage-blob; extra == 'launch'
|
87 |
+
Requires-Dist: boto3; extra == 'launch'
|
88 |
+
Requires-Dist: botocore; extra == 'launch'
|
89 |
+
Requires-Dist: chardet; extra == 'launch'
|
90 |
+
Requires-Dist: google-auth; extra == 'launch'
|
91 |
+
Requires-Dist: google-cloud-aiplatform; extra == 'launch'
|
92 |
+
Requires-Dist: google-cloud-artifact-registry; extra == 'launch'
|
93 |
+
Requires-Dist: google-cloud-compute; extra == 'launch'
|
94 |
+
Requires-Dist: google-cloud-storage; extra == 'launch'
|
95 |
+
Requires-Dist: iso8601; extra == 'launch'
|
96 |
+
Requires-Dist: jsonschema; extra == 'launch'
|
97 |
+
Requires-Dist: kubernetes; extra == 'launch'
|
98 |
+
Requires-Dist: kubernetes-asyncio; extra == 'launch'
|
99 |
+
Requires-Dist: nbconvert; extra == 'launch'
|
100 |
+
Requires-Dist: nbformat; extra == 'launch'
|
101 |
+
Requires-Dist: optuna; extra == 'launch'
|
102 |
+
Requires-Dist: pydantic; extra == 'launch'
|
103 |
+
Requires-Dist: pyyaml>=6.0.0; extra == 'launch'
|
104 |
+
Requires-Dist: tomli; extra == 'launch'
|
105 |
+
Requires-Dist: typing-extensions; extra == 'launch'
|
106 |
+
Provides-Extra: media
|
107 |
+
Requires-Dist: bokeh; extra == 'media'
|
108 |
+
Requires-Dist: moviepy; extra == 'media'
|
109 |
+
Requires-Dist: numpy; extra == 'media'
|
110 |
+
Requires-Dist: pillow; extra == 'media'
|
111 |
+
Requires-Dist: plotly>=5.18.0; extra == 'media'
|
112 |
+
Requires-Dist: rdkit-pypi; extra == 'media'
|
113 |
+
Requires-Dist: soundfile; extra == 'media'
|
114 |
+
Provides-Extra: models
|
115 |
+
Requires-Dist: cloudpickle; extra == 'models'
|
116 |
+
Provides-Extra: perf
|
117 |
+
Requires-Dist: orjson; extra == 'perf'
|
118 |
+
Provides-Extra: sweeps
|
119 |
+
Requires-Dist: sweeps>=0.2.0; extra == 'sweeps'
|
120 |
+
Provides-Extra: workspaces
|
121 |
+
Requires-Dist: wandb-workspaces; extra == 'workspaces'
|
122 |
+
Description-Content-Type: text/markdown
|
123 |
+
|
124 |
+
<div align="center">
|
125 |
+
<img src="https://i.imgur.com/RUtiVzH.png" width="600" /><br><br>
|
126 |
+
</div>
|
127 |
+
|
128 |
+
# Weights and Biases [![PyPI](https://img.shields.io/pypi/v/wandb)](https://pypi.python.org/pypi/wandb) [![Conda (channel only)](https://img.shields.io/conda/vn/conda-forge/wandb)](https://anaconda.org/conda-forge/wandb) [![CircleCI](https://img.shields.io/circleci/build/github/wandb/wandb/main)](https://circleci.com/gh/wandb/wandb) [![Codecov](https://img.shields.io/codecov/c/gh/wandb/wandb)](https://codecov.io/gh/wandb/wandb)
|
129 |
+
|
130 |
+
Use W&B to build better models faster. Track and visualize all the pieces of your machine learning pipeline, from datasets to production machine learning models. Get started with W&B today, [sign up for an account!](https://wandb.com?utm_source=github&utm_medium=code&utm_campaign=wandb&utm_content=readme)
|
131 |
+
|
132 |
+
|
133 |
+
|
134 |
+
See the [W&B Developer Guide](https://docs.wandb.ai/?utm_source=github&utm_medium=code&utm_campaign=wandb&utm_content=documentation) and [API Reference Guide](https://docs.wandb.ai/ref?utm_source=github&utm_medium=code&utm_campaign=wandb&utm_content=documentation) for a full technical description of the W&B platform.
|
135 |
+
|
136 |
+
|
137 |
+
|
138 |
+
# Quickstart
|
139 |
+
|
140 |
+
Get started with W&B in four steps:
|
141 |
+
|
142 |
+
1. First, sign up for a [W&B account](https://wandb.ai/login?utm_source=github&utm_medium=code&utm_campaign=wandb&utm_content=quickstart).
|
143 |
+
|
144 |
+
2. Second, install the W&B SDK with [pip](https://pip.pypa.io/en/stable/). Navigate to your terminal and type the following command:
|
145 |
+
|
146 |
+
```shell
|
147 |
+
pip install wandb
|
148 |
+
```
|
149 |
+
|
150 |
+
3. Third, log into W&B:
|
151 |
+
|
152 |
+
```python
|
153 |
+
wandb.login()
|
154 |
+
```
|
155 |
+
|
156 |
+
4. Use the example code snippet below as a template to integrate W&B to your Python script:
|
157 |
+
|
158 |
+
```python
|
159 |
+
import wandb
|
160 |
+
|
161 |
+
# Start a W&B Run with wandb.init
|
162 |
+
run = wandb.init(project="my_first_project")
|
163 |
+
|
164 |
+
# Save model inputs and hyperparameters in a wandb.config object
|
165 |
+
config = run.config
|
166 |
+
config.learning_rate = 0.01
|
167 |
+
|
168 |
+
# Model training code here ...
|
169 |
+
|
170 |
+
# Log metrics over time to visualize performance with wandb.log
|
171 |
+
for i in range(10):
|
172 |
+
run.log({"loss": ...})
|
173 |
+
|
174 |
+
# Mark the run as finished, and finish uploading all data
|
175 |
+
run.finish()
|
176 |
+
```
|
177 |
+
|
178 |
+
For example, if the preceding code was stored in a script called train.py:
|
179 |
+
|
180 |
+
```shell
|
181 |
+
python train.py
|
182 |
+
```
|
183 |
+
|
184 |
+
You will see a URL in your terminal logs when your script starts and finishes. Data is staged locally in a directory named _wandb_ relative to your script. Navigate to the W&B App to view a dashboard of your first W&B Experiment. Use the W&B App to compare multiple experiments in a unified place, dive into the results of a single run, and much more!
|
185 |
+
|
186 |
+
|
187 |
+
|
188 |
+
# Integrations
|
189 |
+
|
190 |
+
Use your favorite framework with W&B. W&B integrations make it fast and easy to set up experiment tracking and data versioning inside existing projects. For more information on how to integrate W&B with the framework of your choice, see [W&B Integrations](https://docs.wandb.ai/guides/integrations) in the W&B Developer Guide.
|
191 |
+
|
192 |
+
|
193 |
+
|
194 |
+
# Contribution guidelines
|
195 |
+
Weights & Biases ❤️ open source, and we welcome contributions from the community! See the [Contribution guide](https://github.com/wandb/wandb/blob/main/CONTRIBUTING.md) for more information on the development workflow and the internals of the wandb library. For wandb bugs and feature requests, visit [GitHub Issues](https://github.com/wandb/wandb/issues) or contact [email protected].
|
196 |
+
|
197 |
+
|
198 |
+
|
199 |
+
# Academic Researchers
|
200 |
+
Reach out to W&B Support at [email protected] to get a [free academic license](https://www.wandb.com/academic) for you and your research group.
|
201 |
+
|
202 |
+
|
203 |
+
|
204 |
+
# W&B Community
|
205 |
+
|
206 |
+
Be a part of the growing W&B Community and interact with the W&B team in our [Discord](https://wandb.me/discord). Stay connected with the latest ML updates and tutorials with [W&B Fully Connected](https://wandb.ai/fully-connected).
|
207 |
+
|
208 |
+
|
209 |
+
|
210 |
+
# License
|
211 |
+
|
212 |
+
[MIT License](https://github.com/wandb/wandb/blob/main/LICENSE)
|
.cache/pip/http-v2/8/9/2/3/0/89230ee5375192cd78aff8dee73d946e2bcfcfb4c3ec4374132fe597
ADDED
Binary file (1.2 kB). View file
|
|
.cache/pip/http-v2/8/9/3/a/9/893a9178010858cecf72b523725b46ddedbe6c23406a020810080ab3
ADDED
Binary file (1.81 kB). View file
|
|
.cache/pip/http-v2/8/9/3/a/9/893a9178010858cecf72b523725b46ddedbe6c23406a020810080ab3.body
ADDED
Binary file (79.2 kB). View file
|
|
.cache/pip/http-v2/8/f/4/1/0/8f410bbfc5d1848453018f07fdeb351a0d0ae8a3bcdc5a16f937935c
ADDED
Binary file (1.15 kB). View file
|
|
.cache/pip/http-v2/c/4/2/0/3/c4203c5060d0f778eafd521050eab23e6aaa0f9eefa17eb1e671212c.body
ADDED
Binary file (306 kB). View file
|
|
.cache/pip/http-v2/c/5/4/0/3/c5403a101bbaf526810b4c472004bc3b03b96b7c8118e06c7a081e63
ADDED
Binary file (1.82 kB). View file
|
|
.cache/pip/http-v2/c/d/5/d/e/cd5de44b899cbe1869765c21b55cffc53c0c0ffa9d3c6f1fd40a42a2
ADDED
Binary file (1.82 kB). View file
|
|
.cache/pip/http-v2/e/0/2/d/2/e02d204cdd3b7d268ee1e9bbce86143c099522474d7852833cd72d7a.body
ADDED
Binary file (39.5 kB). View file
|
|
.cache/pip/http-v2/e/1/b/5/5/e1b55fb53084fd5cce9225f16241fc71d928894827c254f9bf6a38ba.body
ADDED
Binary file (3.58 kB). View file
|
|
.cache/pip/http-v2/e/2/1/8/e/e218e159f80d2bf1828c7fd77e9bd5d91b70e0dc57d3760ff21315f2
ADDED
Binary file (1.15 kB). View file
|
|
.cache/pip/http-v2/e/2/1/8/e/e218e159f80d2bf1828c7fd77e9bd5d91b70e0dc57d3760ff21315f2.body
ADDED
Binary file (194 kB). View file
|
|
.cache/pip/http-v2/e/9/6/f/6/e96f6a0f641ba82c2185cbd0cd572ff721b2be1fc873c69faf0ff627
ADDED
Binary file (1.81 kB). View file
|
|
.cache/pip/http-v2/e/9/6/f/6/e96f6a0f641ba82c2185cbd0cd572ff721b2be1fc873c69faf0ff627.body
ADDED
Binary file (2.97 kB). View file
|
|
.cache/pip/http-v2/e/9/9/d/2/e99d273763b5a9911259ba7015a44152ddf05aec2016679f6c849a2a.body
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Metadata-Version: 2.1
|
2 |
+
Name: bash_kernel
|
3 |
+
Version: 0.9.3
|
4 |
+
Summary: A bash kernel for Jupyter
|
5 |
+
Author-email: Thomas Kluyver <[email protected]>
|
6 |
+
Description-Content-Type: text/x-rst
|
7 |
+
Classifier: Framework :: Jupyter
|
8 |
+
Classifier: License :: OSI Approved :: BSD License
|
9 |
+
Classifier: Programming Language :: Python :: 3
|
10 |
+
Classifier: Topic :: System :: Shells
|
11 |
+
Requires-Dist: pexpect (>=4.0)
|
12 |
+
Requires-Dist: ipykernel
|
13 |
+
Project-URL: Source, https://github.com/takluyver/bash_kernel
|
14 |
+
|
15 |
+
.. image:: https://mybinder.org/badge_logo.svg
|
16 |
+
:target: https://mybinder.org/v2/gh/takluyver/bash_kernel/master
|
17 |
+
|
18 |
+
=========================
|
19 |
+
A Jupyter kernel for bash
|
20 |
+
=========================
|
21 |
+
|
22 |
+
Installation
|
23 |
+
------------
|
24 |
+
This requires IPython 3.
|
25 |
+
|
26 |
+
.. code:: shell
|
27 |
+
|
28 |
+
pip install bash_kernel
|
29 |
+
python -m bash_kernel.install
|
30 |
+
|
31 |
+
To use it, run one of:
|
32 |
+
|
33 |
+
.. code:: shell
|
34 |
+
|
35 |
+
jupyter notebook
|
36 |
+
# In the notebook interface, select Bash from the 'New' menu
|
37 |
+
jupyter qtconsole --kernel bash
|
38 |
+
jupyter console --kernel bash
|
39 |
+
|
40 |
+
Displaying Rich Content
|
41 |
+
-----------------------
|
42 |
+
|
43 |
+
To use specialized content (images, html, etc) this file defines (in `build_cmds()`) bash functions
|
44 |
+
that take the contents as standard input. Currently, `display` (images), `displayHTML` (html)
|
45 |
+
and `displayJS` (javascript) are supported.
|
46 |
+
|
47 |
+
Example:
|
48 |
+
|
49 |
+
.. code:: shell
|
50 |
+
|
51 |
+
cat dog.png | display
|
52 |
+
echo "<b>Dog</b>, not a cat." | displayHTML
|
53 |
+
echo "alert('It is known khaleesi\!');" | displayJS
|
54 |
+
|
55 |
+
Updating Rich Content Cells
|
56 |
+
---------------------------
|
57 |
+
|
58 |
+
If one is doing something that requires dynamic updates, one can specify a unique display_id,
|
59 |
+
should be a string name (downstream documentation is not clear on this), and the contents
|
60 |
+
will be replaced by the new value. Example:
|
61 |
+
|
62 |
+
.. code:: shell
|
63 |
+
|
64 |
+
display_id="id_${RANDOM}"
|
65 |
+
((ii=0))
|
66 |
+
while ((ii < 10)) ; do
|
67 |
+
echo "<div>${ii}</div>" | displayHTML $display_id
|
68 |
+
((ii = ii+1))
|
69 |
+
sleep 1
|
70 |
+
done
|
71 |
+
|
72 |
+
The same works for images or even javascript content.
|
73 |
+
|
74 |
+
**Remember to create always a new id** (random ids works perfect) each time the cell is executed, otherwise
|
75 |
+
it will try to display on an HTML element that no longer exists (they are erased each time a cell is re-run).
|
76 |
+
|
77 |
+
Programmatically Generating Rich Content
|
78 |
+
----------------------------------------
|
79 |
+
|
80 |
+
Alternatively one can simply generate the rich content to a file in /tmp (or $TMPDIR)
|
81 |
+
and then output the corresponding (to the mimetype) context prefix "_TEXT_SAVED_*"
|
82 |
+
constant. So one can write programs (C++, Go, Rust, etc.) that generates rich content
|
83 |
+
appropriately, when within a notebook.
|
84 |
+
|
85 |
+
The environment variable "NOTEBOOK_BASH_KERNEL_CAPABILITIES" will be set with a comma
|
86 |
+
separated list of the supported types (currently "image,html,javascript") that a program
|
87 |
+
can check for.
|
88 |
+
|
89 |
+
To output to a particular "display_id", to allow update of content (e.g: dynamically
|
90 |
+
updating/generating a plot from a command line program), prefix the filename
|
91 |
+
with "(<display_id>)". E.g: a line to display the contents of /tmp/myHTML.html to
|
92 |
+
a display id "id_12345" would look like:
|
93 |
+
|
94 |
+
bash_kernel: saved html data to: (id_12345) /tmp/myHTML.html
|
95 |
+
|
96 |
+
More Information
|
97 |
+
----------------
|
98 |
+
|
99 |
+
For details of how this works, see the Jupyter docs on `wrapper kernels
|
100 |
+
<http://jupyter-client.readthedocs.org/en/latest/wrapperkernels.html>`_, and
|
101 |
+
Pexpect's docs on the `replwrap module
|
102 |
+
<http://pexpect.readthedocs.org/en/latest/api/replwrap.html>`_.
|
103 |
+
|
.cache/pip/http-v2/e/a/c/6/1/eac61126daf80149d2a016f12a54eab5e3b5c1dbc77410ff1a97edc4
ADDED
Binary file (1.81 kB). View file
|
|
.cache/pip/http-v2/f/3/c/4/d/f3c4dedd1435641845fe96a7938402191795947fd69de9d823bd65e1
ADDED
Binary file (1.82 kB). View file
|
|
.cache/pip/http-v2/f/4/3/c/e/f43ce2cb74a8c7ad77da70314e043a539a7f01416550c3167312132b
ADDED
Binary file (1.16 kB). View file
|
|
.cache/pip/http-v2/f/4/4/1/e/f441e9f50c61e41b200d99c506edae810953f5810bcb8a4e8bae463c.body
ADDED
Binary file (18.9 kB). View file
|
|
.cache/pip/http-v2/f/6/8/9/5/f689581dbe86ea3c1a14226c252116f97e87dde2c835d7d60fd42b59
ADDED
Binary file (1.19 kB). View file
|
|
.cache/pip/http-v2/f/a/0/e/b/fa0eb94064e725636a09e766c68812661f1423e7568ddc8b81c74949
ADDED
Binary file (1.19 kB). View file
|
|
.cache/pip/http-v2/f/a/0/e/b/fa0eb94064e725636a09e766c68812661f1423e7568ddc8b81c74949.body
ADDED
@@ -0,0 +1,1591 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Metadata-Version: 2.1
|
2 |
+
Name: tqdm
|
3 |
+
Version: 4.66.5
|
4 |
+
Summary: Fast, Extensible Progress Meter
|
5 |
+
Maintainer-email: tqdm developers <[email protected]>
|
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-xdist ; extra == 'dev'
|
76 |
+
Provides-Extra: notebook
|
77 |
+
Requires-Dist: ipywidgets >=6 ; extra == 'notebook'
|
78 |
+
Provides-Extra: slack
|
79 |
+
Requires-Dist: slack-sdk ; extra == 'slack'
|
80 |
+
Provides-Extra: telegram
|
81 |
+
Requires-Dist: requests ; extra == 'telegram'
|
82 |
+
|
83 |
+
|Logo|
|
84 |
+
|
85 |
+
tqdm
|
86 |
+
====
|
87 |
+
|
88 |
+
|Py-Versions| |Versions| |Conda-Forge-Status| |Docker| |Snapcraft|
|
89 |
+
|
90 |
+
|Build-Status| |Coverage-Status| |Branch-Coverage-Status| |Codacy-Grade| |Libraries-Rank| |PyPI-Downloads|
|
91 |
+
|
92 |
+
|LICENCE| |OpenHub-Status| |binder-demo| |awesome-python|
|
93 |
+
|
94 |
+
``tqdm`` derives from the Arabic word *taqaddum* (تقدّم) which can mean "progress,"
|
95 |
+
and is an abbreviation for "I love you so much" in Spanish (*te quiero demasiado*).
|
96 |
+
|
97 |
+
Instantly make your loops show a smart progress meter - just wrap any
|
98 |
+
iterable with ``tqdm(iterable)``, and you're done!
|
99 |
+
|
100 |
+
.. code:: python
|
101 |
+
|
102 |
+
from tqdm import tqdm
|
103 |
+
for i in tqdm(range(10000)):
|
104 |
+
...
|
105 |
+
|
106 |
+
``76%|████████████████████████ | 7568/10000 [00:33<00:10, 229.00it/s]``
|
107 |
+
|
108 |
+
``trange(N)`` can be also used as a convenient shortcut for
|
109 |
+
``tqdm(range(N))``.
|
110 |
+
|
111 |
+
|Screenshot|
|
112 |
+
|Video| |Slides| |Merch|
|
113 |
+
|
114 |
+
It can also be executed as a module with pipes:
|
115 |
+
|
116 |
+
.. code:: sh
|
117 |
+
|
118 |
+
$ seq 9999999 | tqdm --bytes | wc -l
|
119 |
+
75.2MB [00:00, 217MB/s]
|
120 |
+
9999999
|
121 |
+
|
122 |
+
$ tar -zcf - docs/ | tqdm --bytes --total `du -sb docs/ | cut -f1` \
|
123 |
+
> backup.tgz
|
124 |
+
32%|██████████▍ | 8.89G/27.9G [00:42<01:31, 223MB/s]
|
125 |
+
|
126 |
+
Overhead is low -- about 60ns per iteration (80ns with ``tqdm.gui``), and is
|
127 |
+
unit tested against performance regression.
|
128 |
+
By comparison, the well-established
|
129 |
+
`ProgressBar <https://github.com/niltonvolpato/python-progressbar>`__ has
|
130 |
+
an 800ns/iter overhead.
|
131 |
+
|
132 |
+
In addition to its low overhead, ``tqdm`` uses smart algorithms to predict
|
133 |
+
the remaining time and to skip unnecessary iteration displays, which allows
|
134 |
+
for a negligible overhead in most cases.
|
135 |
+
|
136 |
+
``tqdm`` works on any platform
|
137 |
+
(Linux, Windows, Mac, FreeBSD, NetBSD, Solaris/SunOS),
|
138 |
+
in any console or in a GUI, and is also friendly with IPython/Jupyter notebooks.
|
139 |
+
|
140 |
+
``tqdm`` does not require any dependencies (not even ``curses``!), just
|
141 |
+
Python and an environment supporting ``carriage return \r`` and
|
142 |
+
``line feed \n`` control characters.
|
143 |
+
|
144 |
+
------------------------------------------
|
145 |
+
|
146 |
+
.. contents:: Table of contents
|
147 |
+
:backlinks: top
|
148 |
+
:local:
|
149 |
+
|
150 |
+
|
151 |
+
Installation
|
152 |
+
------------
|
153 |
+
|
154 |
+
Latest PyPI stable release
|
155 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
156 |
+
|
157 |
+
|Versions| |PyPI-Downloads| |Libraries-Dependents|
|
158 |
+
|
159 |
+
.. code:: sh
|
160 |
+
|
161 |
+
pip install tqdm
|
162 |
+
|
163 |
+
Latest development release on GitHub
|
164 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
165 |
+
|
166 |
+
|GitHub-Status| |GitHub-Stars| |GitHub-Commits| |GitHub-Forks| |GitHub-Updated|
|
167 |
+
|
168 |
+
Pull and install pre-release ``devel`` branch:
|
169 |
+
|
170 |
+
.. code:: sh
|
171 |
+
|
172 |
+
pip install "git+https://github.com/tqdm/tqdm.git@devel#egg=tqdm"
|
173 |
+
|
174 |
+
Latest Conda release
|
175 |
+
~~~~~~~~~~~~~~~~~~~~
|
176 |
+
|
177 |
+
|Conda-Forge-Status|
|
178 |
+
|
179 |
+
.. code:: sh
|
180 |
+
|
181 |
+
conda install -c conda-forge tqdm
|
182 |
+
|
183 |
+
Latest Snapcraft release
|
184 |
+
~~~~~~~~~~~~~~~~~~~~~~~~
|
185 |
+
|
186 |
+
|Snapcraft|
|
187 |
+
|
188 |
+
There are 3 channels to choose from:
|
189 |
+
|
190 |
+
.. code:: sh
|
191 |
+
|
192 |
+
snap install tqdm # implies --stable, i.e. latest tagged release
|
193 |
+
snap install tqdm --candidate # master branch
|
194 |
+
snap install tqdm --edge # devel branch
|
195 |
+
|
196 |
+
Note that ``snap`` binaries are purely for CLI use (not ``import``-able), and
|
197 |
+
automatically set up ``bash`` tab-completion.
|
198 |
+
|
199 |
+
Latest Docker release
|
200 |
+
~~~~~~~~~~~~~~~~~~~~~
|
201 |
+
|
202 |
+
|Docker|
|
203 |
+
|
204 |
+
.. code:: sh
|
205 |
+
|
206 |
+
docker pull tqdm/tqdm
|
207 |
+
docker run -i --rm tqdm/tqdm --help
|
208 |
+
|
209 |
+
Other
|
210 |
+
~~~~~
|
211 |
+
|
212 |
+
There are other (unofficial) places where ``tqdm`` may be downloaded, particularly for CLI use:
|
213 |
+
|
214 |
+
|Repology|
|
215 |
+
|
216 |
+
.. |Repology| image:: https://repology.org/badge/tiny-repos/python:tqdm.svg
|
217 |
+
:target: https://repology.org/project/python:tqdm/versions
|
218 |
+
|
219 |
+
Changelog
|
220 |
+
---------
|
221 |
+
|
222 |
+
The list of all changes is available either on GitHub's Releases:
|
223 |
+
|GitHub-Status|, on the
|
224 |
+
`wiki <https://github.com/tqdm/tqdm/wiki/Releases>`__, or on the
|
225 |
+
`website <https://tqdm.github.io/releases>`__.
|
226 |
+
|
227 |
+
|
228 |
+
Usage
|
229 |
+
-----
|
230 |
+
|
231 |
+
``tqdm`` is very versatile and can be used in a number of ways.
|
232 |
+
The three main ones are given below.
|
233 |
+
|
234 |
+
Iterable-based
|
235 |
+
~~~~~~~~~~~~~~
|
236 |
+
|
237 |
+
Wrap ``tqdm()`` around any iterable:
|
238 |
+
|
239 |
+
.. code:: python
|
240 |
+
|
241 |
+
from tqdm import tqdm
|
242 |
+
from time import sleep
|
243 |
+
|
244 |
+
text = ""
|
245 |
+
for char in tqdm(["a", "b", "c", "d"]):
|
246 |
+
sleep(0.25)
|
247 |
+
text = text + char
|
248 |
+
|
249 |
+
``trange(i)`` is a special optimised instance of ``tqdm(range(i))``:
|
250 |
+
|
251 |
+
.. code:: python
|
252 |
+
|
253 |
+
from tqdm import trange
|
254 |
+
|
255 |
+
for i in trange(100):
|
256 |
+
sleep(0.01)
|
257 |
+
|
258 |
+
Instantiation outside of the loop allows for manual control over ``tqdm()``:
|
259 |
+
|
260 |
+
.. code:: python
|
261 |
+
|
262 |
+
pbar = tqdm(["a", "b", "c", "d"])
|
263 |
+
for char in pbar:
|
264 |
+
sleep(0.25)
|
265 |
+
pbar.set_description("Processing %s" % char)
|
266 |
+
|
267 |
+
Manual
|
268 |
+
~~~~~~
|
269 |
+
|
270 |
+
Manual control of ``tqdm()`` updates using a ``with`` statement:
|
271 |
+
|
272 |
+
.. code:: python
|
273 |
+
|
274 |
+
with tqdm(total=100) as pbar:
|
275 |
+
for i in range(10):
|
276 |
+
sleep(0.1)
|
277 |
+
pbar.update(10)
|
278 |
+
|
279 |
+
If the optional variable ``total`` (or an iterable with ``len()``) is
|
280 |
+
provided, predictive stats are displayed.
|
281 |
+
|
282 |
+
``with`` is also optional (you can just assign ``tqdm()`` to a variable,
|
283 |
+
but in this case don't forget to ``del`` or ``close()`` at the end:
|
284 |
+
|
285 |
+
.. code:: python
|
286 |
+
|
287 |
+
pbar = tqdm(total=100)
|
288 |
+
for i in range(10):
|
289 |
+
sleep(0.1)
|
290 |
+
pbar.update(10)
|
291 |
+
pbar.close()
|
292 |
+
|
293 |
+
Module
|
294 |
+
~~~~~~
|
295 |
+
|
296 |
+
Perhaps the most wonderful use of ``tqdm`` is in a script or on the command
|
297 |
+
line. Simply inserting ``tqdm`` (or ``python -m tqdm``) between pipes will pass
|
298 |
+
through all ``stdin`` to ``stdout`` while printing progress to ``stderr``.
|
299 |
+
|
300 |
+
The example below demonstrate counting the number of lines in all Python files
|
301 |
+
in the current directory, with timing information included.
|
302 |
+
|
303 |
+
.. code:: sh
|
304 |
+
|
305 |
+
$ time find . -name '*.py' -type f -exec cat \{} \; | wc -l
|
306 |
+
857365
|
307 |
+
|
308 |
+
real 0m3.458s
|
309 |
+
user 0m0.274s
|
310 |
+
sys 0m3.325s
|
311 |
+
|
312 |
+
$ time find . -name '*.py' -type f -exec cat \{} \; | tqdm | wc -l
|
313 |
+
857366it [00:03, 246471.31it/s]
|
314 |
+
857365
|
315 |
+
|
316 |
+
real 0m3.585s
|
317 |
+
user 0m0.862s
|
318 |
+
sys 0m3.358s
|
319 |
+
|
320 |
+
Note that the usual arguments for ``tqdm`` can also be specified.
|
321 |
+
|
322 |
+
.. code:: sh
|
323 |
+
|
324 |
+
$ find . -name '*.py' -type f -exec cat \{} \; |
|
325 |
+
tqdm --unit loc --unit_scale --total 857366 >> /dev/null
|
326 |
+
100%|█████████████████████████████████| 857K/857K [00:04<00:00, 246Kloc/s]
|
327 |
+
|
328 |
+
Backing up a large directory?
|
329 |
+
|
330 |
+
.. code:: sh
|
331 |
+
|
332 |
+
$ tar -zcf - docs/ | tqdm --bytes --total `du -sb docs/ | cut -f1` \
|
333 |
+
> backup.tgz
|
334 |
+
44%|██████████████▊ | 153M/352M [00:14<00:18, 11.0MB/s]
|
335 |
+
|
336 |
+
This can be beautified further:
|
337 |
+
|
338 |
+
.. code:: sh
|
339 |
+
|
340 |
+
$ BYTES=$(du -sb docs/ | cut -f1)
|
341 |
+
$ tar -cf - docs/ \
|
342 |
+
| tqdm --bytes --total "$BYTES" --desc Processing | gzip \
|
343 |
+
| tqdm --bytes --total "$BYTES" --desc Compressed --position 1 \
|
344 |
+
> ~/backup.tgz
|
345 |
+
Processing: 100%|██████████████████████| 352M/352M [00:14<00:00, 30.2MB/s]
|
346 |
+
Compressed: 42%|█████████▎ | 148M/352M [00:14<00:19, 10.9MB/s]
|
347 |
+
|
348 |
+
Or done on a file level using 7-zip:
|
349 |
+
|
350 |
+
.. code:: sh
|
351 |
+
|
352 |
+
$ 7z a -bd -r backup.7z docs/ | grep Compressing \
|
353 |
+
| tqdm --total $(find docs/ -type f | wc -l) --unit files \
|
354 |
+
| grep -v Compressing
|
355 |
+
100%|██████████████████████████▉| 15327/15327 [01:00<00:00, 712.96files/s]
|
356 |
+
|
357 |
+
Pre-existing CLI programs already outputting basic progress information will
|
358 |
+
benefit from ``tqdm``'s ``--update`` and ``--update_to`` flags:
|
359 |
+
|
360 |
+
.. code:: sh
|
361 |
+
|
362 |
+
$ seq 3 0.1 5 | tqdm --total 5 --update_to --null
|
363 |
+
100%|████████████████████████████████████| 5.0/5 [00:00<00:00, 9673.21it/s]
|
364 |
+
$ seq 10 | tqdm --update --null # 1 + 2 + ... + 10 = 55 iterations
|
365 |
+
55it [00:00, 90006.52it/s]
|
366 |
+
|
367 |
+
FAQ and Known Issues
|
368 |
+
--------------------
|
369 |
+
|
370 |
+
|GitHub-Issues|
|
371 |
+
|
372 |
+
The most common issues relate to excessive output on multiple lines, instead
|
373 |
+
of a neat one-line progress bar.
|
374 |
+
|
375 |
+
- Consoles in general: require support for carriage return (``CR``, ``\r``).
|
376 |
+
|
377 |
+
* Some cloud logging consoles which don't support ``\r`` properly
|
378 |
+
(`cloudwatch <https://github.com/tqdm/tqdm/issues/966>`__,
|
379 |
+
`K8s <https://github.com/tqdm/tqdm/issues/1319>`__) may benefit from
|
380 |
+
``export TQDM_POSITION=-1``.
|
381 |
+
|
382 |
+
- Nested progress bars:
|
383 |
+
|
384 |
+
* Consoles in general: require support for moving cursors up to the
|
385 |
+
previous line. For example,
|
386 |
+
`IDLE <https://github.com/tqdm/tqdm/issues/191#issuecomment-230168030>`__,
|
387 |
+
`ConEmu <https://github.com/tqdm/tqdm/issues/254>`__ and
|
388 |
+
`PyCharm <https://github.com/tqdm/tqdm/issues/203>`__ (also
|
389 |
+
`here <https://github.com/tqdm/tqdm/issues/208>`__,
|
390 |
+
`here <https://github.com/tqdm/tqdm/issues/307>`__, and
|
391 |
+
`here <https://github.com/tqdm/tqdm/issues/454#issuecomment-335416815>`__)
|
392 |
+
lack full support.
|
393 |
+
* Windows: additionally may require the Python module ``colorama``
|
394 |
+
to ensure nested bars stay within their respective lines.
|
395 |
+
|
396 |
+
- Unicode:
|
397 |
+
|
398 |
+
* Environments which report that they support unicode will have solid smooth
|
399 |
+
progressbars. The fallback is an ``ascii``-only bar.
|
400 |
+
* Windows consoles often only partially support unicode and thus
|
401 |
+
`often require explicit ascii=True <https://github.com/tqdm/tqdm/issues/454#issuecomment-335416815>`__
|
402 |
+
(also `here <https://github.com/tqdm/tqdm/issues/499>`__). This is due to
|
403 |
+
either normal-width unicode characters being incorrectly displayed as
|
404 |
+
"wide", or some unicode characters not rendering.
|
405 |
+
|
406 |
+
- Wrapping generators:
|
407 |
+
|
408 |
+
* Generator wrapper functions tend to hide the length of iterables.
|
409 |
+
``tqdm`` does not.
|
410 |
+
* Replace ``tqdm(enumerate(...))`` with ``enumerate(tqdm(...))`` or
|
411 |
+
``tqdm(enumerate(x), total=len(x), ...)``.
|
412 |
+
The same applies to ``numpy.ndenumerate``.
|
413 |
+
* Replace ``tqdm(zip(a, b))`` with ``zip(tqdm(a), b)`` or even
|
414 |
+
``zip(tqdm(a), tqdm(b))``.
|
415 |
+
* The same applies to ``itertools``.
|
416 |
+
* Some useful convenience functions can be found under ``tqdm.contrib``.
|
417 |
+
|
418 |
+
- `No intermediate output in docker-compose <https://github.com/tqdm/tqdm/issues/771>`__:
|
419 |
+
use ``docker-compose run`` instead of ``docker-compose up`` and ``tty: true``.
|
420 |
+
|
421 |
+
- Overriding defaults via environment variables:
|
422 |
+
e.g. in CI/cloud jobs, ``export TQDM_MININTERVAL=5`` to avoid log spam.
|
423 |
+
This override logic is handled by the ``tqdm.utils.envwrap`` decorator
|
424 |
+
(useful independent of ``tqdm``).
|
425 |
+
|
426 |
+
If you come across any other difficulties, browse and file |GitHub-Issues|.
|
427 |
+
|
428 |
+
Documentation
|
429 |
+
-------------
|
430 |
+
|
431 |
+
|Py-Versions| |README-Hits| (Since 19 May 2016)
|
432 |
+
|
433 |
+
.. code:: python
|
434 |
+
|
435 |
+
class tqdm():
|
436 |
+
"""
|
437 |
+
Decorate an iterable object, returning an iterator which acts exactly
|
438 |
+
like the original iterable, but prints a dynamically updating
|
439 |
+
progressbar every time a value is requested.
|
440 |
+
"""
|
441 |
+
|
442 |
+
@envwrap("TQDM_") # override defaults via env vars
|
443 |
+
def __init__(self, iterable=None, desc=None, total=None, leave=True,
|
444 |
+
file=None, ncols=None, mininterval=0.1,
|
445 |
+
maxinterval=10.0, miniters=None, ascii=None, disable=False,
|
446 |
+
unit='it', unit_scale=False, dynamic_ncols=False,
|
447 |
+
smoothing=0.3, bar_format=None, initial=0, position=None,
|
448 |
+
postfix=None, unit_divisor=1000, write_bytes=False,
|
449 |
+
lock_args=None, nrows=None, colour=None, delay=0):
|
450 |
+
|
451 |
+
Parameters
|
452 |
+
~~~~~~~~~~
|
453 |
+
|
454 |
+
* iterable : iterable, optional
|
455 |
+
Iterable to decorate with a progressbar.
|
456 |
+
Leave blank to manually manage the updates.
|
457 |
+
* desc : str, optional
|
458 |
+
Prefix for the progressbar.
|
459 |
+
* total : int or float, optional
|
460 |
+
The number of expected iterations. If unspecified,
|
461 |
+
len(iterable) is used if possible. If float("inf") or as a last
|
462 |
+
resort, only basic progress statistics are displayed
|
463 |
+
(no ETA, no progressbar).
|
464 |
+
If ``gui`` is True and this parameter needs subsequent updating,
|
465 |
+
specify an initial arbitrary large positive number,
|
466 |
+
e.g. 9e9.
|
467 |
+
* leave : bool, optional
|
468 |
+
If [default: True], keeps all traces of the progressbar
|
469 |
+
upon termination of iteration.
|
470 |
+
If ``None``, will leave only if ``position`` is ``0``.
|
471 |
+
* file : ``io.TextIOWrapper`` or ``io.StringIO``, optional
|
472 |
+
Specifies where to output the progress messages
|
473 |
+
(default: sys.stderr). Uses ``file.write(str)`` and ``file.flush()``
|
474 |
+
methods. For encoding, see ``write_bytes``.
|
475 |
+
* ncols : int, optional
|
476 |
+
The width of the entire output message. If specified,
|
477 |
+
dynamically resizes the progressbar to stay within this bound.
|
478 |
+
If unspecified, attempts to use environment width. The
|
479 |
+
fallback is a meter width of 10 and no limit for the counter and
|
480 |
+
statistics. If 0, will not print any meter (only stats).
|
481 |
+
* mininterval : float, optional
|
482 |
+
Minimum progress display update interval [default: 0.1] seconds.
|
483 |
+
* maxinterval : float, optional
|
484 |
+
Maximum progress display update interval [default: 10] seconds.
|
485 |
+
Automatically adjusts ``miniters`` to correspond to ``mininterval``
|
486 |
+
after long display update lag. Only works if ``dynamic_miniters``
|
487 |
+
or monitor thread is enabled.
|
488 |
+
* miniters : int or float, optional
|
489 |
+
Minimum progress display update interval, in iterations.
|
490 |
+
If 0 and ``dynamic_miniters``, will automatically adjust to equal
|
491 |
+
``mininterval`` (more CPU efficient, good for tight loops).
|
492 |
+
If > 0, will skip display of specified number of iterations.
|
493 |
+
Tweak this and ``mininterval`` to get very efficient loops.
|
494 |
+
If your progress is erratic with both fast and slow iterations
|
495 |
+
(network, skipping items, etc) you should set miniters=1.
|
496 |
+
* ascii : bool or str, optional
|
497 |
+
If unspecified or False, use unicode (smooth blocks) to fill
|
498 |
+
the meter. The fallback is to use ASCII characters " 123456789#".
|
499 |
+
* disable : bool, optional
|
500 |
+
Whether to disable the entire progressbar wrapper
|
501 |
+
[default: False]. If set to None, disable on non-TTY.
|
502 |
+
* unit : str, optional
|
503 |
+
String that will be used to define the unit of each iteration
|
504 |
+
[default: it].
|
505 |
+
* unit_scale : bool or int or float, optional
|
506 |
+
If 1 or True, the number of iterations will be reduced/scaled
|
507 |
+
automatically and a metric prefix following the
|
508 |
+
International System of Units standard will be added
|
509 |
+
(kilo, mega, etc.) [default: False]. If any other non-zero
|
510 |
+
number, will scale ``total`` and ``n``.
|
511 |
+
* dynamic_ncols : bool, optional
|
512 |
+
If set, constantly alters ``ncols`` and ``nrows`` to the
|
513 |
+
environment (allowing for window resizes) [default: False].
|
514 |
+
* smoothing : float, optional
|
515 |
+
Exponential moving average smoothing factor for speed estimates
|
516 |
+
(ignored in GUI mode). Ranges from 0 (average speed) to 1
|
517 |
+
(current/instantaneous speed) [default: 0.3].
|
518 |
+
* bar_format : str, optional
|
519 |
+
Specify a custom bar string formatting. May impact performance.
|
520 |
+
[default: '{l_bar}{bar}{r_bar}'], where
|
521 |
+
l_bar='{desc}: {percentage:3.0f}%|' and
|
522 |
+
r_bar='| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, '
|
523 |
+
'{rate_fmt}{postfix}]'
|
524 |
+
Possible vars: l_bar, bar, r_bar, n, n_fmt, total, total_fmt,
|
525 |
+
percentage, elapsed, elapsed_s, ncols, nrows, desc, unit,
|
526 |
+
rate, rate_fmt, rate_noinv, rate_noinv_fmt,
|
527 |
+
rate_inv, rate_inv_fmt, postfix, unit_divisor,
|
528 |
+
remaining, remaining_s, eta.
|
529 |
+
Note that a trailing ": " is automatically removed after {desc}
|
530 |
+
if the latter is empty.
|
531 |
+
* initial : int or float, optional
|
532 |
+
The initial counter value. Useful when restarting a progress
|
533 |
+
bar [default: 0]. If using float, consider specifying ``{n:.3f}``
|
534 |
+
or similar in ``bar_format``, or specifying ``unit_scale``.
|
535 |
+
* position : int, optional
|
536 |
+
Specify the line offset to print this bar (starting from 0)
|
537 |
+
Automatic if unspecified.
|
538 |
+
Useful to manage multiple bars at once (eg, from threads).
|
539 |
+
* postfix : dict or ``*``, optional
|
540 |
+
Specify additional stats to display at the end of the bar.
|
541 |
+
Calls ``set_postfix(**postfix)`` if possible (dict).
|
542 |
+
* unit_divisor : float, optional
|
543 |
+
[default: 1000], ignored unless ``unit_scale`` is True.
|
544 |
+
* write_bytes : bool, optional
|
545 |
+
Whether to write bytes. If (default: False) will write unicode.
|
546 |
+
* lock_args : tuple, optional
|
547 |
+
Passed to ``refresh`` for intermediate output
|
548 |
+
(initialisation, iterating, and updating).
|
549 |
+
* nrows : int, optional
|
550 |
+
The screen height. If specified, hides nested bars outside this
|
551 |
+
bound. If unspecified, attempts to use environment height.
|
552 |
+
The fallback is 20.
|
553 |
+
* colour : str, optional
|
554 |
+
Bar colour (e.g. 'green', '#00ff00').
|
555 |
+
* delay : float, optional
|
556 |
+
Don't display until [default: 0] seconds have elapsed.
|
557 |
+
|
558 |
+
Extra CLI Options
|
559 |
+
~~~~~~~~~~~~~~~~~
|
560 |
+
|
561 |
+
* delim : chr, optional
|
562 |
+
Delimiting character [default: '\n']. Use '\0' for null.
|
563 |
+
N.B.: on Windows systems, Python converts '\n' to '\r\n'.
|
564 |
+
* buf_size : int, optional
|
565 |
+
String buffer size in bytes [default: 256]
|
566 |
+
used when ``delim`` is specified.
|
567 |
+
* bytes : bool, optional
|
568 |
+
If true, will count bytes, ignore ``delim``, and default
|
569 |
+
``unit_scale`` to True, ``unit_divisor`` to 1024, and ``unit`` to 'B'.
|
570 |
+
* tee : bool, optional
|
571 |
+
If true, passes ``stdin`` to both ``stderr`` and ``stdout``.
|
572 |
+
* update : bool, optional
|
573 |
+
If true, will treat input as newly elapsed iterations,
|
574 |
+
i.e. numbers to pass to ``update()``. Note that this is slow
|
575 |
+
(~2e5 it/s) since every input must be decoded as a number.
|
576 |
+
* update_to : bool, optional
|
577 |
+
If true, will treat input as total elapsed iterations,
|
578 |
+
i.e. numbers to assign to ``self.n``. Note that this is slow
|
579 |
+
(~2e5 it/s) since every input must be decoded as a number.
|
580 |
+
* null : bool, optional
|
581 |
+
If true, will discard input (no stdout).
|
582 |
+
* manpath : str, optional
|
583 |
+
Directory in which to install tqdm man pages.
|
584 |
+
* comppath : str, optional
|
585 |
+
Directory in which to place tqdm completion.
|
586 |
+
* log : str, optional
|
587 |
+
CRITICAL|FATAL|ERROR|WARN(ING)|[default: 'INFO']|DEBUG|NOTSET.
|
588 |
+
|
589 |
+
Returns
|
590 |
+
~~~~~~~
|
591 |
+
|
592 |
+
* out : decorated iterator.
|
593 |
+
|
594 |
+
.. code:: python
|
595 |
+
|
596 |
+
class tqdm():
|
597 |
+
def update(self, n=1):
|
598 |
+
"""
|
599 |
+
Manually update the progress bar, useful for streams
|
600 |
+
such as reading files.
|
601 |
+
E.g.:
|
602 |
+
>>> t = tqdm(total=filesize) # Initialise
|
603 |
+
>>> for current_buffer in stream:
|
604 |
+
... ...
|
605 |
+
... t.update(len(current_buffer))
|
606 |
+
>>> t.close()
|
607 |
+
The last line is highly recommended, but possibly not necessary if
|
608 |
+
``t.update()`` will be called in such a way that ``filesize`` will be
|
609 |
+
exactly reached and printed.
|
610 |
+
|
611 |
+
Parameters
|
612 |
+
----------
|
613 |
+
n : int or float, optional
|
614 |
+
Increment to add to the internal counter of iterations
|
615 |
+
[default: 1]. If using float, consider specifying ``{n:.3f}``
|
616 |
+
or similar in ``bar_format``, or specifying ``unit_scale``.
|
617 |
+
|
618 |
+
Returns
|
619 |
+
-------
|
620 |
+
out : bool or None
|
621 |
+
True if a ``display()`` was triggered.
|
622 |
+
"""
|
623 |
+
|
624 |
+
def close(self):
|
625 |
+
"""Cleanup and (if leave=False) close the progressbar."""
|
626 |
+
|
627 |
+
def clear(self, nomove=False):
|
628 |
+
"""Clear current bar display."""
|
629 |
+
|
630 |
+
def refresh(self):
|
631 |
+
"""
|
632 |
+
Force refresh the display of this bar.
|
633 |
+
|
634 |
+
Parameters
|
635 |
+
----------
|
636 |
+
nolock : bool, optional
|
637 |
+
If ``True``, does not lock.
|
638 |
+
If [default: ``False``]: calls ``acquire()`` on internal lock.
|
639 |
+
lock_args : tuple, optional
|
640 |
+
Passed to internal lock's ``acquire()``.
|
641 |
+
If specified, will only ``display()`` if ``acquire()`` returns ``True``.
|
642 |
+
"""
|
643 |
+
|
644 |
+
def unpause(self):
|
645 |
+
"""Restart tqdm timer from last print time."""
|
646 |
+
|
647 |
+
def reset(self, total=None):
|
648 |
+
"""
|
649 |
+
Resets to 0 iterations for repeated use.
|
650 |
+
|
651 |
+
Consider combining with ``leave=True``.
|
652 |
+
|
653 |
+
Parameters
|
654 |
+
----------
|
655 |
+
total : int or float, optional. Total to use for the new bar.
|
656 |
+
"""
|
657 |
+
|
658 |
+
def set_description(self, desc=None, refresh=True):
|
659 |
+
"""
|
660 |
+
Set/modify description of the progress bar.
|
661 |
+
|
662 |
+
Parameters
|
663 |
+
----------
|
664 |
+
desc : str, optional
|
665 |
+
refresh : bool, optional
|
666 |
+
Forces refresh [default: True].
|
667 |
+
"""
|
668 |
+
|
669 |
+
def set_postfix(self, ordered_dict=None, refresh=True, **tqdm_kwargs):
|
670 |
+
"""
|
671 |
+
Set/modify postfix (additional stats)
|
672 |
+
with automatic formatting based on datatype.
|
673 |
+
|
674 |
+
Parameters
|
675 |
+
----------
|
676 |
+
ordered_dict : dict or OrderedDict, optional
|
677 |
+
refresh : bool, optional
|
678 |
+
Forces refresh [default: True].
|
679 |
+
kwargs : dict, optional
|
680 |
+
"""
|
681 |
+
|
682 |
+
@classmethod
|
683 |
+
def write(cls, s, file=sys.stdout, end="\n"):
|
684 |
+
"""Print a message via tqdm (without overlap with bars)."""
|
685 |
+
|
686 |
+
@property
|
687 |
+
def format_dict(self):
|
688 |
+
"""Public API for read-only member access."""
|
689 |
+
|
690 |
+
def display(self, msg=None, pos=None):
|
691 |
+
"""
|
692 |
+
Use ``self.sp`` to display ``msg`` in the specified ``pos``.
|
693 |
+
|
694 |
+
Consider overloading this function when inheriting to use e.g.:
|
695 |
+
``self.some_frontend(**self.format_dict)`` instead of ``self.sp``.
|
696 |
+
|
697 |
+
Parameters
|
698 |
+
----------
|
699 |
+
msg : str, optional. What to display (default: ``repr(self)``).
|
700 |
+
pos : int, optional. Position to ``moveto``
|
701 |
+
(default: ``abs(self.pos)``).
|
702 |
+
"""
|
703 |
+
|
704 |
+
@classmethod
|
705 |
+
@contextmanager
|
706 |
+
def wrapattr(cls, stream, method, total=None, bytes=True, **tqdm_kwargs):
|
707 |
+
"""
|
708 |
+
stream : file-like object.
|
709 |
+
method : str, "read" or "write". The result of ``read()`` and
|
710 |
+
the first argument of ``write()`` should have a ``len()``.
|
711 |
+
|
712 |
+
>>> with tqdm.wrapattr(file_obj, "read", total=file_obj.size) as fobj:
|
713 |
+
... while True:
|
714 |
+
... chunk = fobj.read(chunk_size)
|
715 |
+
... if not chunk:
|
716 |
+
... break
|
717 |
+
"""
|
718 |
+
|
719 |
+
@classmethod
|
720 |
+
def pandas(cls, *targs, **tqdm_kwargs):
|
721 |
+
"""Registers the current `tqdm` class with `pandas`."""
|
722 |
+
|
723 |
+
def trange(*args, **tqdm_kwargs):
|
724 |
+
"""Shortcut for `tqdm(range(*args), **tqdm_kwargs)`."""
|
725 |
+
|
726 |
+
Convenience Functions
|
727 |
+
~~~~~~~~~~~~~~~~~~~~~
|
728 |
+
|
729 |
+
.. code:: python
|
730 |
+
|
731 |
+
def tqdm.contrib.tenumerate(iterable, start=0, total=None,
|
732 |
+
tqdm_class=tqdm.auto.tqdm, **tqdm_kwargs):
|
733 |
+
"""Equivalent of `numpy.ndenumerate` or builtin `enumerate`."""
|
734 |
+
|
735 |
+
def tqdm.contrib.tzip(iter1, *iter2plus, **tqdm_kwargs):
|
736 |
+
"""Equivalent of builtin `zip`."""
|
737 |
+
|
738 |
+
def tqdm.contrib.tmap(function, *sequences, **tqdm_kwargs):
|
739 |
+
"""Equivalent of builtin `map`."""
|
740 |
+
|
741 |
+
Submodules
|
742 |
+
~~~~~~~~~~
|
743 |
+
|
744 |
+
.. code:: python
|
745 |
+
|
746 |
+
class tqdm.notebook.tqdm(tqdm.tqdm):
|
747 |
+
"""IPython/Jupyter Notebook widget."""
|
748 |
+
|
749 |
+
class tqdm.auto.tqdm(tqdm.tqdm):
|
750 |
+
"""Automatically chooses beween `tqdm.notebook` and `tqdm.tqdm`."""
|
751 |
+
|
752 |
+
class tqdm.asyncio.tqdm(tqdm.tqdm):
|
753 |
+
"""Asynchronous version."""
|
754 |
+
@classmethod
|
755 |
+
def as_completed(cls, fs, *, loop=None, timeout=None, total=None,
|
756 |
+
**tqdm_kwargs):
|
757 |
+
"""Wrapper for `asyncio.as_completed`."""
|
758 |
+
|
759 |
+
class tqdm.gui.tqdm(tqdm.tqdm):
|
760 |
+
"""Matplotlib GUI version."""
|
761 |
+
|
762 |
+
class tqdm.tk.tqdm(tqdm.tqdm):
|
763 |
+
"""Tkinter GUI version."""
|
764 |
+
|
765 |
+
class tqdm.rich.tqdm(tqdm.tqdm):
|
766 |
+
"""`rich.progress` version."""
|
767 |
+
|
768 |
+
class tqdm.keras.TqdmCallback(keras.callbacks.Callback):
|
769 |
+
"""Keras callback for epoch and batch progress."""
|
770 |
+
|
771 |
+
class tqdm.dask.TqdmCallback(dask.callbacks.Callback):
|
772 |
+
"""Dask callback for task progress."""
|
773 |
+
|
774 |
+
|
775 |
+
``contrib``
|
776 |
+
+++++++++++
|
777 |
+
|
778 |
+
The ``tqdm.contrib`` package also contains experimental modules:
|
779 |
+
|
780 |
+
- ``tqdm.contrib.itertools``: Thin wrappers around ``itertools``
|
781 |
+
- ``tqdm.contrib.concurrent``: Thin wrappers around ``concurrent.futures``
|
782 |
+
- ``tqdm.contrib.slack``: Posts to `Slack <https://slack.com>`__ bots
|
783 |
+
- ``tqdm.contrib.discord``: Posts to `Discord <https://discord.com>`__ bots
|
784 |
+
- ``tqdm.contrib.telegram``: Posts to `Telegram <https://telegram.org>`__ bots
|
785 |
+
- ``tqdm.contrib.bells``: Automagically enables all optional features
|
786 |
+
|
787 |
+
* ``auto``, ``pandas``, ``slack``, ``discord``, ``telegram``
|
788 |
+
|
789 |
+
Examples and Advanced Usage
|
790 |
+
---------------------------
|
791 |
+
|
792 |
+
- See the `examples <https://github.com/tqdm/tqdm/tree/master/examples>`__
|
793 |
+
folder;
|
794 |
+
- import the module and run ``help()``;
|
795 |
+
- consult the `wiki <https://github.com/tqdm/tqdm/wiki>`__;
|
796 |
+
|
797 |
+
* this has an
|
798 |
+
`excellent article <https://github.com/tqdm/tqdm/wiki/How-to-make-a-great-Progress-Bar>`__
|
799 |
+
on how to make a **great** progressbar;
|
800 |
+
|
801 |
+
- check out the `slides from PyData London <https://tqdm.github.io/PyData2019/slides.html>`__, or
|
802 |
+
- run the |binder-demo|.
|
803 |
+
|
804 |
+
Description and additional stats
|
805 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
806 |
+
|
807 |
+
Custom information can be displayed and updated dynamically on ``tqdm`` bars
|
808 |
+
with the ``desc`` and ``postfix`` arguments:
|
809 |
+
|
810 |
+
.. code:: python
|
811 |
+
|
812 |
+
from tqdm import tqdm, trange
|
813 |
+
from random import random, randint
|
814 |
+
from time import sleep
|
815 |
+
|
816 |
+
with trange(10) as t:
|
817 |
+
for i in t:
|
818 |
+
# Description will be displayed on the left
|
819 |
+
t.set_description('GEN %i' % i)
|
820 |
+
# Postfix will be displayed on the right,
|
821 |
+
# formatted automatically based on argument's datatype
|
822 |
+
t.set_postfix(loss=random(), gen=randint(1,999), str='h',
|
823 |
+
lst=[1, 2])
|
824 |
+
sleep(0.1)
|
825 |
+
|
826 |
+
with tqdm(total=10, bar_format="{postfix[0]} {postfix[1][value]:>8.2g}",
|
827 |
+
postfix=["Batch", {"value": 0}]) as t:
|
828 |
+
for i in range(10):
|
829 |
+
sleep(0.1)
|
830 |
+
t.postfix[1]["value"] = i / 2
|
831 |
+
t.update()
|
832 |
+
|
833 |
+
Points to remember when using ``{postfix[...]}`` in the ``bar_format`` string:
|
834 |
+
|
835 |
+
- ``postfix`` also needs to be passed as an initial argument in a compatible
|
836 |
+
format, and
|
837 |
+
- ``postfix`` will be auto-converted to a string if it is a ``dict``-like
|
838 |
+
object. To prevent this behaviour, insert an extra item into the dictionary
|
839 |
+
where the key is not a string.
|
840 |
+
|
841 |
+
Additional ``bar_format`` parameters may also be defined by overriding
|
842 |
+
``format_dict``, and the bar itself may be modified using ``ascii``:
|
843 |
+
|
844 |
+
.. code:: python
|
845 |
+
|
846 |
+
from tqdm import tqdm
|
847 |
+
class TqdmExtraFormat(tqdm):
|
848 |
+
"""Provides a `total_time` format parameter"""
|
849 |
+
@property
|
850 |
+
def format_dict(self):
|
851 |
+
d = super().format_dict
|
852 |
+
total_time = d["elapsed"] * (d["total"] or 0) / max(d["n"], 1)
|
853 |
+
d.update(total_time=self.format_interval(total_time) + " in total")
|
854 |
+
return d
|
855 |
+
|
856 |
+
for i in TqdmExtraFormat(
|
857 |
+
range(9), ascii=" .oO0",
|
858 |
+
bar_format="{total_time}: {percentage:.0f}%|{bar}{r_bar}"):
|
859 |
+
if i == 4:
|
860 |
+
break
|
861 |
+
|
862 |
+
.. code::
|
863 |
+
|
864 |
+
00:00 in total: 44%|0000. | 4/9 [00:00<00:00, 962.93it/s]
|
865 |
+
|
866 |
+
Note that ``{bar}`` also supports a format specifier ``[width][type]``.
|
867 |
+
|
868 |
+
- ``width``
|
869 |
+
|
870 |
+
* unspecified (default): automatic to fill ``ncols``
|
871 |
+
* ``int >= 0``: fixed width overriding ``ncols`` logic
|
872 |
+
* ``int < 0``: subtract from the automatic default
|
873 |
+
|
874 |
+
- ``type``
|
875 |
+
|
876 |
+
* ``a``: ascii (``ascii=True`` override)
|
877 |
+
* ``u``: unicode (``ascii=False`` override)
|
878 |
+
* ``b``: blank (``ascii=" "`` override)
|
879 |
+
|
880 |
+
This means a fixed bar with right-justified text may be created by using:
|
881 |
+
``bar_format="{l_bar}{bar:10}|{bar:-10b}right-justified"``
|
882 |
+
|
883 |
+
Nested progress bars
|
884 |
+
~~~~~~~~~~~~~~~~~~~~
|
885 |
+
|
886 |
+
``tqdm`` supports nested progress bars. Here's an example:
|
887 |
+
|
888 |
+
.. code:: python
|
889 |
+
|
890 |
+
from tqdm.auto import trange
|
891 |
+
from time import sleep
|
892 |
+
|
893 |
+
for i in trange(4, desc='1st loop'):
|
894 |
+
for j in trange(5, desc='2nd loop'):
|
895 |
+
for k in trange(50, desc='3rd loop', leave=False):
|
896 |
+
sleep(0.01)
|
897 |
+
|
898 |
+
For manual control over positioning (e.g. for multi-processing use),
|
899 |
+
you may specify ``position=n`` where ``n=0`` for the outermost bar,
|
900 |
+
``n=1`` for the next, and so on.
|
901 |
+
However, it's best to check if ``tqdm`` can work without manual ``position``
|
902 |
+
first.
|
903 |
+
|
904 |
+
.. code:: python
|
905 |
+
|
906 |
+
from time import sleep
|
907 |
+
from tqdm import trange, tqdm
|
908 |
+
from multiprocessing import Pool, RLock, freeze_support
|
909 |
+
|
910 |
+
L = list(range(9))
|
911 |
+
|
912 |
+
def progresser(n):
|
913 |
+
interval = 0.001 / (n + 2)
|
914 |
+
total = 5000
|
915 |
+
text = f"#{n}, est. {interval * total:<04.2}s"
|
916 |
+
for _ in trange(total, desc=text, position=n):
|
917 |
+
sleep(interval)
|
918 |
+
|
919 |
+
if __name__ == '__main__':
|
920 |
+
freeze_support() # for Windows support
|
921 |
+
tqdm.set_lock(RLock()) # for managing output contention
|
922 |
+
p = Pool(initializer=tqdm.set_lock, initargs=(tqdm.get_lock(),))
|
923 |
+
p.map(progresser, L)
|
924 |
+
|
925 |
+
Note that in Python 3, ``tqdm.write`` is thread-safe:
|
926 |
+
|
927 |
+
.. code:: python
|
928 |
+
|
929 |
+
from time import sleep
|
930 |
+
from tqdm import tqdm, trange
|
931 |
+
from concurrent.futures import ThreadPoolExecutor
|
932 |
+
|
933 |
+
L = list(range(9))
|
934 |
+
|
935 |
+
def progresser(n):
|
936 |
+
interval = 0.001 / (n + 2)
|
937 |
+
total = 5000
|
938 |
+
text = f"#{n}, est. {interval * total:<04.2}s"
|
939 |
+
for _ in trange(total, desc=text):
|
940 |
+
sleep(interval)
|
941 |
+
if n == 6:
|
942 |
+
tqdm.write("n == 6 completed.")
|
943 |
+
tqdm.write("`tqdm.write()` is thread-safe in py3!")
|
944 |
+
|
945 |
+
if __name__ == '__main__':
|
946 |
+
with ThreadPoolExecutor() as p:
|
947 |
+
p.map(progresser, L)
|
948 |
+
|
949 |
+
Hooks and callbacks
|
950 |
+
~~~~~~~~~~~~~~~~~~~
|
951 |
+
|
952 |
+
``tqdm`` can easily support callbacks/hooks and manual updates.
|
953 |
+
Here's an example with ``urllib``:
|
954 |
+
|
955 |
+
**``urllib.urlretrieve`` documentation**
|
956 |
+
|
957 |
+
| [...]
|
958 |
+
| If present, the hook function will be called once
|
959 |
+
| on establishment of the network connection and once after each block read
|
960 |
+
| thereafter. The hook will be passed three arguments; a count of blocks
|
961 |
+
| transferred so far, a block size in bytes, and the total size of the file.
|
962 |
+
| [...]
|
963 |
+
|
964 |
+
.. code:: python
|
965 |
+
|
966 |
+
import urllib, os
|
967 |
+
from tqdm import tqdm
|
968 |
+
urllib = getattr(urllib, 'request', urllib)
|
969 |
+
|
970 |
+
class TqdmUpTo(tqdm):
|
971 |
+
"""Provides `update_to(n)` which uses `tqdm.update(delta_n)`."""
|
972 |
+
def update_to(self, b=1, bsize=1, tsize=None):
|
973 |
+
"""
|
974 |
+
b : int, optional
|
975 |
+
Number of blocks transferred so far [default: 1].
|
976 |
+
bsize : int, optional
|
977 |
+
Size of each block (in tqdm units) [default: 1].
|
978 |
+
tsize : int, optional
|
979 |
+
Total size (in tqdm units). If [default: None] remains unchanged.
|
980 |
+
"""
|
981 |
+
if tsize is not None:
|
982 |
+
self.total = tsize
|
983 |
+
return self.update(b * bsize - self.n) # also sets self.n = b * bsize
|
984 |
+
|
985 |
+
eg_link = "https://caspersci.uk.to/matryoshka.zip"
|
986 |
+
with TqdmUpTo(unit='B', unit_scale=True, unit_divisor=1024, miniters=1,
|
987 |
+
desc=eg_link.split('/')[-1]) as t: # all optional kwargs
|
988 |
+
urllib.urlretrieve(eg_link, filename=os.devnull,
|
989 |
+
reporthook=t.update_to, data=None)
|
990 |
+
t.total = t.n
|
991 |
+
|
992 |
+
Inspired by `twine#242 <https://github.com/pypa/twine/pull/242>`__.
|
993 |
+
Functional alternative in
|
994 |
+
`examples/tqdm_wget.py <https://github.com/tqdm/tqdm/blob/master/examples/tqdm_wget.py>`__.
|
995 |
+
|
996 |
+
It is recommend to use ``miniters=1`` whenever there is potentially
|
997 |
+
large differences in iteration speed (e.g. downloading a file over
|
998 |
+
a patchy connection).
|
999 |
+
|
1000 |
+
**Wrapping read/write methods**
|
1001 |
+
|
1002 |
+
To measure throughput through a file-like object's ``read`` or ``write``
|
1003 |
+
methods, use ``CallbackIOWrapper``:
|
1004 |
+
|
1005 |
+
.. code:: python
|
1006 |
+
|
1007 |
+
from tqdm.auto import tqdm
|
1008 |
+
from tqdm.utils import CallbackIOWrapper
|
1009 |
+
|
1010 |
+
with tqdm(total=file_obj.size,
|
1011 |
+
unit='B', unit_scale=True, unit_divisor=1024) as t:
|
1012 |
+
fobj = CallbackIOWrapper(t.update, file_obj, "read")
|
1013 |
+
while True:
|
1014 |
+
chunk = fobj.read(chunk_size)
|
1015 |
+
if not chunk:
|
1016 |
+
break
|
1017 |
+
t.reset()
|
1018 |
+
# ... continue to use `t` for something else
|
1019 |
+
|
1020 |
+
Alternatively, use the even simpler ``wrapattr`` convenience function,
|
1021 |
+
which would condense both the ``urllib`` and ``CallbackIOWrapper`` examples
|
1022 |
+
down to:
|
1023 |
+
|
1024 |
+
.. code:: python
|
1025 |
+
|
1026 |
+
import urllib, os
|
1027 |
+
from tqdm import tqdm
|
1028 |
+
|
1029 |
+
eg_link = "https://caspersci.uk.to/matryoshka.zip"
|
1030 |
+
response = getattr(urllib, 'request', urllib).urlopen(eg_link)
|
1031 |
+
with tqdm.wrapattr(open(os.devnull, "wb"), "write",
|
1032 |
+
miniters=1, desc=eg_link.split('/')[-1],
|
1033 |
+
total=getattr(response, 'length', None)) as fout:
|
1034 |
+
for chunk in response:
|
1035 |
+
fout.write(chunk)
|
1036 |
+
|
1037 |
+
The ``requests`` equivalent is nearly identical:
|
1038 |
+
|
1039 |
+
.. code:: python
|
1040 |
+
|
1041 |
+
import requests, os
|
1042 |
+
from tqdm import tqdm
|
1043 |
+
|
1044 |
+
eg_link = "https://caspersci.uk.to/matryoshka.zip"
|
1045 |
+
response = requests.get(eg_link, stream=True)
|
1046 |
+
with tqdm.wrapattr(open(os.devnull, "wb"), "write",
|
1047 |
+
miniters=1, desc=eg_link.split('/')[-1],
|
1048 |
+
total=int(response.headers.get('content-length', 0))) as fout:
|
1049 |
+
for chunk in response.iter_content(chunk_size=4096):
|
1050 |
+
fout.write(chunk)
|
1051 |
+
|
1052 |
+
**Custom callback**
|
1053 |
+
|
1054 |
+
``tqdm`` is known for intelligently skipping unnecessary displays. To make a
|
1055 |
+
custom callback take advantage of this, simply use the return value of
|
1056 |
+
``update()``. This is set to ``True`` if a ``display()`` was triggered.
|
1057 |
+
|
1058 |
+
.. code:: python
|
1059 |
+
|
1060 |
+
from tqdm.auto import tqdm as std_tqdm
|
1061 |
+
|
1062 |
+
def external_callback(*args, **kwargs):
|
1063 |
+
...
|
1064 |
+
|
1065 |
+
class TqdmExt(std_tqdm):
|
1066 |
+
def update(self, n=1):
|
1067 |
+
displayed = super().update(n)
|
1068 |
+
if displayed:
|
1069 |
+
external_callback(**self.format_dict)
|
1070 |
+
return displayed
|
1071 |
+
|
1072 |
+
``asyncio``
|
1073 |
+
~~~~~~~~~~~
|
1074 |
+
|
1075 |
+
Note that ``break`` isn't currently caught by asynchronous iterators.
|
1076 |
+
This means that ``tqdm`` cannot clean up after itself in this case:
|
1077 |
+
|
1078 |
+
.. code:: python
|
1079 |
+
|
1080 |
+
from tqdm.asyncio import tqdm
|
1081 |
+
|
1082 |
+
async for i in tqdm(range(9)):
|
1083 |
+
if i == 2:
|
1084 |
+
break
|
1085 |
+
|
1086 |
+
Instead, either call ``pbar.close()`` manually or use the context manager syntax:
|
1087 |
+
|
1088 |
+
.. code:: python
|
1089 |
+
|
1090 |
+
from tqdm.asyncio import tqdm
|
1091 |
+
|
1092 |
+
with tqdm(range(9)) as pbar:
|
1093 |
+
async for i in pbar:
|
1094 |
+
if i == 2:
|
1095 |
+
break
|
1096 |
+
|
1097 |
+
Pandas Integration
|
1098 |
+
~~~~~~~~~~~~~~~~~~
|
1099 |
+
|
1100 |
+
Due to popular demand we've added support for ``pandas`` -- here's an example
|
1101 |
+
for ``DataFrame.progress_apply`` and ``DataFrameGroupBy.progress_apply``:
|
1102 |
+
|
1103 |
+
.. code:: python
|
1104 |
+
|
1105 |
+
import pandas as pd
|
1106 |
+
import numpy as np
|
1107 |
+
from tqdm import tqdm
|
1108 |
+
|
1109 |
+
df = pd.DataFrame(np.random.randint(0, 100, (100000, 6)))
|
1110 |
+
|
1111 |
+
# Register `pandas.progress_apply` and `pandas.Series.map_apply` with `tqdm`
|
1112 |
+
# (can use `tqdm.gui.tqdm`, `tqdm.notebook.tqdm`, optional kwargs, etc.)
|
1113 |
+
tqdm.pandas(desc="my bar!")
|
1114 |
+
|
1115 |
+
# Now you can use `progress_apply` instead of `apply`
|
1116 |
+
# and `progress_map` instead of `map`
|
1117 |
+
df.progress_apply(lambda x: x**2)
|
1118 |
+
# can also groupby:
|
1119 |
+
# df.groupby(0).progress_apply(lambda x: x**2)
|
1120 |
+
|
1121 |
+
In case you're interested in how this works (and how to modify it for your
|
1122 |
+
own callbacks), see the
|
1123 |
+
`examples <https://github.com/tqdm/tqdm/tree/master/examples>`__
|
1124 |
+
folder or import the module and run ``help()``.
|
1125 |
+
|
1126 |
+
Keras Integration
|
1127 |
+
~~~~~~~~~~~~~~~~~
|
1128 |
+
|
1129 |
+
A ``keras`` callback is also available:
|
1130 |
+
|
1131 |
+
.. code:: python
|
1132 |
+
|
1133 |
+
from tqdm.keras import TqdmCallback
|
1134 |
+
|
1135 |
+
...
|
1136 |
+
|
1137 |
+
model.fit(..., verbose=0, callbacks=[TqdmCallback()])
|
1138 |
+
|
1139 |
+
Dask Integration
|
1140 |
+
~~~~~~~~~~~~~~~~
|
1141 |
+
|
1142 |
+
A ``dask`` callback is also available:
|
1143 |
+
|
1144 |
+
.. code:: python
|
1145 |
+
|
1146 |
+
from tqdm.dask import TqdmCallback
|
1147 |
+
|
1148 |
+
with TqdmCallback(desc="compute"):
|
1149 |
+
...
|
1150 |
+
arr.compute()
|
1151 |
+
|
1152 |
+
# or use callback globally
|
1153 |
+
cb = TqdmCallback(desc="global")
|
1154 |
+
cb.register()
|
1155 |
+
arr.compute()
|
1156 |
+
|
1157 |
+
IPython/Jupyter Integration
|
1158 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
1159 |
+
|
1160 |
+
IPython/Jupyter is supported via the ``tqdm.notebook`` submodule:
|
1161 |
+
|
1162 |
+
.. code:: python
|
1163 |
+
|
1164 |
+
from tqdm.notebook import trange, tqdm
|
1165 |
+
from time import sleep
|
1166 |
+
|
1167 |
+
for i in trange(3, desc='1st loop'):
|
1168 |
+
for j in tqdm(range(100), desc='2nd loop'):
|
1169 |
+
sleep(0.01)
|
1170 |
+
|
1171 |
+
In addition to ``tqdm`` features, the submodule provides a native Jupyter
|
1172 |
+
widget (compatible with IPython v1-v4 and Jupyter), fully working nested bars
|
1173 |
+
and colour hints (blue: normal, green: completed, red: error/interrupt,
|
1174 |
+
light blue: no ETA); as demonstrated below.
|
1175 |
+
|
1176 |
+
|Screenshot-Jupyter1|
|
1177 |
+
|Screenshot-Jupyter2|
|
1178 |
+
|Screenshot-Jupyter3|
|
1179 |
+
|
1180 |
+
The ``notebook`` version supports percentage or pixels for overall width
|
1181 |
+
(e.g.: ``ncols='100%'`` or ``ncols='480px'``).
|
1182 |
+
|
1183 |
+
It is also possible to let ``tqdm`` automatically choose between
|
1184 |
+
console or notebook versions by using the ``autonotebook`` submodule:
|
1185 |
+
|
1186 |
+
.. code:: python
|
1187 |
+
|
1188 |
+
from tqdm.autonotebook import tqdm
|
1189 |
+
tqdm.pandas()
|
1190 |
+
|
1191 |
+
Note that this will issue a ``TqdmExperimentalWarning`` if run in a notebook
|
1192 |
+
since it is not meant to be possible to distinguish between ``jupyter notebook``
|
1193 |
+
and ``jupyter console``. Use ``auto`` instead of ``autonotebook`` to suppress
|
1194 |
+
this warning.
|
1195 |
+
|
1196 |
+
Note that notebooks will display the bar in the cell where it was created.
|
1197 |
+
This may be a different cell from the one where it is used.
|
1198 |
+
If this is not desired, either
|
1199 |
+
|
1200 |
+
- delay the creation of the bar to the cell where it must be displayed, or
|
1201 |
+
- create the bar with ``display=False``, and in a later cell call
|
1202 |
+
``display(bar.container)``:
|
1203 |
+
|
1204 |
+
.. code:: python
|
1205 |
+
|
1206 |
+
from tqdm.notebook import tqdm
|
1207 |
+
pbar = tqdm(..., display=False)
|
1208 |
+
|
1209 |
+
.. code:: python
|
1210 |
+
|
1211 |
+
# different cell
|
1212 |
+
display(pbar.container)
|
1213 |
+
|
1214 |
+
The ``keras`` callback has a ``display()`` method which can be used likewise:
|
1215 |
+
|
1216 |
+
.. code:: python
|
1217 |
+
|
1218 |
+
from tqdm.keras import TqdmCallback
|
1219 |
+
cbk = TqdmCallback(display=False)
|
1220 |
+
|
1221 |
+
.. code:: python
|
1222 |
+
|
1223 |
+
# different cell
|
1224 |
+
cbk.display()
|
1225 |
+
model.fit(..., verbose=0, callbacks=[cbk])
|
1226 |
+
|
1227 |
+
Another possibility is to have a single bar (near the top of the notebook)
|
1228 |
+
which is constantly re-used (using ``reset()`` rather than ``close()``).
|
1229 |
+
For this reason, the notebook version (unlike the CLI version) does not
|
1230 |
+
automatically call ``close()`` upon ``Exception``.
|
1231 |
+
|
1232 |
+
.. code:: python
|
1233 |
+
|
1234 |
+
from tqdm.notebook import tqdm
|
1235 |
+
pbar = tqdm()
|
1236 |
+
|
1237 |
+
.. code:: python
|
1238 |
+
|
1239 |
+
# different cell
|
1240 |
+
iterable = range(100)
|
1241 |
+
pbar.reset(total=len(iterable)) # initialise with new `total`
|
1242 |
+
for i in iterable:
|
1243 |
+
pbar.update()
|
1244 |
+
pbar.refresh() # force print final status but don't `close()`
|
1245 |
+
|
1246 |
+
Custom Integration
|
1247 |
+
~~~~~~~~~~~~~~~~~~
|
1248 |
+
|
1249 |
+
To change the default arguments (such as making ``dynamic_ncols=True``),
|
1250 |
+
simply use built-in Python magic:
|
1251 |
+
|
1252 |
+
.. code:: python
|
1253 |
+
|
1254 |
+
from functools import partial
|
1255 |
+
from tqdm import tqdm as std_tqdm
|
1256 |
+
tqdm = partial(std_tqdm, dynamic_ncols=True)
|
1257 |
+
|
1258 |
+
For further customisation,
|
1259 |
+
``tqdm`` may be inherited from to create custom callbacks (as with the
|
1260 |
+
``TqdmUpTo`` example `above <#hooks-and-callbacks>`__) or for custom frontends
|
1261 |
+
(e.g. GUIs such as notebook or plotting packages). In the latter case:
|
1262 |
+
|
1263 |
+
1. ``def __init__()`` to call ``super().__init__(..., gui=True)`` to disable
|
1264 |
+
terminal ``status_printer`` creation.
|
1265 |
+
2. Redefine: ``close()``, ``clear()``, ``display()``.
|
1266 |
+
|
1267 |
+
Consider overloading ``display()`` to use e.g.
|
1268 |
+
``self.frontend(**self.format_dict)`` instead of ``self.sp(repr(self))``.
|
1269 |
+
|
1270 |
+
Some submodule examples of inheritance:
|
1271 |
+
|
1272 |
+
- `tqdm/notebook.py <https://github.com/tqdm/tqdm/blob/master/tqdm/notebook.py>`__
|
1273 |
+
- `tqdm/gui.py <https://github.com/tqdm/tqdm/blob/master/tqdm/gui.py>`__
|
1274 |
+
- `tqdm/tk.py <https://github.com/tqdm/tqdm/blob/master/tqdm/tk.py>`__
|
1275 |
+
- `tqdm/contrib/slack.py <https://github.com/tqdm/tqdm/blob/master/tqdm/contrib/slack.py>`__
|
1276 |
+
- `tqdm/contrib/discord.py <https://github.com/tqdm/tqdm/blob/master/tqdm/contrib/discord.py>`__
|
1277 |
+
- `tqdm/contrib/telegram.py <https://github.com/tqdm/tqdm/blob/master/tqdm/contrib/telegram.py>`__
|
1278 |
+
|
1279 |
+
Dynamic Monitor/Meter
|
1280 |
+
~~~~~~~~~~~~~~~~~~~~~
|
1281 |
+
|
1282 |
+
You can use a ``tqdm`` as a meter which is not monotonically increasing.
|
1283 |
+
This could be because ``n`` decreases (e.g. a CPU usage monitor) or ``total``
|
1284 |
+
changes.
|
1285 |
+
|
1286 |
+
One example would be recursively searching for files. The ``total`` is the
|
1287 |
+
number of objects found so far, while ``n`` is the number of those objects which
|
1288 |
+
are files (rather than folders):
|
1289 |
+
|
1290 |
+
.. code:: python
|
1291 |
+
|
1292 |
+
from tqdm import tqdm
|
1293 |
+
import os.path
|
1294 |
+
|
1295 |
+
def find_files_recursively(path, show_progress=True):
|
1296 |
+
files = []
|
1297 |
+
# total=1 assumes `path` is a file
|
1298 |
+
t = tqdm(total=1, unit="file", disable=not show_progress)
|
1299 |
+
if not os.path.exists(path):
|
1300 |
+
raise IOError("Cannot find:" + path)
|
1301 |
+
|
1302 |
+
def append_found_file(f):
|
1303 |
+
files.append(f)
|
1304 |
+
t.update()
|
1305 |
+
|
1306 |
+
def list_found_dir(path):
|
1307 |
+
"""returns os.listdir(path) assuming os.path.isdir(path)"""
|
1308 |
+
listing = os.listdir(path)
|
1309 |
+
# subtract 1 since a "file" we found was actually this directory
|
1310 |
+
t.total += len(listing) - 1
|
1311 |
+
# fancy way to give info without forcing a refresh
|
1312 |
+
t.set_postfix(dir=path[-10:], refresh=False)
|
1313 |
+
t.update(0) # may trigger a refresh
|
1314 |
+
return listing
|
1315 |
+
|
1316 |
+
def recursively_search(path):
|
1317 |
+
if os.path.isdir(path):
|
1318 |
+
for f in list_found_dir(path):
|
1319 |
+
recursively_search(os.path.join(path, f))
|
1320 |
+
else:
|
1321 |
+
append_found_file(path)
|
1322 |
+
|
1323 |
+
recursively_search(path)
|
1324 |
+
t.set_postfix(dir=path)
|
1325 |
+
t.close()
|
1326 |
+
return files
|
1327 |
+
|
1328 |
+
Using ``update(0)`` is a handy way to let ``tqdm`` decide when to trigger a
|
1329 |
+
display refresh to avoid console spamming.
|
1330 |
+
|
1331 |
+
Writing messages
|
1332 |
+
~~~~~~~~~~~~~~~~
|
1333 |
+
|
1334 |
+
This is a work in progress (see
|
1335 |
+
`#737 <https://github.com/tqdm/tqdm/issues/737>`__).
|
1336 |
+
|
1337 |
+
Since ``tqdm`` uses a simple printing mechanism to display progress bars,
|
1338 |
+
you should not write any message in the terminal using ``print()`` while
|
1339 |
+
a progressbar is open.
|
1340 |
+
|
1341 |
+
To write messages in the terminal without any collision with ``tqdm`` bar
|
1342 |
+
display, a ``.write()`` method is provided:
|
1343 |
+
|
1344 |
+
.. code:: python
|
1345 |
+
|
1346 |
+
from tqdm.auto import tqdm, trange
|
1347 |
+
from time import sleep
|
1348 |
+
|
1349 |
+
bar = trange(10)
|
1350 |
+
for i in bar:
|
1351 |
+
# Print using tqdm class method .write()
|
1352 |
+
sleep(0.1)
|
1353 |
+
if not (i % 3):
|
1354 |
+
tqdm.write("Done task %i" % i)
|
1355 |
+
# Can also use bar.write()
|
1356 |
+
|
1357 |
+
By default, this will print to standard output ``sys.stdout``. but you can
|
1358 |
+
specify any file-like object using the ``file`` argument. For example, this
|
1359 |
+
can be used to redirect the messages writing to a log file or class.
|
1360 |
+
|
1361 |
+
Redirecting writing
|
1362 |
+
~~~~~~~~~~~~~~~~~~~
|
1363 |
+
|
1364 |
+
If using a library that can print messages to the console, editing the library
|
1365 |
+
by replacing ``print()`` with ``tqdm.write()`` may not be desirable.
|
1366 |
+
In that case, redirecting ``sys.stdout`` to ``tqdm.write()`` is an option.
|
1367 |
+
|
1368 |
+
To redirect ``sys.stdout``, create a file-like class that will write
|
1369 |
+
any input string to ``tqdm.write()``, and supply the arguments
|
1370 |
+
``file=sys.stdout, dynamic_ncols=True``.
|
1371 |
+
|
1372 |
+
A reusable canonical example is given below:
|
1373 |
+
|
1374 |
+
.. code:: python
|
1375 |
+
|
1376 |
+
from time import sleep
|
1377 |
+
import contextlib
|
1378 |
+
import sys
|
1379 |
+
from tqdm import tqdm
|
1380 |
+
from tqdm.contrib import DummyTqdmFile
|
1381 |
+
|
1382 |
+
|
1383 |
+
@contextlib.contextmanager
|
1384 |
+
def std_out_err_redirect_tqdm():
|
1385 |
+
orig_out_err = sys.stdout, sys.stderr
|
1386 |
+
try:
|
1387 |
+
sys.stdout, sys.stderr = map(DummyTqdmFile, orig_out_err)
|
1388 |
+
yield orig_out_err[0]
|
1389 |
+
# Relay exceptions
|
1390 |
+
except Exception as exc:
|
1391 |
+
raise exc
|
1392 |
+
# Always restore sys.stdout/err if necessary
|
1393 |
+
finally:
|
1394 |
+
sys.stdout, sys.stderr = orig_out_err
|
1395 |
+
|
1396 |
+
def some_fun(i):
|
1397 |
+
print("Fee, fi, fo,".split()[i])
|
1398 |
+
|
1399 |
+
# Redirect stdout to tqdm.write() (don't forget the `as save_stdout`)
|
1400 |
+
with std_out_err_redirect_tqdm() as orig_stdout:
|
1401 |
+
# tqdm needs the original stdout
|
1402 |
+
# and dynamic_ncols=True to autodetect console width
|
1403 |
+
for i in tqdm(range(3), file=orig_stdout, dynamic_ncols=True):
|
1404 |
+
sleep(.5)
|
1405 |
+
some_fun(i)
|
1406 |
+
|
1407 |
+
# After the `with`, printing is restored
|
1408 |
+
print("Done!")
|
1409 |
+
|
1410 |
+
Redirecting ``logging``
|
1411 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
1412 |
+
|
1413 |
+
Similar to ``sys.stdout``/``sys.stderr`` as detailed above, console ``logging``
|
1414 |
+
may also be redirected to ``tqdm.write()``.
|
1415 |
+
|
1416 |
+
Warning: if also redirecting ``sys.stdout``/``sys.stderr``, make sure to
|
1417 |
+
redirect ``logging`` first if needed.
|
1418 |
+
|
1419 |
+
Helper methods are available in ``tqdm.contrib.logging``. For example:
|
1420 |
+
|
1421 |
+
.. code:: python
|
1422 |
+
|
1423 |
+
import logging
|
1424 |
+
from tqdm import trange
|
1425 |
+
from tqdm.contrib.logging import logging_redirect_tqdm
|
1426 |
+
|
1427 |
+
LOG = logging.getLogger(__name__)
|
1428 |
+
|
1429 |
+
if __name__ == '__main__':
|
1430 |
+
logging.basicConfig(level=logging.INFO)
|
1431 |
+
with logging_redirect_tqdm():
|
1432 |
+
for i in trange(9):
|
1433 |
+
if i == 4:
|
1434 |
+
LOG.info("console logging redirected to `tqdm.write()`")
|
1435 |
+
# logging restored
|
1436 |
+
|
1437 |
+
Monitoring thread, intervals and miniters
|
1438 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
1439 |
+
|
1440 |
+
``tqdm`` implements a few tricks to increase efficiency and reduce overhead.
|
1441 |
+
|
1442 |
+
- Avoid unnecessary frequent bar refreshing: ``mininterval`` defines how long
|
1443 |
+
to wait between each refresh. ``tqdm`` always gets updated in the background,
|
1444 |
+
but it will display only every ``mininterval``.
|
1445 |
+
- Reduce number of calls to check system clock/time.
|
1446 |
+
- ``mininterval`` is more intuitive to configure than ``miniters``.
|
1447 |
+
A clever adjustment system ``dynamic_miniters`` will automatically adjust
|
1448 |
+
``miniters`` to the amount of iterations that fit into time ``mininterval``.
|
1449 |
+
Essentially, ``tqdm`` will check if it's time to print without actually
|
1450 |
+
checking time. This behaviour can be still be bypassed by manually setting
|
1451 |
+
``miniters``.
|
1452 |
+
|
1453 |
+
However, consider a case with a combination of fast and slow iterations.
|
1454 |
+
After a few fast iterations, ``dynamic_miniters`` will set ``miniters`` to a
|
1455 |
+
large number. When iteration rate subsequently slows, ``miniters`` will
|
1456 |
+
remain large and thus reduce display update frequency. To address this:
|
1457 |
+
|
1458 |
+
- ``maxinterval`` defines the maximum time between display refreshes.
|
1459 |
+
A concurrent monitoring thread checks for overdue updates and forces one
|
1460 |
+
where necessary.
|
1461 |
+
|
1462 |
+
The monitoring thread should not have a noticeable overhead, and guarantees
|
1463 |
+
updates at least every 10 seconds by default.
|
1464 |
+
This value can be directly changed by setting the ``monitor_interval`` of
|
1465 |
+
any ``tqdm`` instance (i.e. ``t = tqdm.tqdm(...); t.monitor_interval = 2``).
|
1466 |
+
The monitor thread may be disabled application-wide by setting
|
1467 |
+
``tqdm.tqdm.monitor_interval = 0`` before instantiation of any ``tqdm`` bar.
|
1468 |
+
|
1469 |
+
|
1470 |
+
Merch
|
1471 |
+
-----
|
1472 |
+
|
1473 |
+
You can buy `tqdm branded merch <https://tqdm.github.io/merch>`__ now!
|
1474 |
+
|
1475 |
+
Contributions
|
1476 |
+
-------------
|
1477 |
+
|
1478 |
+
|GitHub-Commits| |GitHub-Issues| |GitHub-PRs| |OpenHub-Status| |GitHub-Contributions| |CII Best Practices|
|
1479 |
+
|
1480 |
+
All source code is hosted on `GitHub <https://github.com/tqdm/tqdm>`__.
|
1481 |
+
Contributions are welcome.
|
1482 |
+
|
1483 |
+
See the
|
1484 |
+
`CONTRIBUTING <https://github.com/tqdm/tqdm/blob/master/CONTRIBUTING.md>`__
|
1485 |
+
file for more information.
|
1486 |
+
|
1487 |
+
Developers who have made significant contributions, ranked by *SLoC*
|
1488 |
+
(surviving lines of code,
|
1489 |
+
`git fame <https://github.com/casperdcl/git-fame>`__ ``-wMC --excl '\.(png|gif|jpg)$'``),
|
1490 |
+
are:
|
1491 |
+
|
1492 |
+
==================== ======================================================== ==== ================================
|
1493 |
+
Name ID SLoC Notes
|
1494 |
+
==================== ======================================================== ==== ================================
|
1495 |
+
Casper da Costa-Luis `casperdcl <https://github.com/casperdcl>`__ ~80% primary maintainer |Gift-Casper|
|
1496 |
+
Stephen Larroque `lrq3000 <https://github.com/lrq3000>`__ ~9% team member
|
1497 |
+
Martin Zugnoni `martinzugnoni <https://github.com/martinzugnoni>`__ ~3%
|
1498 |
+
Daniel Ecer `de-code <https://github.com/de-code>`__ ~2%
|
1499 |
+
Richard Sheridan `richardsheridan <https://github.com/richardsheridan>`__ ~1%
|
1500 |
+
Guangshuo Chen `chengs <https://github.com/chengs>`__ ~1%
|
1501 |
+
Helio Machado `0x2b3bfa0 <https://github.com/0x2b3bfa0>`__ ~1%
|
1502 |
+
Kyle Altendorf `altendky <https://github.com/altendky>`__ <1%
|
1503 |
+
Noam Yorav-Raphael `noamraph <https://github.com/noamraph>`__ <1% original author
|
1504 |
+
Matthew Stevens `mjstevens777 <https://github.com/mjstevens777>`__ <1%
|
1505 |
+
Hadrien Mary `hadim <https://github.com/hadim>`__ <1% team member
|
1506 |
+
Mikhail Korobov `kmike <https://github.com/kmike>`__ <1% team member
|
1507 |
+
==================== ======================================================== ==== ================================
|
1508 |
+
|
1509 |
+
Ports to Other Languages
|
1510 |
+
~~~~~~~~~~~~~~~~~~~~~~~~
|
1511 |
+
|
1512 |
+
A list is available on
|
1513 |
+
`this wiki page <https://github.com/tqdm/tqdm/wiki/tqdm-ports>`__.
|
1514 |
+
|
1515 |
+
|
1516 |
+
LICENCE
|
1517 |
+
-------
|
1518 |
+
|
1519 |
+
Open Source (OSI approved): |LICENCE|
|
1520 |
+
|
1521 |
+
Citation information: |DOI|
|
1522 |
+
|
1523 |
+
|README-Hits| (Since 19 May 2016)
|
1524 |
+
|
1525 |
+
.. |Logo| image:: https://tqdm.github.io/img/logo.gif
|
1526 |
+
.. |Screenshot| image:: https://tqdm.github.io/img/tqdm.gif
|
1527 |
+
.. |Video| image:: https://tqdm.github.io/img/video.jpg
|
1528 |
+
:target: https://tqdm.github.io/video
|
1529 |
+
.. |Slides| image:: https://tqdm.github.io/img/slides.jpg
|
1530 |
+
:target: https://tqdm.github.io/PyData2019/slides.html
|
1531 |
+
.. |Merch| image:: https://tqdm.github.io/img/merch.jpg
|
1532 |
+
:target: https://tqdm.github.io/merch
|
1533 |
+
.. |Build-Status| image:: https://img.shields.io/github/actions/workflow/status/tqdm/tqdm/test.yml?branch=master&label=tqdm&logo=GitHub
|
1534 |
+
:target: https://github.com/tqdm/tqdm/actions/workflows/test.yml
|
1535 |
+
.. |Coverage-Status| image:: https://img.shields.io/coveralls/github/tqdm/tqdm/master?logo=coveralls
|
1536 |
+
:target: https://coveralls.io/github/tqdm/tqdm
|
1537 |
+
.. |Branch-Coverage-Status| image:: https://codecov.io/gh/tqdm/tqdm/branch/master/graph/badge.svg
|
1538 |
+
:target: https://codecov.io/gh/tqdm/tqdm
|
1539 |
+
.. |Codacy-Grade| image:: https://app.codacy.com/project/badge/Grade/3f965571598f44549c7818f29cdcf177
|
1540 |
+
:target: https://www.codacy.com/gh/tqdm/tqdm/dashboard
|
1541 |
+
.. |CII Best Practices| image:: https://bestpractices.coreinfrastructure.org/projects/3264/badge
|
1542 |
+
:target: https://bestpractices.coreinfrastructure.org/projects/3264
|
1543 |
+
.. |GitHub-Status| image:: https://img.shields.io/github/tag/tqdm/tqdm.svg?maxAge=86400&logo=github&logoColor=white
|
1544 |
+
:target: https://github.com/tqdm/tqdm/releases
|
1545 |
+
.. |GitHub-Forks| image:: https://img.shields.io/github/forks/tqdm/tqdm.svg?logo=github&logoColor=white
|
1546 |
+
:target: https://github.com/tqdm/tqdm/network
|
1547 |
+
.. |GitHub-Stars| image:: https://img.shields.io/github/stars/tqdm/tqdm.svg?logo=github&logoColor=white
|
1548 |
+
:target: https://github.com/tqdm/tqdm/stargazers
|
1549 |
+
.. |GitHub-Commits| image:: https://img.shields.io/github/commit-activity/y/tqdm/tqdm.svg?logo=git&logoColor=white
|
1550 |
+
:target: https://github.com/tqdm/tqdm/graphs/commit-activity
|
1551 |
+
.. |GitHub-Issues| image:: https://img.shields.io/github/issues-closed/tqdm/tqdm.svg?logo=github&logoColor=white
|
1552 |
+
:target: https://github.com/tqdm/tqdm/issues?q=
|
1553 |
+
.. |GitHub-PRs| image:: https://img.shields.io/github/issues-pr-closed/tqdm/tqdm.svg?logo=github&logoColor=white
|
1554 |
+
:target: https://github.com/tqdm/tqdm/pulls
|
1555 |
+
.. |GitHub-Contributions| image:: https://img.shields.io/github/contributors/tqdm/tqdm.svg?logo=github&logoColor=white
|
1556 |
+
:target: https://github.com/tqdm/tqdm/graphs/contributors
|
1557 |
+
.. |GitHub-Updated| image:: https://img.shields.io/github/last-commit/tqdm/tqdm/master.svg?logo=github&logoColor=white&label=pushed
|
1558 |
+
:target: https://github.com/tqdm/tqdm/pulse
|
1559 |
+
.. |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
|
1560 |
+
:target: https://cdcl.ml/sponsor
|
1561 |
+
.. |Versions| image:: https://img.shields.io/pypi/v/tqdm.svg
|
1562 |
+
:target: https://tqdm.github.io/releases
|
1563 |
+
.. |PyPI-Downloads| image:: https://img.shields.io/pypi/dm/tqdm.svg?label=pypi%20downloads&logo=PyPI&logoColor=white
|
1564 |
+
:target: https://pepy.tech/project/tqdm
|
1565 |
+
.. |Py-Versions| image:: https://img.shields.io/pypi/pyversions/tqdm.svg?logo=python&logoColor=white
|
1566 |
+
:target: https://pypi.org/project/tqdm
|
1567 |
+
.. |Conda-Forge-Status| image:: https://img.shields.io/conda/v/conda-forge/tqdm.svg?label=conda-forge&logo=conda-forge
|
1568 |
+
:target: https://anaconda.org/conda-forge/tqdm
|
1569 |
+
.. |Snapcraft| image:: https://img.shields.io/badge/snap-install-82BEA0.svg?logo=snapcraft
|
1570 |
+
:target: https://snapcraft.io/tqdm
|
1571 |
+
.. |Docker| image:: https://img.shields.io/badge/docker-pull-blue.svg?logo=docker&logoColor=white
|
1572 |
+
:target: https://hub.docker.com/r/tqdm/tqdm
|
1573 |
+
.. |Libraries-Rank| image:: https://img.shields.io/librariesio/sourcerank/pypi/tqdm.svg?logo=koding&logoColor=white
|
1574 |
+
:target: https://libraries.io/pypi/tqdm
|
1575 |
+
.. |Libraries-Dependents| image:: https://img.shields.io/librariesio/dependent-repos/pypi/tqdm.svg?logo=koding&logoColor=white
|
1576 |
+
:target: https://github.com/tqdm/tqdm/network/dependents
|
1577 |
+
.. |OpenHub-Status| image:: https://www.openhub.net/p/tqdm/widgets/project_thin_badge?format=gif
|
1578 |
+
:target: https://www.openhub.net/p/tqdm?ref=Thin+badge
|
1579 |
+
.. |awesome-python| image:: https://awesome.re/mentioned-badge.svg
|
1580 |
+
:target: https://github.com/vinta/awesome-python
|
1581 |
+
.. |LICENCE| image:: https://img.shields.io/pypi/l/tqdm.svg
|
1582 |
+
:target: https://raw.githubusercontent.com/tqdm/tqdm/master/LICENCE
|
1583 |
+
.. |DOI| image:: https://img.shields.io/badge/DOI-10.5281/zenodo.595120-blue.svg
|
1584 |
+
:target: https://doi.org/10.5281/zenodo.595120
|
1585 |
+
.. |binder-demo| image:: https://mybinder.org/badge_logo.svg
|
1586 |
+
:target: https://mybinder.org/v2/gh/tqdm/tqdm/master?filepath=DEMO.ipynb
|
1587 |
+
.. |Screenshot-Jupyter1| image:: https://tqdm.github.io/img/jupyter-1.gif
|
1588 |
+
.. |Screenshot-Jupyter2| image:: https://tqdm.github.io/img/jupyter-2.gif
|
1589 |
+
.. |Screenshot-Jupyter3| image:: https://tqdm.github.io/img/jupyter-3.gif
|
1590 |
+
.. |README-Hits| image:: https://caspersci.uk.to/cgi-bin/hits.cgi?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
|
1591 |
+
:target: https://caspersci.uk.to/cgi-bin/hits.cgi?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
|
.cache/pip/http-v2/f/b/e/3/a/fbe3a5eb3735a745707ab3bf39e17d76ea29c7cd1eaa7763f11e1766
ADDED
Binary file (1.17 kB). View file
|
|
.cache/pip/selfcheck/241e69162522ccf5846a2f42ebc24b17464915a155679666b89a9f31
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"key":"/usr","last_check":"2024-09-25T18:27:19.029638+00:00","pypi_version":"24.2"}
|
.jupyter/jupyter_nbconvert_config.json
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"version": 1,
|
3 |
+
"Exporter": {
|
4 |
+
"extra_template_paths": [
|
5 |
+
".",
|
6 |
+
"/usr/local/lib/python3.10/dist-packages/jupyter_contrib_nbextensions/templates"
|
7 |
+
],
|
8 |
+
"preprocessors": [
|
9 |
+
"jupyter_contrib_nbextensions.nbconvert_support.CodeFoldingPreprocessor",
|
10 |
+
"jupyter_contrib_nbextensions.nbconvert_support.PyMarkdownPreprocessor"
|
11 |
+
]
|
12 |
+
}
|
13 |
+
}
|
.jupyter/jupyter_notebook_config.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"NotebookApp": {
|
3 |
+
"nbserver_extensions": {
|
4 |
+
"jupyter_nbextensions_configurator": true
|
5 |
+
}
|
6 |
+
}
|
7 |
+
}
|
.jupyter/lab/workspaces/default-37a8.jupyterlab-workspace
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"data":{"layout-restorer:data":{"main":{"dock":{"type":"tab-area","currentIndex":0,"widgets":["terminal:1","editor:train.py","terminal:2"]},"current":"terminal:1"},"down":{"size":0,"widgets":[]},"left":{"collapsed":false,"visible":true,"current":"filebrowser","widgets":["filebrowser","running-sessions","@jupyterlab/toc:plugin","extensionmanager.main-view"],"widgetStates":{"jp-running-sessions":{"sizes":[0.25,0.25,0.25,0.25],"expansionStates":[false,false,false,false]},"extensionmanager.main-view":{"sizes":[0.3333333333333333,0.3333333333333333,0.3333333333333333],"expansionStates":[false,false,false]}}},"right":{"collapsed":true,"visible":true,"widgets":["jp-property-inspector","debugger-sidebar"],"widgetStates":{"jp-debugger-sidebar":{"sizes":[0.2,0.2,0.2,0.2,0.2],"expansionStates":[false,false,false,false,false]}}},"relativeSizes":[0.17564730580825752,0.8243526941917425,0],"top":{"simpleVisibility":true}},"terminal:1":{"data":{"name":"1"}},"terminal:2":{"data":{"name":"2"}},"editor:train.py":{"data":{"path":"train.py","factory":"Editor"}},"file-browser-filebrowser:cwd":{"path":""}},"metadata":{"id":"default"}}
|
.local/share/jupyter/nbextensions/autoscroll/main.js
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
define([
|
2 |
+
'jquery',
|
3 |
+
'base/js/namespace',
|
4 |
+
'base/js/events',
|
5 |
+
'notebook/js/outputarea',
|
6 |
+
'notebook/js/codecell'
|
7 |
+
], function (
|
8 |
+
$,
|
9 |
+
IPython,
|
10 |
+
events,
|
11 |
+
oa,
|
12 |
+
codecell
|
13 |
+
) {
|
14 |
+
"use strict";
|
15 |
+
|
16 |
+
var prev_threshold = 0;
|
17 |
+
var action_full_name; // will be set when registering the action
|
18 |
+
|
19 |
+
// define default values for config parameters
|
20 |
+
var params = {
|
21 |
+
autoscroll_set_on_load : false,
|
22 |
+
autoscroll_starting_threshold : 100,
|
23 |
+
autoscroll_show_selector : true,
|
24 |
+
autoscroll_show_button : false
|
25 |
+
};
|
26 |
+
|
27 |
+
// update params with any specified in the server's config file
|
28 |
+
var update_params = function() {
|
29 |
+
var config = IPython.notebook.config;
|
30 |
+
for (var key in params) {
|
31 |
+
if (config.data.hasOwnProperty(key))
|
32 |
+
params[key] = config.data[key];
|
33 |
+
}
|
34 |
+
};
|
35 |
+
|
36 |
+
var initAutoScroll = function() {
|
37 |
+
if (IPython.notebook === undefined) return;
|
38 |
+
var cells = IPython.notebook.get_cells();
|
39 |
+
var ncells = IPython.notebook.ncells();
|
40 |
+
for (var i=0; i<ncells; i++) {
|
41 |
+
var cell = cells[i];
|
42 |
+
if ((cell instanceof codecell.CodeCell)) {
|
43 |
+
cell.scroll_output()
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
};
|
48 |
+
|
49 |
+
var toggle_output_autoscroll = function() {
|
50 |
+
if (oa.OutputArea.auto_scroll_threshold > 0) {
|
51 |
+
prev_threshold = oa.OutputArea.auto_scroll_threshold;
|
52 |
+
oa.OutputArea.auto_scroll_threshold = -1;
|
53 |
+
}
|
54 |
+
else {
|
55 |
+
var new_thr = prev_threshold <= 0 ? 1 : prev_threshold;
|
56 |
+
prev_threshold = oa.OutputArea.auto_scroll_threshold;
|
57 |
+
oa.OutputArea.auto_scroll_threshold = new_thr;
|
58 |
+
}
|
59 |
+
|
60 |
+
$('#autoscroll_selector').val(oa.OutputArea.auto_scroll_threshold);
|
61 |
+
|
62 |
+
$('.btn[data-jupyter-action="' + action_full_name + '"]')
|
63 |
+
.toggleClass('active', oa.OutputArea.auto_scroll_threshold <= 0)
|
64 |
+
.blur();
|
65 |
+
initAutoScroll();
|
66 |
+
};
|
67 |
+
|
68 |
+
var initialize = function() {
|
69 |
+
update_params();
|
70 |
+
|
71 |
+
var thresholds = [-1, 1, 10, 20, 50, 100, 200, 500, 1000];
|
72 |
+
|
73 |
+
if (params.autoscroll_set_on_load) {
|
74 |
+
var st = params.autoscroll_starting_threshold;
|
75 |
+
oa.OutputArea.auto_scroll_threshold = st;
|
76 |
+
if (thresholds.includes(st) === false) thresholds.push(st);
|
77 |
+
}
|
78 |
+
|
79 |
+
thresholds.sort(function(a, b){ return a-b; });
|
80 |
+
|
81 |
+
if (params.autoscroll_show_selector) {
|
82 |
+
var select = $('<select id="autoscroll_selector"/>')
|
83 |
+
.addClass("form-control select-xs");
|
84 |
+
select.change(function() {
|
85 |
+
oa.OutputArea.auto_scroll_threshold = parseInt($(this).val(), 10);
|
86 |
+
$('.btn[data-jupyter-action="' + action_full_name + '"]')
|
87 |
+
.toggleClass('active', oa.OutputArea.auto_scroll_threshold <= 0);
|
88 |
+
$(this).blur();
|
89 |
+
});
|
90 |
+
for (var i in thresholds) {
|
91 |
+
var thr = thresholds[i];
|
92 |
+
select.append($('<option/>').attr('value', thr).text(thr));
|
93 |
+
}
|
94 |
+
select.find('option[value="100"]').text('100 (default)');
|
95 |
+
select.find('option[value="-1"]').text('no-scroll');
|
96 |
+
IPython.toolbar.element.append(
|
97 |
+
$('<label class="navbar-text"/>').text('auto-scroll threshold:')
|
98 |
+
).append(select);
|
99 |
+
select.val(oa.OutputArea.auto_scroll_threshold);
|
100 |
+
}
|
101 |
+
|
102 |
+
if (params.autoscroll_show_button) {
|
103 |
+
IPython.toolbar.add_buttons_group([action_full_name]);
|
104 |
+
}
|
105 |
+
initAutoScroll();
|
106 |
+
};
|
107 |
+
|
108 |
+
var load_ipython_extension = function () {
|
109 |
+
var prefix = 'auto';
|
110 |
+
var action_name = 'toggle-output-autoscroll';
|
111 |
+
var action = {
|
112 |
+
icon: 'fa-close',
|
113 |
+
help: 'Toggle output auto-scrolling',
|
114 |
+
help_index : 'zz',
|
115 |
+
handler : toggle_output_autoscroll
|
116 |
+
};
|
117 |
+
|
118 |
+
action_full_name = IPython.keyboard_manager.actions.register(action, action_name, prefix);
|
119 |
+
|
120 |
+
IPython.notebook.config.loaded.then(initialize);
|
121 |
+
events.on("notebook_loaded.Notebook", function(){
|
122 |
+
initAutoScroll();
|
123 |
+
});
|
124 |
+
|
125 |
+
};
|
126 |
+
|
127 |
+
return {
|
128 |
+
load_ipython_extension : load_ipython_extension
|
129 |
+
};
|
130 |
+
});
|
.local/share/jupyter/nbextensions/cell_filter/cell_filter.js
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* cell_filter.js
|
3 |
+
* An extension that allows you to filter cells by tags. Keywords entered into the search bar separated by spaces joins them with logical AND.
|
4 |
+
*
|
5 |
+
*
|
6 |
+
* @version 0.1.0
|
7 |
+
* @author Benjamin Ellenberger, https://github.com/benelot
|
8 |
+
* @updated 2018-02-16
|
9 |
+
*
|
10 |
+
*
|
11 |
+
*/
|
12 |
+
define([
|
13 |
+
'require',
|
14 |
+
'jqueryui',
|
15 |
+
'base/js/namespace',
|
16 |
+
'base/js/utils',
|
17 |
+
'services/config'
|
18 |
+
], function (
|
19 |
+
requirejs,
|
20 |
+
$,
|
21 |
+
Jupyter,
|
22 |
+
utils
|
23 |
+
) {
|
24 |
+
'use strict';
|
25 |
+
|
26 |
+
function filterRows (filterText, caseSensitive, useRegex) {
|
27 |
+
var input = $('#filterkeyword');
|
28 |
+
var btnRegex = $('#filterisreg');
|
29 |
+
|
30 |
+
filterText = filterText !== undefined ? filterText : input.val();
|
31 |
+
useRegex = useRegex !== undefined ? useRegex : btnRegex.attr('aria-pressed') === 'true';
|
32 |
+
caseSensitive = caseSensitive !== undefined ? caseSensitive : $('#filtercase').attr('aria-pressed') === 'true';
|
33 |
+
|
34 |
+
if (!useRegex) {
|
35 |
+
// escape any regex special chars
|
36 |
+
filterText = filterText.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
|
37 |
+
var keywords = filterText.split(' '); // get all space separated keywords
|
38 |
+
filterText = '.*'; // catch all stuff before the keywords
|
39 |
+
keywords.forEach(function(keyword){ // find all keywords we are looking for with regex (?=.*keyword)
|
40 |
+
filterText += '(?=.*' + keyword + ')';
|
41 |
+
});
|
42 |
+
filterText += '.*'; // catch all stuff after the keywords
|
43 |
+
}
|
44 |
+
var matchExpr;
|
45 |
+
try {
|
46 |
+
matchExpr = new RegExp(filterText, caseSensitive ? '' : 'i'); // prepare regex
|
47 |
+
}
|
48 |
+
catch (err) {
|
49 |
+
// do nothing, error is handled based on undefined matchExpr
|
50 |
+
}
|
51 |
+
|
52 |
+
var invalidRegex = matchExpr === undefined; // indicate invalid regex
|
53 |
+
btnRegex.toggleClass('btn-danger', invalidRegex);
|
54 |
+
btnRegex.toggleClass('btn-default', !invalidRegex);
|
55 |
+
btnRegex.closest('.form-group').toggleClass('has-error has-feedback', invalidRegex);
|
56 |
+
|
57 |
+
Jupyter.notebook.get_cells().forEach(function (cell, idx, cells) { // toggle visibility of cells depending on their tags
|
58 |
+
var tags = cell.metadata.tags || [];
|
59 |
+
tags = tags.join(' ');
|
60 |
+
if(filterText === ".*(?=.*).*" || filterText === "" || tags.search(matchExpr) !== -1 && tags.length > 0){ // empty filter or match expression on non-zero tags
|
61 |
+
cell.element.show(); // cell.element.style.display = '';
|
62 |
+
//cell.element.find("div.inner_cell").show();
|
63 |
+
}
|
64 |
+
else{
|
65 |
+
cell.element.hide(); // cell.element.style.display = 'none';
|
66 |
+
//cell.element.find("div.inner_cell").hide();
|
67 |
+
}
|
68 |
+
});
|
69 |
+
}
|
70 |
+
|
71 |
+
function filterRowsDefaultParams () {
|
72 |
+
return filterRows();
|
73 |
+
}
|
74 |
+
|
75 |
+
function load_ipython_extension () {
|
76 |
+
|
77 |
+
var form_tgrp = $('<div/>')
|
78 |
+
.addClass('btn-group') // insert a top form-group to make the form appear next to the buttons
|
79 |
+
.appendTo('#maintoolbar-container');
|
80 |
+
|
81 |
+
var frm_grp = $('<div/>')
|
82 |
+
.addClass('form-group') // insert a form-group
|
83 |
+
.css('margin-bottom', 0)
|
84 |
+
.appendTo(form_tgrp);
|
85 |
+
|
86 |
+
var grp = $('<div/>')
|
87 |
+
.addClass('input-group') // insert an input-group
|
88 |
+
.appendTo(frm_grp);
|
89 |
+
|
90 |
+
$('<input/>') // insert search bar
|
91 |
+
.attr('type', 'text')
|
92 |
+
.addClass('form-control input-sm')
|
93 |
+
.attr('title', 'Keyword for filtering cells by tags')
|
94 |
+
.attr('id', 'filterkeyword')
|
95 |
+
.attr('placeholder', 'Cell Tag Filter')
|
96 |
+
.css('font-weight', 'bold')
|
97 |
+
.css('width', '70%')
|
98 |
+
.css('height', '24px')
|
99 |
+
.on('focus', function (evt) { Jupyter.notebook.keyboard_manager.disable();})
|
100 |
+
.on('blur', function (evt) { Jupyter.notebook.keyboard_manager.enable();})
|
101 |
+
.appendTo(grp);
|
102 |
+
|
103 |
+
$('<button/>')
|
104 |
+
.attr('type', 'button') // insert regex button
|
105 |
+
.attr('id', 'filterisreg')
|
106 |
+
.addClass('btn btn-default btn-sm')
|
107 |
+
.attr('data-toggle', 'button')
|
108 |
+
.css('font-weight', 'bold')
|
109 |
+
.attr('title', 'Use regex (JavaScript regex syntax)')
|
110 |
+
.text('.*')
|
111 |
+
.on('click', function (evt) { setTimeout(filterRowsDefaultParams); })
|
112 |
+
.appendTo(grp);
|
113 |
+
|
114 |
+
$('<button/>') // insert case sensitive button
|
115 |
+
.attr('type', 'button')
|
116 |
+
.attr('id', 'filtercase')
|
117 |
+
.addClass('btn btn-default btn-sm')
|
118 |
+
.attr('data-toggle', 'button')
|
119 |
+
.attr('tabindex', '0')
|
120 |
+
.attr('title', 'Match case')
|
121 |
+
.css('font-weight', 'bold')
|
122 |
+
.text('Aa')
|
123 |
+
.on('click', function (evt) { setTimeout(filterRowsDefaultParams); })
|
124 |
+
.appendTo(grp);
|
125 |
+
|
126 |
+
$('#filterkeyword').on('keyup', filterRowsDefaultParams); // trigger filtering right with typing
|
127 |
+
}
|
128 |
+
|
129 |
+
return {
|
130 |
+
load_ipython_extension : load_ipython_extension
|
131 |
+
};
|
132 |
+
|
133 |
+
});
|
.local/share/jupyter/nbextensions/code_font_size/code_font_size.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Type: IPython Notebook Extension
|
2 |
+
Name: Code Font Size
|
3 |
+
Link: README.md
|
4 |
+
Description: Adds toolbar buttons to increase and decrease code's font size.
|
5 |
+
This is useful, for example, when projecting the notebook.
|
6 |
+
Main: code_font_size.js
|
7 |
+
Compatibility: 4.x, 5.x
|
.local/share/jupyter/nbextensions/code_prettify/2to3.yaml
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Type: Jupyter Notebook Extension
|
2 |
+
Name: 2to3 Converter
|
3 |
+
Description: Converts python2 code in a notebook's code cell to python3 code
|
4 |
+
Link: README_2to3.md
|
5 |
+
Main: 2to3.js
|
6 |
+
Compatibility: Jupyter 4.x, 5.x
|
7 |
+
Parameters:
|
8 |
+
|
9 |
+
- name: 2to3.add_toolbar_button
|
10 |
+
description: Add a toolbar button to convert the selected cell(s)
|
11 |
+
input_type: checkbox
|
12 |
+
default: true
|
13 |
+
|
14 |
+
- name: 2to3.button_icon
|
15 |
+
description: |
|
16 |
+
Toolbar button icon: a font-awesome class defining the icon used for the
|
17 |
+
toolbar button. See https://fontawesome.com/icons for available icons.
|
18 |
+
input_type: text
|
19 |
+
default: 'fa-space-shuttle'
|
20 |
+
|
21 |
+
- name: 2to3.button_label
|
22 |
+
description: Toolbar button label text
|
23 |
+
input_type: text
|
24 |
+
default: 'Code converter'
|
25 |
+
|
26 |
+
- name: 2to3.register_hotkey
|
27 |
+
description: Register a hotkey to convert the selected cell(s)
|
28 |
+
input_type: checkbox
|
29 |
+
default: true
|
30 |
+
|
31 |
+
- name: 2to3.hotkeys.process_selected
|
32 |
+
description: Hotkey to convert the selected cell(s) from python2 to python3
|
33 |
+
input_type: hotkey
|
34 |
+
default: 'Ctrl-M'
|
35 |
+
|
36 |
+
- name: 2to3.hotkeys.process_all
|
37 |
+
description: Hotkey to convert the whole notebook
|
38 |
+
input_type: hotkey
|
39 |
+
default: 'Ctrl-Shift-M'
|
40 |
+
|
41 |
+
- name: 2to3.show_alerts_for_not_supported_kernel
|
42 |
+
description: Show alerts if the kernel is not supported
|
43 |
+
input_type: checkbox
|
44 |
+
default: false
|
45 |
+
|
46 |
+
- name: 2to3.show_alerts_for_errors
|
47 |
+
description: Show alerts for errors in the kernel converting calls
|
48 |
+
input_type: checkbox
|
49 |
+
default: true
|
50 |
+
|
51 |
+
- name: 2to3.kernel_config_map_json
|
52 |
+
description: |
|
53 |
+
kernel_config_map_json:
|
54 |
+
json defining library calls required to load the kernel-specific
|
55 |
+
converting modules, and the prefix & postfix for the json-format string
|
56 |
+
required to make the converting call.
|
57 |
+
input_type: textarea
|
58 |
+
default: |
|
59 |
+
{
|
60 |
+
"python": {
|
61 |
+
"library": "import lib2to3.refactor, json\n_2to3_refactoring_tool = lib2to3.refactor.RefactoringTool(\n set(lib2to3.refactor.get_fixers_from_package('lib2to3.fixes')))\ndef _2to3_refactor_cell(src):\n try:\n tree = _2to3_refactoring_tool.refactor_string(src+'\\n', '<dummy_name>')\n except (lib2to3.pgen2.parse.ParseError, lib2to3.pgen2.tokenize.TokenError):\n return src \n else:\n return str(tree)[:-1]",
|
62 |
+
"prefix": "print(json.dumps(refactor_cell(u",
|
63 |
+
"postfix": ")))"
|
64 |
+
}
|
65 |
+
}
|
.local/share/jupyter/nbextensions/code_prettify/README_2to3.md
ADDED
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
A 2to3 converter
|
2 |
+
================
|
3 |
+
|
4 |
+
This nbextension converts python2 code in notebook code cells to python3 code.
|
5 |
+
|
6 |
+
Under the hood, it uses a call to the current notebook kernel to reformat the
|
7 |
+
code.
|
8 |
+
The conversion run by the kernel uses Python's standard-library [lib2to3]
|
9 |
+
module.
|
10 |
+
|
11 |
+
The nbextension provides
|
12 |
+
|
13 |
+
- a toolbar button (configurable to be added or not)
|
14 |
+
|
15 |
+
- a keyboard shortcut for reformatting the current code-cell (default shortcut
|
16 |
+
is `Ctrl-M`, can also be configured not to add the keyboard shortcut).
|
17 |
+
|
18 |
+
- a keyboard shortcut for reformatting the whole notebook (default shortcut
|
19 |
+
is `Ctrl-Shift-M`, can also be configured not to add the keyboard shortcut).
|
20 |
+
|
21 |
+
Syntax needs to be correct, but the nbextension may be able to point out basic
|
22 |
+
syntax errors.
|
23 |
+
|
24 |
+
![](demo_2to3.gif)
|
25 |
+
|
26 |
+
|
27 |
+
Options
|
28 |
+
-------
|
29 |
+
|
30 |
+
All options are provided by the [KerneExecOnCells library] - see the
|
31 |
+
[internals] section below for details.
|
32 |
+
There are a few nbextension-wide options, configurable using the
|
33 |
+
[jupyter_nbextensions_configurator] or by editing the `notebook` section config
|
34 |
+
file directly.
|
35 |
+
The options are as follows:
|
36 |
+
|
37 |
+
- `2to3.add_toolbar_button`:
|
38 |
+
Whether to add a toolbar button to transform the selected cell(s).
|
39 |
+
Defaults to `true`.
|
40 |
+
|
41 |
+
- `2to3.button_icon`:
|
42 |
+
A font-awesome class defining the icon used for the toolbar button and
|
43 |
+
actions. See [fontawesome] for available icon classes.
|
44 |
+
Defaults to `fa-legal`.
|
45 |
+
|
46 |
+
- `2to3.button_label`:
|
47 |
+
Toolbar button label text. Also used in the actions' help text.
|
48 |
+
Defaults to `Convert Python 2 to 3`.
|
49 |
+
|
50 |
+
- `2to3.register_hotkey`:
|
51 |
+
Whether to register hotkeys to transform the selected cell(s)/whole notebook.
|
52 |
+
Defaults to `true`.
|
53 |
+
|
54 |
+
- `2to3.hotkeys.process_all`:
|
55 |
+
Hotkey to use to transform all the code cells in the notebook.
|
56 |
+
Defaults to `Ctrl-Shift-L`.
|
57 |
+
|
58 |
+
- `2to3.hotkeys.process_selected`:
|
59 |
+
Hotkey to use to transform the selected cell(s).
|
60 |
+
Defaults to `Ctrl-L`.
|
61 |
+
|
62 |
+
- `2to3.show_alerts_for_not_supported_kernel`:
|
63 |
+
Whether to show alerts if the kernel is not supported.
|
64 |
+
Defaults to `false`.
|
65 |
+
|
66 |
+
- `2to3.show_alerts_for_errors`:
|
67 |
+
Whether to show alerts for errors in the kernel calls.
|
68 |
+
Defaults to `true`.
|
69 |
+
|
70 |
+
- `2to3.kernel_config_map_json`:
|
71 |
+
The value of this key is a string which can be parsed into a json object
|
72 |
+
giving the config for each kernel language.
|
73 |
+
|
74 |
+
The following give the per-kernel options of the parsed json, using the
|
75 |
+
language key `python `:
|
76 |
+
|
77 |
+
* `2to3.kernel_config_map_json.python.library`:
|
78 |
+
String to execute in the kernel in order to load any necessary kernel
|
79 |
+
libraries.
|
80 |
+
|
81 |
+
* `2to3.kernel_config_map_json.python.replacements_json_to_kernel`:
|
82 |
+
a list of pairs of strings, used as arguments to javascript's
|
83 |
+
`String.replace(from, to)` to translate from a json string into a valid
|
84 |
+
representation of the same string in the kernel language. Since json
|
85 |
+
strings are particularly simple, this can often (as with the python
|
86 |
+
language) be left as the default, an empty list.
|
87 |
+
|
88 |
+
* `2to3.kernel_config_map_json.python.prefix` and
|
89 |
+
`2to3.kernel_config_map_json.python.postfix`:
|
90 |
+
Strings added as bookends to the kernel string (translated from the json
|
91 |
+
string using the replacements above) to make up the kernel prettifier call
|
92 |
+
kernel's prettifier libraries.
|
93 |
+
|
94 |
+
* `2to3.kernel_config_map_json.python.trim_formatted_text`:
|
95 |
+
Whether to trim whitespace from the transformed cell text. Since jupyter
|
96 |
+
cells don't usually have leading or trailing whitespace, the default
|
97 |
+
behaviour is to trim the transformed text, in order to prevent the
|
98 |
+
transform adding extra newlines at the end (a common behaviour for source
|
99 |
+
files, where having a trailing newline is often considered good practice).
|
100 |
+
|
101 |
+
|
102 |
+
Internals
|
103 |
+
---------
|
104 |
+
|
105 |
+
Under the hood, this nbextension uses the [KerneExecOnCells library], a shared
|
106 |
+
library for creating Jupyter nbextensions which transform code cell text using
|
107 |
+
calls to the active kernel.
|
108 |
+
|
109 |
+
See the [shared README] for the internal model used by the nbextension.
|
110 |
+
|
111 |
+
History
|
112 |
+
-------
|
113 |
+
|
114 |
+
The project was forked by [@EWouters] from [@jfbercher]'s [code_prettify],
|
115 |
+
retaining most of the code.
|
116 |
+
|
117 |
+
It has since been altered to use the [KerneExecOnCells library], a shared
|
118 |
+
library for creating Jupyter nbextensions which transform code cell text using
|
119 |
+
calls to the active kernel.
|
120 |
+
|
121 |
+
The 2to3 conversion's kernel-side python code is based on [2to3_nb.py] by
|
122 |
+
[@takluyver] and [@fperez].
|
123 |
+
|
124 |
+
It could be extended to use the [futurize] functions so it can convert both
|
125 |
+
ways.
|
126 |
+
|
127 |
+
[2to3_nb.py]: https://gist.github.com/takluyver/c8839593c615bb2f6e80
|
128 |
+
[@EWouters]: https://github.com/EWouters
|
129 |
+
[@fperez]: https://github.com/fperez
|
130 |
+
[@jfbercher]: https://github.com/jfbercher
|
131 |
+
[@takluyver]: https://github.com/takluyver
|
132 |
+
[code_prettify]: https://github.com/jfbercher/code_prettify
|
133 |
+
[futurize]: http://python-future.org/automatic_conversion.html
|
134 |
+
[fontawesome]: https://fontawesome.com/icons
|
135 |
+
[internals]: #Internals
|
136 |
+
[jupyter_nbextensions_configurator]: https://github.com/Jupyter-contrib/jupyter_nbextensions_configurator
|
137 |
+
[KerneExecOnCells library]: README.md
|
138 |
+
[lib2to3]: https://docs.python.org/3/library/2to3.html#module-lib2to3
|
139 |
+
[shared README]: README.md
|
.local/share/jupyter/nbextensions/code_prettify/README_isort.md
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Sort imports using isort
|
2 |
+
|
3 |
+
This nbextension sorts imports in notebook code cells.
|
4 |
+
|
5 |
+
Under the hood, it uses a call to the current notebook kernel to reformat the code. The conversion run by the kernel uses Python's package [isort](https://github.com/timothycrosley/isort) by [Timothy Edmund Crosley](https://github.com/timothycrosley).
|
6 |
+
|
7 |
+
The nbextension provides
|
8 |
+
|
9 |
+
- a toolbar button (configurable to be added or not)
|
10 |
+
|
11 |
+
**pre-requisites:** of course, you must have the corresponding package installed:
|
12 |
+
|
13 |
+
```
|
14 |
+
pip install isort [--user]
|
15 |
+
```
|
16 |
+
|
17 |
+
## Options
|
18 |
+
|
19 |
+
All options are provided by the [KerneExecOnCells library](kernel_exec_on_cell.js). There are a few nbextension-wide options, configurable using the [jupyter_nbextensions_configurator](https://github.com/Jupyter-contrib/jupyter_nbextensions_configurator) or by editing the `notebook` section config file directly. The options are as follows:
|
20 |
+
|
21 |
+
- `isort.add_toolbar_button`: Whether to add a toolbar button to transform the selected cell(s). Defaults to `true`.
|
22 |
+
|
23 |
+
- `isort.button_icon`:
|
24 |
+
A font-awesome class defining the icon used for the toolbar button and actions.
|
25 |
+
See [fontawesome] for available icon classes.
|
26 |
+
Defaults to `fa-sort`.
|
27 |
+
|
28 |
+
- `isort.show_alerts_for_not_supported_kernel`:
|
29 |
+
Whether to show alerts if the kernel is not supported.
|
30 |
+
Defaults to `false`.
|
31 |
+
|
32 |
+
- `isort.show_alerts_for_errors`: Whether to show alerts for errors in the kernel calls. Defaults to `false`.
|
33 |
+
|
34 |
+
- `isort.button_label`: Toolbar button label text. Also used in the actions' help text. Defaults to `Sort imports with isort`.
|
35 |
+
|
36 |
+
- `isort.kernel_config_map_json`: The value of this key is a string which can be parsed into a json object giving the config for each kernel language.
|
37 |
+
|
38 |
+
## Internals
|
39 |
+
|
40 |
+
Under the hood, this nbextension uses the [kerneexeconcells library](kernel_exec_on_cell.js), a shared library for creating Jupyter nbextensions which transform code cell text using calls to the active kernel.
|
41 |
+
|
42 |
+
See the [shared README](README.md) and [kerneexeconcells library](kernel_exec_on_cell.js) for the internal model used by the nbextension.
|
43 |
+
|
44 |
+
[fontawesome]: https://fontawesome.com/icons
|
.local/share/jupyter/nbextensions/code_prettify/autopep8.js
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright (c) Jupyter-Contrib Team.
|
2 |
+
// Distributed under the terms of the Modified BSD License.
|
3 |
+
// Authors: @kenkoooo, @jfbercher and @jcb91
|
4 |
+
|
5 |
+
define(['./kernel_exec_on_cell'], function(kernel_exec_on_cell) {
|
6 |
+
'use strict';
|
7 |
+
|
8 |
+
var mod_name = 'autopep8';
|
9 |
+
|
10 |
+
// gives default settings
|
11 |
+
var cfg = {
|
12 |
+
add_toolbar_button: true,
|
13 |
+
hotkeys: {
|
14 |
+
process_selected: 'Alt-A',
|
15 |
+
process_all: 'Alt-Shift-A',
|
16 |
+
},
|
17 |
+
register_hotkey: true,
|
18 |
+
show_alerts_for_errors: true,
|
19 |
+
button_icon: 'fa-cog',
|
20 |
+
button_label: 'Prettify (using autopep8)',
|
21 |
+
kbd_shortcut_text: 'Prettify' // ' current cell(s)'
|
22 |
+
};
|
23 |
+
|
24 |
+
cfg.kernel_config_map = { // map of parameters for supported kernels
|
25 |
+
"python": {
|
26 |
+
"library": "import json\nimport autopep8",
|
27 |
+
"prefix": "print(json.dumps(autopep8.fix_code(u",
|
28 |
+
"postfix": ")))"
|
29 |
+
}
|
30 |
+
};
|
31 |
+
|
32 |
+
var prettifier = new kernel_exec_on_cell.define_plugin(mod_name, cfg);
|
33 |
+
prettifier.load_ipython_extension = prettifier.initialize_plugin;
|
34 |
+
return prettifier;
|
35 |
+
|
36 |
+
});
|