https://github.com/aweirddev/holdon
A lightweight Python progress bar library with a simple API.
https://github.com/aweirddev/holdon
Last synced: about 1 year ago
JSON representation
A lightweight Python progress bar library with a simple API.
- Host: GitHub
- URL: https://github.com/aweirddev/holdon
- Owner: AWeirdDev
- License: mit
- Created: 2024-02-24T14:21:07.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-25T06:50:25.000Z (over 2 years ago)
- Last Synced: 2025-02-23T11:36:15.512Z (over 1 year ago)
- Language: Python
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# holdon
Holdon, pronounced "hold'n," is a lightweight Python progress bar library with a simple API.
```haskell
$ pip install holdon
```
## Get Started
Holdon is like [tqdm](https://pypi.org/project/tqdm), just wrap `progress()` around an iterator and we're good to go.
```python
import time
from holdon import progress
for i in progress(range(100)):
time.sleep(0.1)
```
```python
23.0% ━━━╸━━━━━━━━━━━━━━━━ 23 / 100 (9.9it/s)
```
If you do not have any iterator, you can use class `RawProgress()` and update everything manually. To learn more, refer to the documentation below.
## Documentation
Minimal, lol.
### def progress()
```python
progress(
iterator: Iterator,
*,
width: Optional[int] = None,
size: Optional[int] = None,
unit: Literal["it", "bytes"] = "it"
) -> Iterator[Any]
```
Creates a progress bar.
**Example:**
You can wrap `progress()` around any iterator:
```python
for i in progress(range(100)):
... # do your work here
```
You can also wrap it around a custom iterator, but you'll need to specify its total iterations.
```python
words = ["cheese", "is", "good", "but", "i'm", "lactose", "intolerant"]
def word_it():
for word in words:
yield word + " "
for word in progress(word_it(), size=len(words)):
... # do your work here
```
**Args:**
- iterator (`Iterator`): The iterator. For instance, `range` or `list`.
- width (`int`, *optional*): Width of the progress bar. Defaults to 50.
- size (`int`, *optional*): Size of the iterator or the `len()` of the iterator.
- unit (`Literal["it", "bytes"]`): Unit. Could be one of: "it" (iterations) or "bytes" (bytes).
### class RawProgress
Attributes
- const fmt (`str`): Progress bar format.
- slots width (`int`): Progress bar width.
- slots size (`int`): Total iterations as "size."
- slots unit (`Literal["it", "bytes"]`): Unit. Could be one of: "it" (iterations) or "bytes" (bytes).
```python
__init__(
self,
width: int = 50,
size: int = 100,
unit: Literal["it", "bytes"] = "it"
)
```
The progress bar.
**Example:**
A minimal example:
```python
rp = RawProgress()
for i in range(500):
rp.advance(1)
```
You can also change the `unit` parameter to `"bytes"` and specify the total content length (see [`requests`](https://pypi.org/project/requests)) to indicate download progress:
```python
rp = RawProgress(
unit="bytes",
size=int(http_response.headers['Content-Length'])
)
for chunk in http_response.iter_content():
rp.advance(len(chunk))
```
**Args:**
- width (`int`): Progress bar width.
- size (`int`): Total iterations as "size."
- unit (`Literal["it", "bytes"]`): Unit. Could be one of: "it" (iterations) or "bytes" (bytes).
#### def RawProgress.advance()
```python
advance(self, i: int = 1) -> None
```
Advance.
**Args:**
- i (`int`): Advance size.
#### def RawProgress.render()
```python
render(self) -> None
```
Renders the progress bar.
***
(c) 2024 AWeirdDev