Skip to main content

clitint

Coloured terminal text for Python 3.13+, with no dependencies.

Python Dependencies Typed Licence

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

text_1 = formatter("error:", "bold_red")
text_2 = formatter("warning", "underline_black_highlight_yellow")
print(text_1, "file not found")
print(text_2)
clitint printing a bold red 'error:' and an underlined black-on-yellow 'warning' in a terminal, and plain text when redirected to a file

It is made for libraries and tools that build messages: one call with a short spec, an answer that follows the environment as it is now, and colours only when both stdout and stderr are terminals, so an error message that ends up in a log has no escape codes in it.

📦 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, e.g. highlight_blue

Combine as many attributes as you like with at most one colour and one background: bold_highlight_blue, italic_red, underline_green.

  • 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:

# Condition Result
1 turn_colours_off() / turn_colours_on() was called as chosen
2 NO_COLOR, ANSI_COLORS_DISABLED or CLITINT_COLOURS_OFF=1 plain
3 FORCE_COLOR coloured
4 TERM=dumb plain
5 otherwise coloured only when both stdout and stderr are terminals

let_the_environment_decide() undoes rule 1, and colours_on() tells you the answer now.

NO_COLOR and FORCE_COLOR count when they are set to anything but an empty string, as no-color.org and force-color.org say (FORCE_COLOR=0 forces too). On Windows 10 and 11 the console is asked to read escape sequences; where it can't, text is plain unless forced.

🧰 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.2

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.2
File Size Uploaded Provenance Actions
clitint-0.1.2.tar.gz 14.4 kB Without provenance Details for clitint-0.1.2.tar.gz

Built distribution (wheel)

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

Total release size: 23.9 kB

Release files / clitint-0.1.2.tar.gz

Download URL clitint-0.1.2.tar.gz
Size 14.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1c46255f834c56696038149f30170747d757d50a4b89b73e90598d77f959e0f5
BLAKE2b-256 checksum
How to use checksums
b2ca9ddcee48fb6f37ead27ada7c379fff35bf74d2251470a0bdba3329b72e53
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.2-py3-none-any.whl

Download URL clitint-0.1.2-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a94742d957f299b6ce4788692a3418e93b6f3e1b3155d197c64b41b720aebf81
BLAKE2b-256 checksum
How to use checksums
99da2ab195cd2cb65670ea3832bb2146ef87facf205d9eda222203899b22cbb0
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.2

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