Welcome to Buzio’s documentation!

https://img.shields.io/pypi/v/buzio.svg https://travis-ci.org/chrismaille/buzio.svg?branch=master https://img.shields.io/pypi/pyversions/buzio.svg https://coveralls.io/repos/github/chrismaille/buzio/badge.svg?branch=master Documentation Status https://api.codacy.com/project/badge/Grade/5a70e225a4744cbc828013eeb003f2d7 Maintainability Requirements Status

This document will guide you how to install, configure and use Buzio in your projects.

What is Buzio?

Buzio is a python library tool for printing formatted text in terminal, similar to termcolor or colored. But unlike these, Buzio has some new features like:

Generate fancy formats

“Section” example 1:

from buzio import console

console.section("First Section")

Terminal output:

$ >> First Section
$ ----------------

“Section” example 2:

from buzio import console

console.section("Main Section", full_width=True, transform="upper center")

Terminal output:

$ >                                 MAIN SECTION                                 <
$ --------------------------------------------------------------------------------

Humanize Python objects

Buzio can automatically humanize any python object for printing in terminal:

from datetime import datetime, timedelta
from buzio import console

today = datetime.now()
yesterday = today - timedelta(days=1)
my_dict = {
        "start day": yesterday,
        "end day": today
}

console.box(my_dict, date_format="%a, %b-%d-%Y")

The output on terminal will be (in blue color):

$ *********************************
$ *                               *
$ *  start day: Thu, Feb-01-2018  *
$ *   end day: Fri, Feb-02-2018   *
$ *                               *
$ *********************************

Ask for Input data

You can use Buzio to automatically generate “choose” and “select” questions, based on Python objects:

“Choose” example:

from buzio import console

my_choices = [
        "Orange",
        "Apple",
        "Potato"
]

console.choose(my_choices)

Terminal output:

$ 1. Orange
$ 2. Apple
$ 3. Potato
$
$ Select (1-3): ?

“Select” example:

from buzio import console

my_options = [
        "Save",
        "Save and Exit",
        "Cancel"
]

console.select(my_options)

Terminal output:

$ Select: (S)ave and Exit, S(A)ve, (C)ancel?

You can also “ask” a question and, optionally, use a method to validate the answer:

from buzio import console

def check_answer(answer):
   return int(answer) == 4

console.ask("What is the sum of 2+2", validator=check_answer)
print("Thanks!")

Terminal output:

$ What is the sum of 2+2? : 3
$ Please answer again: 4
$ Thanks!

Run terminal commands

You can use Buzio to run terminal commands (using Python subprocess) and get the stdout result:

>>> from buzio import console
>>> ret = console.run("echo HelloWorld!", get_stdout=True, verbose=True)
Cmd: echo HelloWorld!
>>> print(ret)
HelloWorld!

Indices and tables