An assortment of spinners to use while your Python programs run.
In order to install revolution
, run the following in your command line:
pip install revolution
In order to use revolution
in your code, importing it is as simple as:
from revolution import Revolution
revolution
can be used as a function decorator:
import time
from revolution import Revolution
@Revolution
def do_something():
for _ in range(10):
time.sleep(0.1)
do_something()
You can also provide it a description while you wait for your task to finish:
import time
from revolution import Revolution
@Revolution(desc='Just passing time...')
def do_something():
for _ in range(10):
time.sleep(0.1)
do_something()
Another possible way to implement revolution
is through the use of a with statement:
import time
from revolution import Revolution
with Revolution(desc='Running through numbers') as rev:
for _ in range(100):
time.sleep(0.1)
rev.update(1)
You can also include a visual counter by including a total:
import time
from revolution import Revolution
with Revolution(desc='Counting up to 100', total=100) as rev:
for _ in range(100):
time.sleep(0.1)
rev.update(1)
If you give a Revolution object a range object or a list, you can then iterate over it:
import time
from revolution import Revolution
total = 0
for i in Revolution(range(100)):
total += i
time.sleep(0.1)
print(total)
Finally, you can use revolution
by manually controlling when to stop it:
from revolution import Revolution
rev = Revolution(desc='Doing things...')
rev.start()
# ...
rev.stop()
These are the available parameters for initializing a Revolution object:
Revolution(func=None, desc='', total=None, style='', color='blue', success=None, safe=True, interval=None)
More info
func
: list or range, optional
If this is a list or range object, it will iterate over each of the elements and return them one by one.
The func
parameter should be left blank unless you initialize a Revolution object with a range object or a list.
More info
desc
: str, optional
A string to use in place of the text that displays beside the spinner.
More info
total
: int, optional
An integer that indicates the total number of expected iterations.
More info
style
: str, optional
A string that indicates which spinner style to use. If style is None or if it doesn't exist, the classic style will be used.
Available options can be viewed by running revolution --example
or revolution -e
in your console.
More info
color
: str, optional
A string that indicates which color should be used for the spinner. If a color is not provided, the color will default to 'blue'.
Available options:
* black
* red
* green
* yellow
* blue
* violet
* cyan
* white
More info
success
: str, optional
A string that will be displayed beside the spinner when the spinner animation stops.
More info
safe
: bool, optional
If True (default), spinners on Windows machines will always use the 'classic' style (even if a different style is provided).
If you are using a certain spinner style and are unsure as to how it will appear on Windows machines, it is recommended that you leave safe
set to its default value.
More info
interval
: float, optional
A float value that is used to indicate the refresh rate of the entire spinner.
There are multiple built-in spinner styles that you can take advantage of. However, only the classic spinner will be used on Windows machines unless you set safe=False
when you initialize a Revolution object.
Revolution(style='classic')
- Windows-friendly
- If a Revolution object doesn't contain a specified style, this is the style that it will default to
Revolution(style='dots')
- Windows-friendly
Revolution(style='equal')
- Windows-friendly
Revolution(style='braille')
Revolution(style='braille_long')
Revolution(style='braille_crawl')
Revolution(style='braille_bounce')
Revolution(style='arc')
Revolution(style='clear_quadrants')