11
Build CLI with Hype
First thing first, the installation of Hype is easy!
Just run
$ pip install hypecli
and you are good to go!
After that, let's take a look at the basic example of Hype π:
from hype import Hype #: Import Hype
app = Hype() #: Create hype app instance
@app.command() #: Create hype command
def greet(name: str):
""""
Greet the user
"""
app.echo('Hello, {}'.format(name.capitalize()))
if __name__ == "__main__":
app.run() #: Now, run it!
As you can see, Hype is based on modern Python type hints. It was inspired Typer a different Python library. However Typer was built on the top of click, which is an awesome library as well!
As I mentioned earlier, Hype doesn't rely on any third-party library but then there are some plugins that third-party library powered Hype. For example, the color printing that is powered by colorama.
Printing colors with Hype is easier than you thought. It uses a BBCode parser to parse color tags, here is the example:
from hype import print #: Print is a wrapper for
#: standard printing and color printing
#: Note: If you want to print colored text,
#: make sure to install the color plugin.
#: `pip install hypecli[color]`
#: More information: https://hype.serum.studio/getting-started
print('[red]This is red[/red]') #: This will print a color red text.
With simple BBCode parser, it makes the printing looks good and faster. For more information about colors, kindly refer to the
Documention about handling colors.
Hype Comes with UI support like: Spinner
, Table
and Progress Bar
. It is like all in one library.
Here is an example for Spinners:
from hype.ui import Spinner
with Spinner('Loading', 'arc') as spinner:
#: Some heavy task here
spinner.stop()
For Table:
from hype.ui import Table
table = Table(headers=['Name', 'Age', 'Hobby'])
table.add_row(['Zenqi', '5', 'Reading'])
print(table(background_color='red')) #: or #: print(table.render())
Ang last for the progressbar:
from hype.ui import progressbar
import time
with progressbar(100) as bar:
time.sleep(.01)
bar()
More features are coming with Hype. Just read the Documentation for more information
11