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.1

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.1
File Size Uploaded Provenance Actions
clitint-0.1.1.tar.gz 11.5 kB Without provenance Details for clitint-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 19.5 kB

Release files / clitint-0.1.1.tar.gz

Download URL clitint-0.1.1.tar.gz
Size 11.5 kB
Tags Source
SHA-256 checksum
How to use checksums
672fdd30f7ece0e241332b5a52c5086c3f96017221bdcbdae556543a763a9d8d
BLAKE2b-256 checksum
How to use checksums
1d5a2c1dea20f5009c1ac2c178880b4d6a590eef798474a7a29a63ba72d42817
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.1-py3-none-any.whl

Download URL clitint-0.1.1-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a824bc9d00b99f909acd144884026b3c65bdfe9b4f26eb6bf769b8d7aefefe26
BLAKE2b-256 checksum
How to use checksums
79d8fd31df927aed3f948e6d79630fa04fcd42701a46c4413fa7cd3ecef7a15c
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.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.

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