Skip to main content

colorprint

A simple Python library for colored terminal output.

Features

  • Named colors
  • HEX colors
  • Short HEX colors
  • cprint() function
  • @colored decorator
  • No external dependencies
  • Python 3.10+

Installation

Install the package from PyPI:

pip install colorprint

For development, clone the repository and install it in editable mode:

git clone https://github.com/your-username/colorprint.git
cd colorprint
python -m pip install -e .

Usage

Basic usage

Import cprint:

from colorprint import cprint

Use a named color:

cprint("Hello!", color="red")
cprint("Success!", color="green")
cprint("Warning!", color="yellow")
cprint("Information!", color="cyan")

You can also omit the color argument:

cprint("Hello!")

Supported colors

The following colors are available:

black
red
green
yellow
blue
magenta
cyan
white

Example:

cprint("Black", color="black")
cprint("Red", color="red")
cprint("Green", color="green")
cprint("Yellow", color="yellow")
cprint("Blue", color="blue")
cprint("Magenta", color="magenta")
cprint("Cyan", color="cyan")
cprint("White", color="white")

HEX colors

colorprint supports custom HEX colors.

cprint("Blue", color="#00aaff")
cprint("Purple", color="#a020f0")
cprint("Orange", color="#ff8800")

Short HEX notation is also supported:

cprint("White", color="#fff")
cprint("Red", color="#f00")
cprint("Green", color="#0f0")

Both of these are equivalent:

cprint("Hello", color="#fff")
cprint("Hello", color="#ffffff")

Decorator

colorprint provides the @colored decorator.

Import it:

from colorprint import colored

Use it with a function:

@colored("green")
def hello():
    return "Hello, world!"

hello()

The decorator prints the return value using the selected color.

Function arguments

The decorator works with functions that accept arguments:

from colorprint import colored

@colored("cyan")
def add(a, b):
    return a + b

result = add(10, 20)

print(result)

Output:

30

The result is still returned normally, so you can store it in a variable.

HEX with decorator

HEX colors can also be used with the decorator:

from colorprint import colored

@colored("#00aaff")
def message():
    return "Custom colored message"

message()

Error handling

An unknown color raises ValueError:

from colorprint import cprint

cprint("Hello", color="unknown")

Result:

ValueError: Unknown color: unknown

An invalid HEX color also raises ValueError:

cprint("Hello", color="#xyz")

Example

A complete example:

from colorprint import cprint, colored

cprint("Hello!", color="red")
cprint("Success!", color="green")
cprint("Warning!", color="yellow")
cprint("Custom color!", color="#00aaff")


@colored("cyan")
def hello():
    return "Hello from decorator!"


@colored("#a020f0")
def add(a, b):
    return a + b


hello()

result = add(10, 20)

print(f"Result: {result}")

Project structure

colorprint/
├── src/
│   └── colorprint/
│       ├── __init__.py
│       └── colors.py
├── tests/
│   └── colors_test.py
├── main.py
├── README.md
├── pyproject.toml
└── .gitignore

Development

Create a virtual environment:

python -m venv .venv

Activate it on Linux/macOS:

source .venv/bin/activate

Install the package:

python -m pip install -e .

Install pytest:

python -m pip install pytest

Run tests:

python -m pytest

Requirements

  • Python 3.10 or newer
  • No external runtime dependencies

Metadata

Release files for colorprint-python 0.1.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 colorprint-python 0.1.0
File Size Uploaded Provenance
colorprint_python-0.1.0.tar.gz 3.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for colorprint-python 0.1.0
File Interpreter ABI Platform
colorprint_python-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.9 kB

Release files / colorprint_python-0.1.0.tar.gz

Download URL colorprint_python-0.1.0.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cb4fb51a8b0acb6f22ddcb1b36be48000da5c7ae324de4b6589be81f1da78b29
BLAKE2b-256 checksum
How to use checksums
6de845440bece7d54a8cca6c4cdd44a93e62d1291837a77fda99165a34f6fcac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / colorprint_python-0.1.0-py3-none-any.whl

Download URL colorprint_python-0.1.0-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e1fb98bd1e47f629f5b6924e729105cf9855d97d43ca248018d2d344bfa39fc
BLAKE2b-256 checksum
How to use checksums
9b17e97cd8d75501da4c1e69340c316429017df889a4e4fa6ed31f192f350181
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Security for colorprint-python 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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