tidyprint
tidyprint is a dependency-free Python library for adding ANSI text styles
and colors, log prefixes, and ASCII or Unicode borders to terminal output.
Requirements
- Python 3.10 or newer
- No runtime dependencies
Install
From a local checkout:
python -m pip install .
To build distributable wheel and source archive files:
python -m pip install build
python -m build
The generated files are written to dist/. To install a built wheel:
python -m pip install dist/tidyprint-0.2.0-py3-none-any.whl
Quick start
from tidyprint import print
print("Hello", color="blue", border="stars")
print("Success!", color="bright_green", bold=True, underline=True)
print("First line\nSecond line", border="rounded", title="Notice", padding=1)
print("Cache cleared", level="INFO", color=(80, 180, 255))
tidyprint.print writes the formatted message to standard output by default,
just like Python's built-in print.
API
tidyprint.print(
*values,
sep=" ",
end="\n",
file=None,
flush=False,
color=None,
bg_color=None,
bold=False,
underline=False,
italic=False,
dim=False,
reversed=False,
strikethrough=False,
border=None,
title=None,
justify="left",
padding=0,
timestamp=False,
level=None,
)
Standard print options
*values: Objects to print. Each is converted to text withstr().sep: Text between values; defaults to a space.Nonealso means a space.end: Text appended at the end; defaults to a newline.file: Writable text stream; defaults to standard output.flush: Flush the output stream when true.
Formatting options
color: Foreground color. Accepts a basic color name (black,red,green,yellow,blue,magenta,cyan,white), a bright name such asbright_red, a foreground ANSI code from30-37or90-97, a#RRGGBBstring, or an(red, green, blue)integer tuple (channels0-255).bg_color: Background color using the same forms; ANSI codes are40-47for standard backgrounds and100-107for bright backgrounds.bold,underline,italic,dim,reversed,strikethrough: Set any of these booleans to enable the corresponding terminal text style.border:stars,hashes,equals, orboxfor ASCII;unicodefor single-line box drawing;doublefor double-line box drawing; orroundedfor rounded Unicode corners.title: Optional text inset into the top border. Requiresborder.justify: Aligns each line within the border:left,center, orright. Shorter lines are padded to the width of the longest line.padding: Non-negative number of spaces between text and the border walls. Requiresborder.timestamp: Set toTrueto prepend the current local time inYYYY-MM-DD HH:MM:SSformat.level: Optional non-empty log level; it is uppercased and prepended in brackets, such as[INFO]or[ERROR]. Can be combined withtimestamp.
Styles and colors are emitted as ANSI escape sequences. Terminals that do not
support ANSI styling may display those sequences instead of formatting them.
Invalid style names, colors, borders, and alignment values raise ValueError.
Examples
from tidyprint import print
# Multiple values and standard print options work as usual.
print(
"Status:",
"ready",
end="!\n",
color="bright_green",
bg_color=40,
bold=True,
underline=True,
)
# A titled rounded box aligns and pads its contents.
print(
"Build complete\nAll checks passed",
border="rounded",
title="Build",
justify="center",
padding=1,
)
# Prefix output with a timestamp and log level.
print("Connection established", timestamp=True, level="INFO")
# HEX and RGB colors support 24-bit TrueColor terminals.
print("Custom color", color="#55AAFF", bg_color=(20, 30, 40))
# Send the output to a file or another writable text stream.
with open("output.txt", "w", encoding="utf-8") as output:
print("Saved output", file=output)
Development
Run the unit tests from the project root:
python -m unittest discover -s tests -v
Metadata
Release files for tidyprint 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tidyprint-0.2.0.tar.gz | 9.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tidyprint-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.1 kB
Release files / tidyprint-0.2.0.tar.gz
| Download URL | tidyprint-0.2.0.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d0176c521444b9af934d38234b56cb681490d34b46d629cd5fe40b7d6dfee736
|
|
BLAKE2b-256 checksum How to use checksums |
b5e2d60faa8f935b8bf6d8f9176ab19e9e9c77c9fddf220cdda924830d9c3d11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / tidyprint-0.2.0-py3-none-any.whl
| Download URL | tidyprint-0.2.0-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d4f414dcd13854c7567c429953bec793f40ee568c2c027c5973539608533a1f5
|
|
BLAKE2b-256 checksum How to use checksums |
03f3bf2965b1f3b42b98d7af35f13582edf966bb7213c92a31516e8ba5e7243e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|