Simple library that allows you to add a progress bar to your console output.
Project description
ProgressPrinter
Progress Bar:
For the full example see examples_progress_bar.py and examples_byte_progress_bar.py
A first really bare version of a html documentation is available here
This will be edited in the next days to make things clearer.
ProgressBar Examples
from time import sleep
from ProgressPrinter import ProgressBar
def ex1():
pb1 = ProgressBar(100, '%', pre='Downloading file', post='Download finished', length=25)
pb1.print_progress() # Prints the initial empty progress bar
for mb in range(1, 101):
pb1.print_progress(mb)
sleep(0.15)
Downloading file
[========================>] - Finished 100 % of 100 %
Download finished
def ex2():
pb2 = ProgressBar(500, 'MB', pre='Downloading file', post='Download finished', head='#')
pb2.print_progress() # Prints the initial empty progress bar
for mb in range(1, 501):
pb2.print_progress(mb)
sleep(0.02)
Downloading file
[=================================================#] - Finished 500 MB of 500 MB
Download finished
def ex3():
pb3 = ProgressBar(1000.12, 'MB', pre='Downloading file', post='Download finished', length=100)
pb3.print_progress() # Prints the initial empty progress bar
for mb in range(1, 1001):
if mb != 1000 and mb % 2 == 0:
mb = mb + 0.5
elif mb != 1000:
mb = mb + 0.25
else:
mb = mb + 0.12
pb3.print_progress(mb)
sleep(0.025)
Downloading file
[===================================================================================================>] - Finished 1000.12 MB of 1000.12 MB
Download finished
def ex4():
pb4 = ProgressBar(5, 'files', pre='Deleting files', post='Finished!', length=25, empty='*', fill='#')
pb4.print_progress() # Prints the initial empty progress bar
for file in range(1, 6):
pp4.print_progress(file, pre="Deleting file file{}.txt".format(file))
sleep(1)
Deleting files
Deleting file file1.txt
Deleting file file2.txt
Deleting file file3.txt
Deleting file file4.txt
Deleting file file5.txt
[########################>] - Finished 5 files of 5 files
Finished!
def ex5():
with open('example.txt', 'r') as f:
pb5 = ProgressBar(len(f.readlines()), 'lines', pre="Reading lines from file {}".format(f.name), post='Finished reading file!')
f.seek(0) # Return to start of line after obtaining line count
pb5.print_progress() # Prints the initial empty progress bar
for lineno, line in enumerate(f, start=1):
pb5.print_progress(lineno, pre=line.replace('\n', ''))
sleep(1)
Reading lines from file example.txt
Line 1
Line 2
Line 3
Line 4
...
[=================================================>] - Finished 5 lines of 5 lines
Finished reading file!
ByteProgressBar Example
import requests
from ProgressPrinter import ByteProgressBar
def ex1():
# The ByteProgressBar is a extension of the normal progress bar that supports automatic unit conversion
# from bytes, the base unit you will work with most of the time, to KB, MB, etc.
# This for example is useful when downloading or working with a file (see example below)
#
# UNCOMMENT TO LINK YOU WANT TO USE FOR THE TEST DOWNLOAD
# -------------------------------------------------------
# 100MB.bin [100 MB] - Auto conversion to MB
# link = 'https://speed.hetzner.de/100MB.bin'
# -------------------------------------------------------------------------------------------
# Linux Mint Cinnamon x64.iso [ca. 1.87 GB] - Auto conversion to GB
link = 'http://mirrors.evowise.com/linuxmint/stable/19.2/linuxmint-19.2-cinnamon-64bit.iso'
# -------------------------------------------------------------------------------------------
file_name = link.split('/')[-1]
with open(file_name, 'wb') as f:
response = requests.get(link, stream=True)
byte_size = int(response.headers.get('content-length'))
if byte_size is None:
f.write(response.content)
else:
# Set to ByteProgressBar.UNITS.AUTO to automatically interfere a fitting unit from the byte size
# -----------------------------------------------------------------------------------------------
# Supported values: ByteProgressBar.UNITS.{BYTES, KILOBYTES, MEGABYTES, GIGABYTES, TERABYTES, AUTO}
bpb1 = ByteProgressBar(byte_size, ByteProgressBar.UNITS.AUTO, pre='Downloading {} from {}'
.format(file_name, link), post='Finished download!')
bpb1.print_progress()
loaded_bytes = 0
for chunk in response.iter_content(chunk_size=1048576): # 1 MB
loaded_bytes += len(chunk)
f.write(chunk)
bpb1.print_progress(loaded_bytes)
Downloading linuxmint-19.2-cinnamon-64bit.iso from http://mirrors.evowise.com/linuxmint/stable/19.2/linuxmint-19.2-cinnamon-64bit.iso
[======> ] - Finished 0.27 GB of 1.87 GB
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ProgressPrinter-0.1.1.tar.gz
(5.2 kB
view details)
Built Distribution
File details
Details for the file ProgressPrinter-0.1.1.tar.gz
.
File metadata
- Download URL: ProgressPrinter-0.1.1.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bd17de391dab898f4b423bc9a78479f0856ff2ad65a868ac70bd974d1e5cbc0 |
|
MD5 | 7b66d4a82da54cede2678038957fe9a5 |
|
BLAKE2b-256 | 2cd2c6c23305804aab174e5374f8846d34a65bd9028ca69c98fc98ee0f478995 |
File details
Details for the file ProgressPrinter-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: ProgressPrinter-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bfa35125390a6412dc7e3c267a93273c2c21f9fd3b266634c3fc89a86c4fb8b |
|
MD5 | 2c5d9d634a8543f3b47d47bbc148eb90 |
|
BLAKE2b-256 | 97dc6f918127310301b98a9cf51efe16d5635ae1654e1a0c5bd3d68d2c3fa509 |