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
Metadata
Release files for colored-messages 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| colored_messages-0.1.1.tar.gz | 5.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| colored_messages-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.4 kB
Release files / colored_messages-0.1.1.tar.gz
| Download URL | colored_messages-0.1.1.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5cdafe130bcdad54463ed7986590d806888ea86229778425d25a2ccad5d813cc
|
|
BLAKE2b-256 checksum How to use checksums |
49385095c4d1afa34e1322c9760c899f221aa4b9bea942fd037190d9fb79c23f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / colored_messages-0.1.1-py3-none-any.whl
| Download URL | colored_messages-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ea613d51318377b072abaf3a270660b056bb70b6d75e9077e7f1ae564703be8
|
|
BLAKE2b-256 checksum How to use checksums |
7395ce8d0906171f470b5577b0cd7b7ade2d840216a3feec5bb377334b2b1e8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Security for colored-messages 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.