Pure Python implementation of FIGlet for creating ASCII art text from regular text using various fonts
—
Core functionality for converting plain text into ASCII art using FIGlet fonts. This module provides both simple utility functions and programmatic access to text rendering capabilities.
Converts text to ASCII art using the specified font and options. This is the most commonly used function for simple text-to-ASCII art conversion.
def figlet_format(text: str, font: str = "standard", **kwargs) -> FigletString:
"""
Convert text to ASCII art using specified font.
Parameters:
- text (str): Text to convert to ASCII art
- font (str): Font name to use (default: "standard")
- direction (str): Text direction ("auto", "left-to-right", "right-to-left")
- justify (str): Text justification ("auto", "left", "center", "right")
- width (int): Output width in characters (default: 80)
Returns:
FigletString: ASCII art representation of the text
Raises:
FontNotFound: If the specified font cannot be located
FontError: If there is a problem parsing the font file
CharNotPrinted: If width is insufficient to print a character
"""import pyfiglet
# Basic usage with default font
result = pyfiglet.figlet_format("Hello")
print(result)
# Using a different font
result = pyfiglet.figlet_format("Hello", font="big")
print(result)
# With additional formatting options
result = pyfiglet.figlet_format(
"Centered Text",
font="slant",
justify="center",
width=60
)
print(result)Prints ASCII art text directly to stdout with optional color support. Useful for terminal applications that need immediate colored output.
def print_figlet(text: str, font: str = "standard", colors: str = ":", **kwargs) -> None:
"""
Print ASCII art text directly to stdout with color support.
Parameters:
- text (str): Text to convert and print
- font (str): Font name to use (default: "standard")
- colors (str): Color specification in "foreground:background" format
- direction (str): Text direction ("auto", "left-to-right", "right-to-left")
- justify (str): Text justification ("auto", "left", "center", "right")
- width (int): Output width in characters (default: 80)
Returns:
None: Prints to stdout
Raises:
FontNotFound: If the specified font cannot be located
FontError: If there is a problem parsing the font file
InvalidColor: If color specification is invalid
"""import pyfiglet
# Basic printing
pyfiglet.print_figlet("Hello World")
# With colors (red text on blue background)
pyfiglet.print_figlet("Colored Text", colors="red:blue")
# Only foreground color
pyfiglet.print_figlet("Red Text", colors="red:")
# Only background color
pyfiglet.print_figlet("Blue Background", colors=":blue")
# RGB colors
pyfiglet.print_figlet("RGB Text", colors="255;100;50:0;0;255")The colors parameter accepts several formats:
Available named colors: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, LIGHT_GRAY, DEFAULT, DARK_GRAY, LIGHT_RED, LIGHT_GREEN, LIGHT_YELLOW, LIGHT_BLUE, LIGHT_MAGENTA, LIGHT_CYAN, WHITE, RESET
Both functions work with FigletString, an enhanced string type that supports ASCII art manipulation methods like reverse(), flip(), and whitespace normalization.
Install with Tessl CLI
npx tessl i tessl/pypi-pyfiglet