This page looks best with JavaScript enabled

Command-Line Banner Generation Tool - pyfiglet

 ·  ☕ 3 min read

1. What Is pyfiglet

pyfiglet is an ASCII art text generation tool implemented in Python. It can generate graphics like the following from a string:

1
2
3
4
5
6
 _          _ _                             _     _ _
| |__   ___| | | ___    __      _____  _ __| | __| | |
| '_ \ / _ \ | |/ _ \   \ \ /\ / / _ \| '__| |/ _` | |
| | | |  __/ | | (_) |   \ V  V / (_) | |  | | (_| |_|
|_| |_|\___|_|_|\___( )   \_/\_/ \___/|_|  |_|\__,_(_)
                    |/

When writing CLI tools, you can use pyfiglet to generate a Banner to display on the command line.

2. Installation

In a Python environment, install with pip:

1
pip install pyfiglet

3. Demo Usage

First take a look at the help documentation:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
pyfiglet --help

Usage: pyfiglet [options] [text..]

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -f FONT, --font=FONT  font to render with (default: standard)
  -D DIRECTION, --direction=DIRECTION
                        set direction text will be formatted in (default:
                        auto)
  -j SIDE, --justify=SIDE
                        set justification, defaults to print direction
  -w COLS, --width=COLS
                        set terminal width for wrapping/justification
                        (default: 80)
  -r, --reverse         shows mirror image of output text
  -F, --flip            flips rendered output text over
  -l, --list_fonts      show installed fonts list
  -i, --info_font       show font's information, use with -f FONT
  -L LOAD, --load=LOAD  load and install the specified font definition
  -c COLOR, --color=COLOR
                        prints text with passed foreground color,
                        --color=foreground:background
                        --color=:background                  # only background
                        --color=foreground | foreground:     # only foreground
                        --color=list                         # list all colors
                        COLOR = list[COLOR] | [0-255];[0-255];[0-255] (RGB)

Now let’s try these parameters directly:

  • Default parameters
1
2
3
4
5
6
7
pyfiglet Kube

 _  __     _
| |/ /   _| |__   ___
| ' / | | | '_ \ / _ \
| . \ |_| | |_) |  __/
|_|\_\__,_|_.__/ \___|
  • Center alignment
1
2
3
4
5
6
pyfiglet Kube -j center
                              _  __     _
                             | |/ /   _| |__   ___
                             | ' / | | | '_ \ / _ \
                             | . \ |_| | |_) |  __/
                             |_|\_\__,_|_.__/ \___|
  • Specifying a font

Fonts can be found at http://www.figlet.org/fontdb.cgi.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
pyfiglet -f isometric3 Kube

      ___           ___                         ___
     /__/|         /__/\         _____         /  /\
    |  |:|         \  \:\       /  /::\       /  /:/_
    |  |:|          \  \:\     /  /:/\:\     /  /:/ /\
  __|  |:|      ___  \  \:\   /  /:/~/::\   /  /:/ /:/_
 /__/\_|:|____ /__/\  \__\:\ /__/:/ /:/\:| /__/:/ /:/ /\
 \  \:\/:::::/ \  \:\ /  /:/ \  \:\/:/~/:/ \  \:\/:/ /:/
  \  \::/~~~~   \  \:\  /:/   \  \::/ /:/   \  \::/ /:/
   \  \:\        \  \:\/:/     \  \:\/:/     \  \:\/:/
    \  \:\        \  \::/       \  \::/       \  \::/
     \__\/         \__\/         \__\/         \__\/
  • Setting colors
1
pyfiglet -f isometric3 -c BLUE  Kube

1
pyfiglet -f isometric3 -c RED  Kube

In addition, you can also render fonts in Python code via from pyfiglet import Figlet.


WeChat Official Account
WRITTEN BY
WeChat Official Account