pyfiglet: Pure-Python FIGlet Implementation
pyfiglet is a pure-Python port of FIGlet, a program that generates ASCII art from text. It enables dynamic rendering of text in various ASCII art fonts within Python applications or via the command line interface. The library is actively maintained, with recent releases focusing on bug fixes, type hinting, and Python version compatibility. [1, 3, 9]
Warnings
- breaking Versions 1.0.0 and above drop support for Python versions older than 3.9. If you need Python <= 3.7 support, you must use `pyfiglet<1`. Version 1.0.0 was initially yanked due to compatibility issues with older Python versions. [3]
- gotcha Some fonts that were previously available in older `pyfiglet` distributions (or the original C `FIGlet`) have been removed due to distribution rights. Users expecting specific fonts might find them missing. [1, 5]
- gotcha When bundling applications with PyInstaller, `pyfiglet` fonts might not be automatically included, leading to `ModuleNotFoundError: No module named 'pyfiglet.fonts'` errors at runtime. [15]
- gotcha The internal code for kerning, mushing, and rendering is described as "fragile and complex." While this primarily affects contributors modifying the core logic, it suggests potential for unexpected behavior with highly customized inputs or unusual fonts. [1, 5, 8]
- gotcha An open issue indicates potential incompatibility where `pyfiglet` might break with `setuptools >= 82`. This could lead to installation or runtime errors in environments with newer `setuptools` versions. [14]
Install
-
pip install pyfiglet
Imports
- figlet_format
import pyfiglet result = pyfiglet.figlet_format("Hello")
Quickstart
import pyfiglet
# Render text using the default font
text_default = pyfiglet.figlet_format("Hello, World!")
print(text_default)
# Render text using a specific font (e.g., 'slant')
text_slant = pyfiglet.figlet_format("Pyfiglet", font="slant")
print(text_slant)
# List available fonts (optional)
# Uncomment to see a long list
# fig = pyfiglet.Figlet()
# print(fig.getFonts())