Getting Started with quo python
Tags: python, codenewbie, console, terminal
Published: 2022-08-31 08:39:49

[![Twitter Follow](https://img.shields.io/twitter/follow/gerrishon_s.svg?style=social)](https://twitter.com/gerrishon_s)


[![Logo](https://raw.githubusercontent.com/scalabli/quo/master/pics/quo.png)](https://github.com/scalabli/quo)


`Forever Scalable`

**Quo** is a toolkit for writing Command-Line Interface(CLI) applications and a TUI (Text User Interface) framework for Python.

Quo is making headway towards composing speedy and orderly CLI and TUI applications while forestalling any disappointments brought about by the failure to execute a python application.
Simple to code, easy to learn, and does not come with needless baggage. 

## Compatibility
Quo works flawlessly  with Linux, OSX, and Windows.
Quo requires Python `3.8` or later. 


## Features
- [x] Support for Ansi, RGB and Hex color models
- [x] Support for tabular presentation of data
- [x] Intuitive progressbars
- [x] Code completions
- [x] Nesting of commands
- [x] Customizable Text User Interface _(TUI)_ dialogs.
- [x] Automatic help page generation
- [x] Syntax highlighting
- [x] Autosuggestions
- [x] Key Binders

## Getting Started
### Installation
You can install quo via the Python Package Index (PyPI)

```
pip install -U quo

```

In order to check your installation you can use
```
python -m pip show quo
```
Run the following to test Quo output on your terminal:
```
python -m quo

```
![test](https://github.com/scalabli/quo/raw/master/docs/images/test.png)

# Quo Library
Quo contains a number of builtin features you c
an use to create elegant output in your CLI.

## Quo echo
To output formatted text to your terminal you can import the [echo](https://quo.readthedocs.io/en/latest/introduction.html#quick-start) method.
Try this:

**Example 1**
```python
 from quo import echo

 echo("Hello, World!", fg="red", italic=True, bold=True)
```
![Hello World](https://github.com/scalabli/quo/raw/master/pics/print.png)

**Example 2**
```python
 from quo import echo

 echo("Quo is ", nl=False)
 echo("scalable", bg="red", fg="black") 
```
![Scalable](https://github.com/scalabli/quo/raw/master/pics/scalable.png)

Alternatively, you can import [print](https://quo.readthedocs.io/en/latest/printing_text.html#print)
```python
 from quo import print

 print('<b>This is bold</b>')
 print('<i>This is italic</i>')
 print('<u>This is underlined</u>')
                    
 # Colors from the ANSI palette.
 print('<red>This is red</red>')
 print('<style fg="green" bg="red">Green on red background</stlye>')

```
## Quo prompt
 - Using ``quo.prompt`` method.
```python
 from quo import prompt

 prompt("What is your name?")
```
![quo.prompt](https://github.com/scalabli/quo/raw/master/pics/prompt.png)

- Using ``quo.prompt.Prompt`` object

**Example 1**

```python
 from quo.prompt import Prompt
   
 session = Prompt()
 session.prompt("Type something:") 
```

**Example 2**

Real time integer validator

```python

 from quo.prompt import Prompt

 session = Prompt(int=True)
 number = int(session.prompt('Give a number: '))

```

![validate](https://raw.githubusercontent.com/scalabli/quo/master/docs/images/number-validator.png)


**Example 3**

A prompt with a bottom toolbar

```python

  from quo.prompt import Prompt
  from quo.text import Text

  def toolbar():
        return Text('This is a <b><style bg="red">Toolbar</style></b>!')

  # Returns a callable
  session = Prompt(bottom_toolbar=toolbar)
  session.prompt('> ')

```

![validate](https://raw.githubusercontent.com/scalabli/quo/master/docs/images/bottom-toolbar.png)


**Example 4**

A placeholder  text that's displayed as long as no input s given.

:bulb: This won't be returned as part of the output.

```python

  from quo.prompt import Prompt
  from quo.text import Text

  session = Prompt(placeholder=Text('<gray>(please type something)</gray>'))
  session.prompt("What is your name?: ")
```
**Example 5**

Add colors to the prompt itself.

```python

 from quo.color import Color
 from quo.prompt import Prompt

 style = Color("fg:red")
 session = Prompt(style=style)
 session.prompt("Type something: ")

```
![validate](https://raw.githubusercontent.com/scalabli/quo/master/docs/images/colored-prompt1.png)


Read more on [Prompt](https://quo.readthedocs.io/latest/prompt.html)

## Quo Console

For more control over quo terminal content, import and construct a `Console` object.


``Bar``

Draw a horizontal bar with an optional title, which is a good way of dividing your terminal output in to sections.

```python

 from quo.console import Console

 console = Console()
 console.bar("I am a bar", style="fg:red bg:yellow")

```

``Launching Applications``

Quo supports launching applications through `Console.launch`

**Example 1**

```python

 from quo.console import Console

 console = Console()
 console.launch("https://quo.rtfd.io/")

```

**Example 2**

```python

 from quo.console import Console

 console = Console()
 console.launch("/home/path/README.md", locate=True)

```

``Rule``

Used for drawing a horizontal line.

**Example 1**

```python

 from quo.console import Console

 console = Console()
 console.rule(

```

**Example 2**

A multicolored line.

```python

 from quo.console import Console

 console = Console()
 console.rule(multicolored=True)

```
![Multicolored](https://quo.readthedocs.io/en/latest/_images/rulemulticolored.jpg)


``Spin``🔁

Quo can create a context manager that is used to display a spinner on stdout as long as the context has not exited

```python

 import time
 from quo.console import Console

 console = Console()

 with console.spin():
           time.sleep(3)
           print("Hello, World")

```
Read more on [Console](https://quo.readthedocs.io/en/latest/console.html)

## Quo Dialogs

High level API for displaying dialog boxes to the user for informational purposes, or to get input from the user.

**Example 1**

Message Box dialog
```python

 from quo.dialog import MessageBox

 MessageBox(
       title="Message pop up window", 
       text="Do you want to continue?\nPress ENTER to quit."
              )

```
![Message Box](https://github.com/scalabli/quo/raw/master/docs/images/messagebox.png)

**Example 2**

Input Box dialog

```python

 from quo.dialog import InputBox

 InputBox(
      title="InputBox shenanigans",
      text="What Country are you from? :"
        )

```
![Prompt Box](https://github.com/scalabli/quo/raw/master/docs/images/promptbox.png)

Read more on [Dialogs](https://quo.readthedocs.io/en/latest/dialogs.html)


## Quo Key Binding🔐

A key binding is an association between a physical key on akeyboard and a parameter.

```python

 from quo import echo
 from quo.keys import bind
 from quo.prompt import Prompt

 session = Prompt()

 # Print "Hello world" when ctrl-h is pressed
 @bind.add("ctrl-h")
 def _(event):
      echo("Hello, World!")

 session.prompt("")

```

Read more on [Key bindings](https://quo.readthedocs.io/en/latest/kb.html)

## Quo Tables

This offers a number of configuration options to set the look and feel of the table, including how borders are rendered and the style and alignment of the columns.

**Example 1**

```python

 from quo.table import Table

 data = [
     ["Name", "Gender", "Age"],
     ["Alice", "F", 24],
     ["Bob", "M", 19],
     ["Dave", "M", 24]
  ]

 Table(data)

```
![tabulate](https://raw.githubusercontent.com/scalabli/quo/master/docs/images/tables/table.png)

**Example 2**

Right aligned table

```python

 from quo.table import Table

 data = [
    ["Name", "Gender", "Age"],
    ["Alice", "F", 24],
    ["Bob", "M", 19],
    ["Dave", "M", 24]
    ]
 Table(data, align="right")

```

![tabulate](https://raw.githubusercontent.com/scalabli/quo/master/docs/images/tables/right-table.png)

**Example 3**

Colored table

```python

 from quo.table import Table

 data = [
    ["Name", "Gender", "Age"],
    ["Alice", "F", 24],
    ["Bob", "M", 19],
    ["Dave", "M", 24]
    
 Table(data, style="fg:green")

```


![tabulate](https://raw.githubusercontent.com/scalabli/quo/master/docs/images/tables/colored-table.png)

**Example 4**

Grid table

```python

 from quo.table import Table

 data = [
    ["Name", "Gender", "Age"],
    ["Alice", "F", 24],
    ["Bob", "M", 19],
    ["Dave", "M", 24]
    ]

 Table(data, theme="grid")

```


![tabulate](https://raw.githubusercontent.com/scalabli/quo/master/docs/images/tables/grid-table.png)




Read more on [Table](https://quo.readthedocs.io/en/latest/table.html)

## Quo Widgets
A collection of reusable components for building full screen applications.

``Frame`` 🎞️

Draw a border around any container, optionally with a title.

```python

 from quo import container
 from quo.widget import Frame, Label

 content = Frame(
             Label("Hello, World!"),
               title="Quo: python")

 #Press Ctrl-C to exit
 container(content, bind=True, full_screen=True)

```
![Frame](https://raw.githubusercontent.com/scalabli/quo/master/docs/images/widgets/frame.png)

``Label``

Widget that displays the given text. It is not editable or focusable.

**Example 1**

This will occupy a minimum space in your terminal

```python

 from quo import container
 from quo.widget import Label

 content = Label("Hello, World", style="fg:black bg:red")

 container(content)

```
**Example 2**

This will be a fullscreen application

```python

 from quo import container
 from quo.widget import Label

 content = Label("Hello, World", style="fg:black bg:red")

 # Press Ctrl-C to exit
 container(content, bind=True, full_screen=True)

```
**Example 3**

Full screen application using a custom binding key.

```python

 from quo import container
 from quo.keys import bind
 from quo.widget import Label

 content = Label("Hello, World", style="fg:black bg:red")

 #Press Ctrl-Z to exit
 @bind.add("ctrl-z")
 def _(event):
     event.app.exit()

 container(content, bind=True, full_screen=True)

```

Read more on [Widgets](https://quo.readthedocs.io/en/latest/widgets.html)

Click the following headings for more:»

<details>
<summary>Completion</summary>

## ``Autocompletion``

Press [Tab] to autocomplete
```python

 from quo.prompt import Prompt
 from quo.completion import WordCompleter
 example = WordCompleter(['USA', 'UK', 'Canada', 'Kenya'])
 session = Prompt(completer=example)
 session.prompt('Which country are you from?: ')
```
![Autocompletion](https://github.com/scalabli/quo/raw/master/docs/images/autocompletion.png)

## ``Autosuggestion``
Auto suggestion is a way to propose some input completions to the user. Usually, the input is compared to the history and when there is another entry starting with the given text, the completion will be shown as gray text behind the current input. Pressing the right arrow → or ctrl-e will insert this suggestion, alt-f willinsert the first word of the suggestion.
```python

 from quo.history import MemoryHistory
 from quo.prompt import Prompt

 MemoryHistory.append("import os")
 MemoryHistory.append('print("hello")') 
 MemoryHistory.append('print("world")')  
 MemoryHistory.append("import path")

 session = Prompt(history=MemoryHistory, suggest="history")

 while True:
    session.prompt('> ')
```
Read more on [Completions](https://quo.readthedocs.io/en/latest/prompt.html#completion)
</details>

<details>
<summary>Documenting Scripts</summary>
Quo automatically generates help pages for your command-line tools.

```python
 from quo import print
 from quo.console import command
 from quo.console import app

 @command()
 @app('--count', default=1, help='number of greetings')
 @app('--name', prompt="What is your name?", help="The person to greet")

def hello(count: int, name: str):
    """This script prints hello NAME COUNT times."""
       for x in range(count):
           print(f"Hello {name}!")

 if __name__ == "__main__:
          hello()
```
And what it looks like:
![Help Text](https://raw.githubusercontent.com/secretum-inc/quo/master/docs/images/help-text.png)

</details>
<details>
<summary>Progress</summary>
Creating a new progress bar can be done by calling the class **ProgressBar**
The progress can be displayed for any iterable. This works by wrapping the iterable (like ``range``) with the class **ProgressBar**

```python

 import time
 from quo.progress import ProgressBar
  
 with ProgressBar() as pb:
               for i in pb(range(800)):
                             time.sleep(.01)
```
![Progress](https://raw.githubusercontent.com/scalabli/quo/master/docs/images/simple-progress-bar.png)

Read more on [Progress](https://quo.readthedocs.io/en/latest/progress.html)

</details>

For more intricate  examples, have a look in the [examples](https://github.com/scalabli/quo/tree/master/examples) directory and the documentation.

## Donate🎁

In order to for us to maintain this project and grow our community of contributors.
[Donate](https://ko-fi.com/scalabli)



## Quo is...

**Simple**
     If you know Python you can  easily use quo and it can integrate with just about anything.




## Getting Help

### Community

For discussions about the usage, development, and the future of quo, please join our Google community

* [Community👨‍👩‍👦‍👦](https://groups.google.com/g/scalabli)

## Resources

### Bug tracker

If you have any suggestions, bug reports, or annoyances please report them
to our issue tracker at 
[Bug tracker](https://github.com/scalabli/quo/issues/) or send an email to:

 📥 scalabli@googlegroups.com




## Blogs💻

→ How to build CLIs using [quo](https://www.python-engineer.com/posts/cli-with-quo/)

## License📑

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)  
This software is licensed under the `MIT License`. See the [License](https://github.com/scalabli/quo/blob/master/LICENSE) file in the top distribution directory for the full license text.


## Code of Conduct
Code of Conduct is adapted from the Contributor Covenant,
version 1.2.0 available at
[Code of Conduct](http://contributor-covenant.org/version/1/2/0/)