Skip to main content

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 helpersprint_error, print_warning, print_info, print_success — each with a colored [Tag] prefix, usable with zero configuration.
  • Low-level building blocksterm_color for full control over every ANSI attribute (bold, dim, italic, underline, highlight, reverse, color).
  • Named color shortcutsred(), 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

colored_messages-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

colored_messages-0.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file colored_messages-0.1.0.tar.gz.

File metadata

  • Download URL: colored_messages-0.1.0.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

Hashes for colored_messages-0.1.0.tar.gz
Algorithm Hash digest
SHA256 568b00ed030a5dd85c6e0030e41521dbf2054293e7e3318065fd1ecaf04b9671
MD5 76a564afe8b98e0a4646ef5b044d265d
BLAKE2b-256 be66c76c76fddccca39c2f614aeb314167ee56c8861f11f504d578614d370556

See more details on using hashes here.

File details

Details for the file colored_messages-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: colored_messages-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 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

Hashes for colored_messages-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fedc62249a8aaafc62f51030be1152ec07945a6561004b60e74746167c1de665
MD5 dd44ac42454634fa857c70e6a2fd9cab
BLAKE2b-256 d96b69026c021246cd29554e972ebb6829836cde7816782b331bfcd8525536cb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page