A Python library of interactive CLI elements you have been looking for
For documentation but more and prettier see here
BeauPy stands on the shoulders of giants. It is based on another library with which it shares some of the source code, cutie, developed by Kamik423. It has begun as a fork but has since diverged into it's own thing and as such, detached from the original repository.
BeauPy implements a number of common interactive elements:
| Function | Functionality |
|---|---|
select |
Prompt to pick a choice from a list |
select_multiple |
Prompt to select one or multiple choices from a list |
confirm |
Prompt with a question and yes/no options |
prompt |
Prompt that takes free input with optional validation, type conversion and input hiding |
BeauPy is a library of interactive TUI elements for CLI applications.
BeauPy is
- rich friendly
- stylable
- opinionated
- configurable
From PyPI:
pip install beaupyFrom source:
git clone https://github.com/petereon/beaupy.git
poetry build
pip install ./dist/beaupy-{{some-version}}-py3-none-any.whlTUI elements shown in the above gif are the result of the follwing code:
import time
from beaupy import *
from beaupy.spinners import *
def main():
"""Main."""
# Confirm a dialog
if confirm("Will you take the ring to Mordor?"):
names = [
"Frodo Baggins",
"Samwise Gamgee",
"Legolas",
"Aragorn",
"[red]Sauron[/red]",
]
console.print("Who are you?")
# Choose one item from a list
name = select(names, cursor="π’§", cursor_style="cyan")
console.print(f"AlΓ‘menΓ«, {name}")
item_options = [
"The One Ring",
"Dagger",
"Po-tae-toes",
"Lightsaber (Wrong franchise! Nevermind, roll with it!)",
]
console.print("What do you bring with you?")
# Choose multiple options from a list
items = select_multiple(item_options, tick_character='π', ticked_indices=[0], maximal_count=3)
potato_count = 0
if "Po-tae-toes" in items:
# Prompt with type conversion and validation
potato_count = prompt('How many potatoes?', target_type=int, validator=lambda count: count > 0)
# Spinner to show while doing some work
spinner = Spinner(DOTS, "Packing things...")
spinner.start()
time.sleep(2)
spinner.stop()
# Get input without showing it being typed
if "friend" == prompt("Speak, [blue bold underline]friend[/blue bold underline], and enter", secure=True).lower():
# Custom spinner animation
spinner_animation = ['ββ', 'ββ', ' ', 'ββ', 'ββ']
spinner = Spinner(spinner_animation, "Opening the Door of Durin...")
spinner.start()
time.sleep(2)
spinner.stop()
else:
spinner_animation = ['ππ βοΈ ', 'π π βοΈ ', 'π π βοΈ ', 'π π βοΈ ', 'π πβοΈ ']
spinner = Spinner(spinner_animation, "Getting attacked by an octopus...")
spinner.start()
time.sleep(2)
spinner.stop()
if 'The One Ring' in items:
console.print("[green]You throw The One Ring to a lava from an eagle![/green]")
else:
console.print("[red]You forgot the right and brought Middle-Earth to its knees![/red]")
console.print(f"And you brought {potato_count} taters!")
For more information refer to more_examples or definitive, but much less exciting api documentation
This repository has a associated GitHub project where work that is currently done can be seen
If you want to contribute, please feel free to suggest features or implement them yourself.
Also please report any issues and bugs you might find!
To start development you can clone the repository:
git clone https://github.com/petereon/beaupy.gitChange the directory to the project directory:
cd ./beaupy/This project uses poetry as a dependency manager. You can install the dependencies using:
poetry installFor testing, this project relies on ward. It is included as a development dependency, so
after installing the dependencies you can simply execute the following:
poetry run poe testMaking sure the code follows quality standards and formatting can be ensured by executing
poetry run poe lintYou can also have the tests and lints run after every saved change by executing a respective watch command
poetry run poe test:watchor
poetry run poe lint:watchAfter you have made your changes, create a pull request towards a master branch of this repository
Looking forward to your pull requests!
Internal logic of beaupy is supported for all the major platforms (Windows, Linux, macOS).
- For user input from console,
beaupyrelies on pallets/click, authors of which claim for it to be to be OS Independent on their PyPI page, and test against all the major platforms and Python versions - For printing to console
beaupyrelies on Textualize/rich, which claims to support all the major platforms.
- Version
2.x.xreportedly does not always support arrow keys on Windows.
- therealOri/PassGen: A strong password generator and built in password manager made with python3!
The project is licensed under the MIT License.

