Skip to main content

colorful-log

PyPI version Python versions License

A small Python library for coloring and styling terminal text, without writing raw ANSI escape codes by hand.

from colorful_log import PrintLog, Colors

print(PrintLog("Build succeeded").color(Colors.GREEN).bold())

Why colorful-log?

Terminal colors are done with escape sequences like \033[1;32m, which are hard to read, easy to get wrong, and easy to forget to reset. colorful-log wraps them in a small, readable API:

  • Readable code. PrintLog("Done").color(Colors.GREEN).bold() says what it does. No escape codes to memorize.
  • Hex colors out of the box. Use "#6381f6" directly, for both text and background.
  • Reusable styles. Build a template once (for example an "error" style) and reuse it for any text.
  • Lightweight. One small dependency (typing-extensions), fully typed, and works on Python 3.10+.

Installation

pip install colorful-log

Requires Python 3.10 or newer.

Features

  • Foreground and background colors from built-in colors, hex codes, or your own registered colors
  • Text styles: bold, dim, italic, underline, reverse, and strikethrough
  • Method chaining and a short | operator for setting the text color
  • Reusable templates with copy(), and an easy way to swap the text with a call
  • Custom color registry, which can also override built-in colors
  • plain property to get the text without any formatting
  • Separate resets for colors (reset()) and styles (reset_style())
  • Clear ValueError for invalid hex colors

Usage

Basic

from colorful_log import PrintLog, Colors

print(PrintLog("Hello, World!").color(Colors.CYAN))
print(PrintLog("Hello, World!").color("#6381f6").background("#1e1e2e"))

Built-in colors: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE.

Text styles

Styles can be chained in any order.

PrintLog("Important").bold().underline()
PrintLog("Deprecated").dim().strikethrough()

Available styles: bold(), dim(), italic(), underline(), revert() (reverse video), strikethrough().

Setting the color with |

The | operator is a shortcut for setting the text color.

print(PrintLog("Warning: disk almost full") | Colors.YELLOW)
print(PrintLog("Custom") | "#ff8800")

Custom colors

Register a color once and use it anywhere.

Colors.register("brand", "#6381f6")

print(PrintLog("Brand color") | Colors.brand)

Registering a name that already exists replaces it, including the built-in colors:

Colors.register("RED", "#ff5555")   # Colors.RED is now #ff5555

This is global, so it affects every use of Colors.RED in your program. RESET, register, and names starting with _ are reserved and raise a ValueError.

Templates

Calling a PrintLog instance replaces its text and keeps its formatting, so you can define a style once and reuse it.

error = PrintLog().color(Colors.WHITE).background(Colors.RED).bold()

print(error("Something went wrong"))
print(error("Another error"))

Calling an instance (and using +) modifies that same object and returns it. If you need independent results, use copy():

a = error.copy()("First")
b = error.copy()("Second")

Appending text

msg = PrintLog("Hello")
print(msg + ", World!")      # appends to the existing text

Plain text

plain returns the text without any color or style codes, which is useful for logs or files.

error("Disk full").plain     # "Disk full"

Resetting

style = PrintLog("text").bold().color(Colors.RED)

style.reset()          # clears foreground and background colors, keeps styles
style.reset_style()    # clears text styles, keeps colors

Invalid colors

Invalid hex values raise a ValueError with a clear message.

PrintLog("x") | "#GGGGGG"
# ValueError: Invalid HEX color: '#GGGGGG'. Expected format: '#RRGGBB'.

Only the #RRGGBB format is supported.

Notes

  • Hex colors use 24-bit ("truecolor") ANSI codes. Most modern terminals support them, but some older ones do not.
  • Output contains ANSI escape codes. Use .plain if you need clean text, for example when writing to a file.

License

Released under the MIT License.

Author

Finsa Kusuma Putra (@Finsa-SC)

Metadata

Release files for colorful-log 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for colorful-log 0.5.0
File Size Uploaded
colorful_log-0.5.0.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for colorful-log 0.5.0
File Interpreter ABI Platform
colorful_log-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.0 kB

Release files / colorful_log-0.5.0.tar.gz

Download URL colorful_log-0.5.0.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c5daa018c049c233ed133ef9c306352075380d49468752568ea5b980dfbda6b9
BLAKE2b-256 checksum
How to use checksums
fb5c2cd5e76a73f2d9d78def99891e3d6dc1b8b79f9bb7281911857e104bad96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release files / colorful_log-0.5.0-py3-none-any.whl

Download URL colorful_log-0.5.0-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c4176a843214293541763b1fdb7a2c61a90e90390a9cfaaa1ea1b1fc77a9ac9a
BLAKE2b-256 checksum
How to use checksums
ef83e10a407e63ac402a88345894ccedd0f09c74b5d5c7b8fba84141412855c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page