Socket
Socket
Sign inDemoInstall

pyloaders

Package Overview
Dependencies
0
Maintainers
1
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pyloaders

Basic animated ASCII loaders for Python scripts


Maintainers
1

Readme

pyloaders

Basic animated ASCII loaders for Python scripts. Python 2 & 3 compatible.

  • Spinning Loader
  • Text Loader
  • Bar Loader
  • Progress Loader

Installation

pip install pyloaders
From Source
git clone https://gitlab.com/ml394/pyloaders.git
cd pyloaders
python setup.py install

Usage

All loaders are declared by calling LoaderClass(<arguments>)

Arguments
OptionDescriptionTypeChoicesDefaultValid For
textText displayed while loadingstr'Loading'Text, Spinning
sizeFull width of loaderstrsmall, medium, large'medium'Text, Bar, Progress
characterASCII value used in loaderstr. = * > ~ # @ $ + ! ? ,'.' / '='Text, Bar, Progress
speedTime between loader paintsfloat.25Text, Spinning, Bar
durationRuntime of fixed loader, in secondsint10Text, Spinning, Bar
directionInitial direction of moving loaderstrltr, rtl'ltr'Text, Bar
animationContinuous or oscillating movementstrloop, bounce'loop'Text, Bar
colourTerminal colour support requiredstrblue, green, yellow, redNoneALL
styleTerminal styles support requiredstrheader, bold, underlineNoneALL
complete_textText displayed after loader endsstr'Done!'ALL
startProgress loader start positionint0Progress
totalProgress loader total countint100Progress

Indeterminate

Available Classes: SpinningLoader, TextLoader, BarLoader

Run as threads which can be started and stopped dynamically by you at any stage.

  • To start a loader, call its start() method.
  • After you have completed your tasks, call the loader's stop() method to terminate the thread.
  • If you have set a fixed duration of the loader, call the run() method to run the loader for the set amount of time.
Threaded
from loaders import TextLoader

loader = TextLoader()
loader.start()
# Perform some tasks
loader.stop()
Fixed Duration
from loaders import TextLoader

fixed_loader = TextLoader(duration=10)
fixed_loader.run() # Pauses program execution and runs loader for 10s

Output

/ Loading...        # SpinningLoader

.....Loading...     # TextLoader

|   ======    |     # BarLoader

Remember: Don't try to start more than one loader at the same time!

Determinate

Available Classes: ProgressLoader

Used to measure the completion progress of a loop or function.

When you initialize a ProgressLoader object, you should specify the total number of iterations that will be performed in your loop as the total argument.

On each iteration, call the loader's progress(n) method, where n is the current iteration count, to update the progress bar in the terminal.

from loaders import ProgressLoader

loader = ProgressLoader(total=10)
for i in range(10):
    # Perform some task each loop
    loader.progress(i)

Output

|==========          | 50%

Remember: Don't print anything to the console while the loader is running!

Bash

New in version 0.0.5

You can now start a loader for shell commands

$ load some --shell command
[    ========    ]

Tests

There is a small test suite that uses the pytest module.

  1. Clone the repository
  2. Install pytest and dependencies
  3. Run pytest from project folder
git clone https://gitlab.com/ml394/pyloaders.git
cd pyloaders
pip install -r requirements.txt
pytest

Examples

An visual example can be performed by running example.py from the project directory.

This will run a suite of example loaders specified in the file for 5s each. By default, the indeterminate examples are run on fixed durations. To run them as threads, use the optional thread argument.

# Fixed duration
python example.py

# Threaded
python example.py thread

Contributing

To contribute to this project, clone master and create your own development branch.

git clone https://gitlab.com/ml394/pyloaders.git
git checkout -b <feature-name>

Push your branch remotely, and create a merge request to master so we can review your code.

If the merge request is approved, your new feature will be merged and pushed for the next release.

To Do

  • Loader colours / styles
  • CI/CD Pipeline
  • API Documentation
  • Print output while loader running

Donate

BTC donations (no matter how tiny) accepted at wallet address:

1PSWQrgbagNARvtum6pGS7rPUub4YiLmzX

FAQs


Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc