Blessed
Blessed is an easy, practical Python library for making terminal applications, offering an elegant interface to handle colors, keyboard input, and screen positioning. It is currently at version 1.38.0 and maintains an active development and release cadence, with frequent updates improving compatibility and adding features.
Warnings
- breaking Python 3.7 and earlier versions are no longer supported since Blessed version 1.28. Attempting to use Blessed 1.28+ with Python 3.7 or older will result in an ImportError.
- deprecated The `Terminal.move()` method is deprecated in favor of `Terminal.move_xy(x, y)`. Also, compoundable attributes like `superscript`, `subscript`, `shadow`, and `dim` with colors (e.g., `term.blue_subscript('a')`) are deprecated as they are rarely supported by terminals.
- gotcha The `Terminal.location()` context manager cannot be nested. Entering a new `location` context while another is active may lead to unexpected cursor behavior.
- gotcha Blessed automatically omits terminal styling sequences if output is redirected to a non-terminal (e.g., a file or pipe). This is a feature, but can be a gotcha if styling is expected in piped output.
- gotcha Earlier versions of Blessed had less robust Windows support, particularly concerning `async_inkey()`, mouse events, and resize notifications. `async_inkey()` raised `NotImplementedError` on Windows prior to 1.33, and general performance for keyboard input was much slower.
- gotcha Fixes for Kitty keyboard protocol (correct key identification for CSI, alphanumeric keys, etc.) were applied in versions 1.30 and 1.36. Users of Kitty terminal emulators on older Blessed versions might experience incorrect key detection.
Install
-
pip install blessed
Imports
- Terminal
from blessed import Terminal
Quickstart
from blessed import Terminal
import os
term = Terminal()
print(term.home + term.clear + term.move_y(term.height // 2))
print(term.black_on_darkkhaki(term.center('press any key to continue.')))
with term.cbreak(), term.hidden_cursor():
# Use os.environ.get for auth keys in real applications if needed
inp = term.inkey(timeout=os.environ.get('BLESSED_INKEY_TIMEOUT', 3))
print(term.move_down(2) + 'You pressed ' + term.bold(repr(inp)))
print(term.normal + 'Exiting.')