Minimal, dependency-free helpers for color-formatted terminal messages
Project description
colored_messages
A minimal, dependency-free Python library for printing color-formatted messages in Linux/macOS terminals using ANSI escape codes.
Features
- Four ready-made print helpers —
print_error,print_warning,print_info,print_success— each with a colored[Tag]prefix, usable with zero configuration. - Low-level building blocks —
term_colorfor full control over every ANSI attribute (bold, dim, italic, underline, highlight, reverse, color). - Named color shortcuts —
red(),green(),yellow(),blue(),bold()for quick inline formatting. - No dependencies — only the Python standard library is required.
Installation
pip install colored-messages
Quick start
from colored_messages import print_error, print_warning, print_info, print_success
print_info("Loading configuration…")
print_success("Server started on port 8080")
print_warning("Disk usage above 80 %")
print_error("Connection refused")
Terminal output:
[Info] Loading configuration…
[OK] Server started on port 8080
[Warning] Disk usage above 80 %
[Error] Connection refused ← printed to stderr
Each tag is rendered in its matching color (blue / green / yellow / red).
print_error writes to sys.stderr; the other three write to sys.stdout.
API reference
Print helpers
| Function | Tag | Color | Bold tag | Stream |
|---|---|---|---|---|
print_info(msg) |
[Info] |
Blue | No | stdout |
print_success(msg) |
[OK] |
Green | Yes | stdout |
print_warning(msg) |
[Warning] |
Yellow | No | stdout |
print_error(msg) |
[Error] |
Red | Yes | stderr |
custom_print
Print any message with a fully custom tag:
from colored_messages import custom_print, TermColors
custom_print("Starting backup…", TermColors.CYAN, "Backup", bold=True)
# → [Backup] Starting backup…
Additional keyword arguments are forwarded to print() (e.g. file=, end=,
flush=).
Named color shortcuts
from colored_messages import red, green, yellow, blue, bold
print(f"Status: {green('OK')}")
print(f"Level: {red('CRITICAL', bold=True)}")
print(f"Title: {bold('Important notice')}")
Each shortcut accepts an optional bold=True keyword argument.
term_color — full control
from colored_messages import term_color, TermColors
s = term_color(
"hello",
color=TermColors.PURPLE,
bold=True,
underline=True,
italic=True,
)
print(s)
Supported attributes:
| Keyword | SGR code | Effect |
|---|---|---|
bold=True |
1 | Increased intensity |
dim=True |
2 | Decreased intensity |
italic=True |
3 | Italic text |
underline=True |
4 | Single underline |
highlight=True |
7 | Reverse video (swap fg/bg) |
reverse=True |
— | Use color as background instead of foreground |
bold — preserve surrounding color
from colored_messages import bold, term_color, TermColors
# The bold wrapper uses SGR 22 (normal intensity) instead of SGR 0 (full
# reset), so an outer color is not disturbed:
msg = term_color(f"prefix: {bold('important')} suffix", TermColors.BLUE)
print(msg)
TermColors
from colored_messages import TermColors
TermColors.GRAY # 0
TermColors.RED # 1
TermColors.GREEN # 2
TermColors.YELLOW # 3
TermColors.BLUE # 4
TermColors.PURPLE # 5
TermColors.CYAN # 6
TermColors.WHITE # 7
TermColors is an IntEnum, so its members can be used directly as integers.
Development
This project uses uv and just.
# Run linter, type checker, and test suite
just test
Individual commands:
uv run ruff check --fix . # lint & auto-fix
uv run mypy . # type checking
uv run pytest tests # unit tests
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file colored_messages-0.1.1.tar.gz.
File metadata
- Download URL: colored_messages-0.1.1.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cdafe130bcdad54463ed7986590d806888ea86229778425d25a2ccad5d813cc
|
|
| MD5 |
78fc3c304cbb0d650381ad34606ab348
|
|
| BLAKE2b-256 |
49385095c4d1afa34e1322c9760c899f221aa4b9bea942fd037190d9fb79c23f
|
File details
Details for the file colored_messages-0.1.1-py3-none-any.whl.
File metadata
- Download URL: colored_messages-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ea613d51318377b072abaf3a270660b056bb70b6d75e9077e7f1ae564703be8
|
|
| MD5 |
0a8e35b09334fdeebccc44fb65d30400
|
|
| BLAKE2b-256 |
7395ce8d0906171f470b5577b0cd7b7ade2d840216a3feec5bb377334b2b1e8d
|