Skip to main content

clitint

Very fast terminal text formatting 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.

This library is ideal for simple and very fast formatting of text on libraries and command-line tools.

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

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.3
File Size Uploaded Provenance Actions
clitint-0.1.3.tar.gz 15.0 kB Without provenance Details for clitint-0.1.3.tar.gz

Built distribution (wheel)

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

Total release size: 25.1 kB

Release files / clitint-0.1.3.tar.gz

Download URL clitint-0.1.3.tar.gz
Size 15.0 kB
Tags Source
SHA-256 checksum
How to use checksums
584256e86354a09277e4a49e2987a79db013301a37b58d6bcdd85196d810606e
BLAKE2b-256 checksum
How to use checksums
2aa61a5a70c6250f1042ea97cfe3090a94d9555bc9cb2318b2aa6da8683717ca
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.3-py3-none-any.whl

Download URL clitint-0.1.3-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
298ec64c4e494b27f9bfd19f1607baec3f8c61c2d4726f42259179405832ec5f
BLAKE2b-256 checksum
How to use checksums
fa129831468fae92738ff0b77d6757768ff58779b01dbd74bb259f5fa79385d0
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.3

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