Skip to main content

Smartbar

Project description

SmartBar

SmartBar is a powerful, automatic, and extensible progress bar library for Python, built with smart I/O tracking and multi-threading support.
It provides real-time progress, ETA, speed tracking, and works seamlessly with file and network I/O using with blocks — no manual .update() needed.

Features

  • Thread-safe and concurrent
  • Supports multiple bars simultaneously
  • Automatically wraps open() and requests.get() to track progress
  • Works with both reading and writing
  • Smart ETA and speed calculation
  • Custom bar styles and position control
  • Pause, resume and ignore support
  • Friendly with context manager usage

Installation

pip install smartbar

Example Usages

from smartbar import SmartBar
import requests

with SmartBar("Downloading", length=40) as bar:
    r = requests.get("https://example.com/file", stream=True)
    for chunk in r.iter_content(1024):
        pass  # progress auto-tracked
from smartbar import SmartBar
import requests
import time

BAR1 = f"%(DESC). \033[48;5;214m[%(BAR)]\033[0m %(CUR)/%(TOTAL) (%(PERCENT)%) | %(SPEED) | ETA: %(ETA)"
BAR2 = f"%(DESC).. \033[48;5;214m[%(BAR)]\033[0m %(CUR)/%(TOTAL) (%(PERCENT)%) | %(SPEED) | ETA: %(ETA)"
BAR3 = f"%(DESC)... \033[48;5;214m[%(BAR)]\033[0m %(CUR)/%(TOTAL) (%(PERCENT)%) | %(SPEED) | ETA: %(ETA)" 

url = "https://download.samplelib.com/mp4/sample-20s.mp4"

with SmartBar("Downloading", custom_bar_output=BAR1) as bar:
    response = requests.get(url, stream=True)
    with open("video.mp4", "wb") as f:
        stime = time.time()
        for chunk in response.iter_content(chunk_size=8192):
            if chunk:
                f.write(chunk)
            if time.time() - stime > 1:
                if bar.custom_bar_output == BAR1:
                    bar.custom_bar_output = BAR2
                elif bar.custom_bar_output == BAR2:
                    bar.custom_bar_output = BAR3
                else:
                    bar.custom_bar_output = BAR1
                stime = time.time()

Disable auto-track

import time

BAR1 = "%(DESC). {} SEC \033[48;5;214m[%(BAR)]\033[0m %(CUR)/%(TOTAL) (%(PERCENT)%) | %(SPEED) | ETA: %(ETA)"
BAR2 = "%(DESC).. {} SEC \033[48;5;214m[%(BAR)]\033[0m %(CUR)/%(TOTAL) (%(PERCENT)%) | %(SPEED) | ETA: %(ETA)"
BAR3 = "%(DESC)... {} SEC \033[48;5;214m[%(BAR)]\033[0m %(CUR)/%(TOTAL) (%(PERCENT)%) | %(SPEED) | ETA: %(ETA)" 

SEC = 10

with SmartBar("Waiting", auto_bar=False, mode="items") as bar: # Manuel bar
    STIME = time.time()
    ctime = time.time()
    bar.total = SEC
    while True:
        if time.time() - ctime > 1:
            if bar.custom_bar_output == BAR1:
                bar.custom_bar_output = BAR2.format(max(0, abs(int(time.time() - STIME) - 10)))
            elif bar.custom_bar_output == BAR2:
                bar.custom_bar_output = BAR3.format(max(0, abs(int(time.time() - STIME) - 10)))
            else:
                bar.custom_bar_output = BAR1.format(max(0, abs(int(time.time() - STIME) - 10)))
            bar.add(time.time() - ctime)
            ctime = time.time()
            

Pause, Resume & Ignore

bar.pause()
# some time later...
bar.resume()

bar.ignore(r)  # disables tracking for a specific response or file

Author

lama2923
GitHub: https://github.com/lama2923

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smartbar-1.0.4.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smartbar-1.0.4-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file smartbar-1.0.4.tar.gz.

File metadata

  • Download URL: smartbar-1.0.4.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.1

File hashes

Hashes for smartbar-1.0.4.tar.gz
Algorithm Hash digest
SHA256 8221ceb52f9d713689ac7f8a51d0166676d5016b164acf5df26c1fad78a82ad3
MD5 c475baa6af133bb3dce00238716b8012
BLAKE2b-256 f329000b1c802bb650802dfc61c41046263d258daf71c3ab9634b150e438cb6f

See more details on using hashes here.

File details

Details for the file smartbar-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: smartbar-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.1

File hashes

Hashes for smartbar-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0f3086bbf0221c0dc5a6e5ea8fcd38f8efe7a6c4476d60b35ab987e64991b2ee
MD5 77673acad8ef219984df3ee35e368599
BLAKE2b-256 28ed1309b44153f46fbc218441ef82b154371d954b9faf7375f6f152af46d94b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page