Handy ANSI color and text-style helpers for beautiful Python terminal output.
Project description
printcolorpt
printcolorpt is a handy ANSI styling helper for Python.
It gives you short, memorable functions for colored terminal output:
from pt import *
printR("error")
printG("success")
printY("warning")
printB("info")
printO("orange")
printC("cyan")
printD("debug")
Version 0.2.0 expands the public API from 10 helpers to 17 helpers:
- 7 full-line print helpers
- 7 inline color wrappers
- 3 raw text-style constants (NEW)
Installation
pip install printcolorpt
Quick start
from pt import *
printR("failed", bold=True)
printG("completed", underline=True)
printY("check this value", italic=True)
printD("debug log", bold=True, italic=True)
The print* helpers behave like Python's built-in print() for common arguments such as sep, end, file, and flush.
from pt import *
printB("x", "y", "z", sep=" -> ")
printC("loading", end="... ", flush=True)
printG("done")
Full-line color printing
Use these when the entire output line should have one color.
from pt import *
printR("red")
printG("green")
printY("yellow")
printB("blue")
printO("orange")
printC("cyan")
printD("dark gray debug")
Each print helper supports the same three style flags:
from pt import *
printR("bold red", bold=True)
printG("italic green", italic=True)
printB("underlined blue", underline=True)
printO("bold italic underlined orange", bold=True, italic=True, underline=True)
Inline color composition
Use uppercase color wrappers when one line needs multiple colors.
from pt import *
print(
RED("ERROR")
+ " | "
+ YELLOW("retrying")
+ " | "
+ GREEN("recovered")
)
A practical status line:
from pt import *
filename = "records.parquet"
rows = 1_240_000
seconds = 3.82
print(
BLUE("READ")
+ " "
+ filename
+ " | "
+ GREEN(f"{rows:,} rows")
+ " | "
+ DEBUG(f"{seconds:.2f}s")
)
A clean validation summary:
from pt import *
passed = 132
failed = 1
skipped = 4
print(
BOLD + "TEST "
+ GREEN(f"PASS={passed}")
+ " "
+ RED(f"FAIL={failed}")
+ " "
+ YELLOW(f"SKIP={skipped}")
)
Text styles
BOLD, ITALIC, and UNDERLINE are raw ANSI style constants.
from pt import *
print(BOLD + RED("bold red"))
print(ITALIC + BLUE("italic blue"))
print(UNDERLINE + CYAN("underlined cyan"))
When composing several styled segments, remember that every color wrapper resets the style at the end of its own text. Re-apply a style before the next segment when needed.
from pt import *
print(
ITALIC + RED("italic red")
+ " "
+ ITALIC + UNDERLINE + BLUE("italic underlined blue")
)
Debugging recipes
Compact debug markers
from pt import *
printD("[1/4] load input")
printB("[2/4] normalize columns")
printY("[3/4] validate missing values")
printG("[4/4] export completed")
Loop progress
from pt import *
items = ["address", "geometry", "date", "score"]
for i, name in enumerate(items, start=1):
printB(f"[{i}/{len(items)}] processing {name}")
# do something here
printG("all steps completed", bold=True)
Exception-friendly output
from pt import *
try:
value = int("not-a-number")
except ValueError as e:
printR("ValueError:", e, bold=True)
printD("hint: check the input type before conversion")
Data pipeline style
from pt import *
print(BOLD + BLUE("PIPELINE START"))
printD("reading source file")
printY("missing values detected in 2 columns")
printG("geometry validation passed")
print(BOLD + GREEN("PIPELINE DONE"))
Public API
Print helpers
| Function | Color | Typical use |
|---|---|---|
printR(...) |
red | errors, failures |
printG(...) |
green | success, completion |
printY(...) |
yellow | warnings, checkpoints |
printB(...) |
blue | information, steps |
printO(...) |
orange | highlights, attention |
printC(...) |
cyan | secondary information |
printD(...) |
dark gray | debug messages |
Inline color wrappers
| Function | Color |
|---|---|
RED(text) |
red |
GREEN(text) |
green |
YELLOW(text) |
yellow |
BLUE(text) |
blue |
ORANGE(text) |
orange |
CYAN(text) |
cyan |
DEBUG(text) |
dark gray |
Style constants
| Constant | Meaning |
|---|---|
BOLD |
bold text |
ITALIC |
italic text |
UNDERLINE |
underlined text |
0.2.0 highlights
- Added
printO()andORANGE(). - Added
printC()andCYAN(). - Added
BOLD,ITALIC, andUNDERLINE. - Added style flags to print helpers:
bold,italic,underline. - Keeps the original simple import style:
from pt import *. - Still no external dependencies.
Notes
This package uses ANSI escape sequences. Color rendering depends on the terminal or notebook frontend. It works best in modern terminals, VS Code terminals, and Jupyter environments that support ANSI colors.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file printcolorpt-0.2.0.tar.gz.
File metadata
- Download URL: printcolorpt-0.2.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8df4315e27fe38884b54cdc224f0c1983e10ffb5388e94181f0f624e30d3ea1
|
|
| MD5 |
01f36db4ce710f6c4e6c1b12d62d290b
|
|
| BLAKE2b-256 |
7305bf571b57d00182c4650cffec62d52173785d1cc00944f21b1aa6c893879e
|
File details
Details for the file printcolorpt-0.2.0-py3-none-any.whl.
File metadata
- Download URL: printcolorpt-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4d340b6f136cdf436939d1b5e283e363f4304605ccf506211363f4955130d03
|
|
| MD5 |
2489b6b8a03b104b6f4488ee732be5a4
|
|
| BLAKE2b-256 |
08129634d8f4fbb6aa9ddf7490240a439c695c1eea1c96f9db63091593cb02b4
|