Pure Python implementation of FIGlet for creating ASCII art text from regular text using various fonts
—
Comprehensive font system for managing FIGlet fonts including discovery, validation, installation, and information retrieval. Supports .flf, .tlf font formats and ZIP archives containing multiple fonts.
Retrieves a list of all available fonts from both built-in and user-installed locations.
@classmethod
def getFonts(cls) -> list[str]:
"""
Get list of all available font names.
Returns:
list[str]: Sorted list of available font names (without extensions)
Searches:
- Built-in fonts in pyfiglet.fonts package
- User fonts in SHARED_DIRECTORY
- Validates each font file before including
"""from pyfiglet import FigletFont
# Get all available fonts
fonts = FigletFont.getFonts()
print(f"Available fonts: {len(fonts)}")
for font in fonts[:10]: # Show first 10
print(f" {font}")
# Check if a specific font exists
if "slant" in FigletFont.getFonts():
print("Slant font is available")Retrieves detailed information about a specific font including metadata, character descriptions, and font properties.
@classmethod
def infoFont(cls, font: str, short: bool = False) -> str:
"""
Get information about a specific font.
Parameters:
- font (str): Font name to get information about
- short (bool): If True, return only the first line of info
Returns:
str: Font information including metadata and description
Raises:
FontNotFound: If the specified font cannot be located
"""from pyfiglet import FigletFont
# Get full font information
info = FigletFont.infoFont("standard")
print(info)
# Get short description only
short_info = FigletFont.infoFont("standard", short=True)
print(f"Font info: {short_info}")
# Info for multiple fonts
for font in ["big", "slant", "shadow"]:
try:
info = FigletFont.infoFont(font, short=True)
print(f"{font}: {info}")
except Exception as e:
print(f"{font}: Error - {e}")Installs new font files or font archives to the system for use with PyFiglet.
@staticmethod
def installFonts(file_name: str) -> None:
"""
Install the specified font file to the system.
Parameters:
- file_name (str): Path to font file (.flf, .tlf) or ZIP archive
Returns:
None: Prints installation progress to stdout
Installation locations:
- Standard install: Package fonts directory
- Zipped package: SHARED_DIRECTORY
Raises:
FileNotFoundError: If the font file cannot be found
PermissionError: If unable to write to installation directory
"""from pyfiglet import FigletFont
# Install a single font file
FigletFont.installFonts("path/to/newfont.flf")
# Install fonts from ZIP archive
FigletFont.installFonts("path/to/font-collection.zip")
# The installation creates necessary directories automatically
# and extracts fonts from ZIP files preserving their namesChecks if a font file is valid FIGlet format before attempting to load it.
@classmethod
def isValidFont(cls, font: str) -> bool:
"""
Check if a font file is valid FIGlet format.
Parameters:
- font (str): Font filename (with extension) to validate
Returns:
bool: True if font file is valid FIGlet format
Validation checks:
- File extension (.flf or .tlf)
- FIGlet magic number in header
- Supports ZIP archives (validates first file)
"""from pyfiglet import FigletFont
# Validate font files
valid_fonts = []
test_files = ["standard.flf", "big.flf", "invalid.txt"]
for font_file in test_files:
if FigletFont.isValidFont(font_file):
valid_fonts.append(font_file)
print(f"✓ {font_file} is valid")
else:
print(f"✗ {font_file} is invalid")PyFiglet supports multiple font formats:
Fonts are searched in this order:
pyfiglet.fonts package%APPDATA%/pyfiglet/usr/local/share/pyfiglet/Install with Tessl CLI
npx tessl i tessl/pypi-pyfiglet