Skip to main content

clitint

Coloured terminal text for Python 3.13+, with no dependencies. Text is coloured only when someone is reading it on a terminal: redirect the output to a file, a pipe or a CI log and it comes out plain.

from clitint import formatter

print(formatter("error:", "bold_red"), "file not found")
print(formatter("warning", "underline_black_highlight_yellow"))

Install

pip install clitint

Specs

A spec is a set of styles joined by _, in any order: "red", "bold_red", "red_bold", "italic_white_highlight_blue".

Kind Names
Attributes bold, dim, italic, underline
Colours black, red, green, yellow, blue, magenta, cyan, white, grey, orange
Backgrounds highlight_ followed by a colour: highlight_blue

You can also combine: bold_highlight_blue, italic_red, underline_green, etc.

An unknown name, two colours or two backgrounds raise a ValueError that names the problem. formatter takes any object and writes its str. Each spec is worked out once and remembered.

When text is coloured

formatter decides at every call, in this order:

  1. what the program chose: turn_colours_off() or turn_colours_on() (let_the_environment_decide() undoes it);
  2. CLITINT_COLOURS_OFF=1, NO_COLOR or ANSI_COLORS_DISABLED: plain;
  3. FORCE_COLOR: coloured;
  4. TERM=dumb: plain;
  5. otherwise, coloured only when both stdout and stderr are terminals.

The last rule is there because a string doesn't know where it is going. An error message might be printed, logged or raised. 2> errors.log with stdout on a terminal still gives a plain message, so no escape codes end up in the log.

colours_on() tells you the answer now.

Other tools

from clitint import strip_colours, escapes, one_decision, coloured

strip_colours(formatter("x", "red"))        # 'x': every ANSI style sequence removed (for tests and logs)

with one_decision():                        # one message: decide once, not at every formatter call
    line = formatter("a", "red") + " " + formatter("b", "blue")

red, reset = escapes("red")                 # the raw sequences, for a hot f-string
text = f"{red}x{reset}" if coloured() else "x"

Licence

MIT

Metadata

Release files for clitint 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 clitint 0.1.0
File Size Uploaded Provenance Actions
clitint-0.1.0.tar.gz 11.3 kB Without provenance Details for clitint-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 19.3 kB

Release files / clitint-0.1.0.tar.gz

Download URL clitint-0.1.0.tar.gz
Size 11.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4c12335f44195202c5768ade495aa31ae98e13b0757c8500a4f95befe1f4209c
BLAKE2b-256 checksum
How to use checksums
d8fad1ecfb98567aeb81bc2737d90b1ed96ad18e6c4df1686ab0ff13d27939a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

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

Download URL clitint-0.1.0-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
57af3317624952afbe668a03329f4e5d99da86f1a11ec1347bf76f56c20bc914
BLAKE2b-256 checksum
How to use checksums
f4d503ca3b0a569f2927f989bfea9fa55de0121dd553c18cb1178217db6fe086
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for clitint 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.

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