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.4.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.4.0
File Size Uploaded
colorful_log-0.4.0.tar.gz 4.1 kB Details

Built distribution (wheel)

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

Total release size: 10.0 kB

Release files / colorful_log-0.4.0.tar.gz

Download URL colorful_log-0.4.0.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9b82f1b6fb1f368a2b14fb9badcd037426b6ff85e0627ed2faa09946e67d6229
BLAKE2b-256 checksum
How to use checksums
9e9cc64d99971dd142062df7ef4cb74e7a36eb6a1bc3cc69eea25116b089e4f9
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.4.0-py3-none-any.whl

Download URL colorful_log-0.4.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a24d0f5ec742d3839eaa3c373515168663e91c1a7a1aa9debade6d7d138166e9
BLAKE2b-256 checksum
How to use checksums
c3c3bd3149cb691e5d4900ec5639d65940db224f88e3debe59883b46974c80c7
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

0.5.0

2 release files

This release

0.4.0 This release

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