colorprint
A simple Python library for colored terminal output.
Features
- Named colors
- HEX colors
- Short HEX colors
cprint()function@coloreddecorator- No external dependencies
- Python 3.10+
Installation
Install the package from PyPI:
pip install colorprint
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.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 | |
|---|---|---|---|---|
| colorprint_python-0.1.1.tar.gz | 3.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| colorprint_python-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.8 kB
Release files / colorprint_python-0.1.1.tar.gz
| Download URL | colorprint_python-0.1.1.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1806a6690976d6ccfec058adaf3a6c4bedd3e93ba6602d7a080c024af7615a3d
|
|
BLAKE2b-256 checksum How to use checksums |
c5ba49c8243eb3d61c2123ff3ed772a3a38e4937c4090df3c28e7b4b96b385b6
|
| 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.1-py3-none-any.whl
| Download URL | colorprint_python-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
67c458540ba03a7ba792baedd489c5753a825614908f22f76dd12bd1f5553b22
|
|
BLAKE2b-256 checksum How to use checksums |
c1af7e81051ab58c461810f89ce87cff04f875ec76f020cb1f35841db55297bb
|
| 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.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.