Blessings
Blessings is a thin, practical Python wrapper around terminal capabilities, offering an elegant interface for coloring, styling, and positioning text. It aims to simplify advanced terminal interactions compared to raw ANSI escape codes or the `curses` library, handling common cases like output redirection gracefully. The latest version, 1.7, was released in June 2018. The project is largely unmaintained, with active development continuing in a fork called `blessed`.
Warnings
- deprecated The `blessings` library is largely unmaintained since its last release (v1.7 in 2018). Most active development and new features, including Python 3.7+ compatibility, Windows support, and improved keyboard handling, are found in the `blessed` fork (PyPI: `blessed`).
- gotcha Blessings does not natively support color or styling on the Windows command prompt by itself. While it may work in some environments (like Cygwin, WSL), direct Windows CMD support is absent.
- breaking Blessings is explicitly incompatible with specific Python 3 versions (3.0, 3.1, 3.2, 3.3).
- gotcha The original `blessings` library does not provide robust character-by-character keyboard input handling, which is a common requirement for interactive terminal applications. Users often expect this functionality similar to `curses`.
- gotcha When output is redirected (e.g., to a file or pipe), `blessings` intelligently omits terminal control codes by default. If you intend to pipe output to a program that *can* handle escape sequences (like `less -r`), this automatic omission might be undesired.
- gotcha While string concatenation (e.g., `term.bold + 'text' + term.normal`) works for applying styles, it requires manual resetting with `term.normal`. For simpler usage, attributes can be called directly.
Install
-
pip install blessings
Imports
- Terminal
from blessings import Terminal
Quickstart
from blessings import Terminal
term = Terminal()
# Basic styling
print(term.bold_red_on_yellow('Hello, Blessings!'))
# Temporary cursor positioning
with term.location(x=0, y=term.height - 1):
print(term.underline('This text is at the bottom.'))
# Clear the screen
# print(term.clear)
# Example of does_styling for graceful degradation
if term.does_styling:
print(term.bold('Terminal supports styling!'))
else:
print('Terminal does not support styling, printing plain text.')