Skip to main content

K o l o r o

CI status PyPI version PyPI - Downloads

Koloro - colorful terminal text in Python

Koloro preview

Usage

Install with pip:

pip install koloro
import koloro

print(koloro.red(f"Error: something was wrong in {koloro.cyan('main.py')}"))

The following environment variables can be used to disable color output globally:

  • Disable settings:

    • NO_COLOR (assigning something to NO_COLOR disables color output regardless of the value)
    • TERM=dumb
  • Enable settings:

    • FORCE_COLOR (assigning something to FORCE_COLOR enables color output regardless of the value)

Moreover, the enabled variable can also be used to toggle color output on and off:

import koloro

# color output on
koloro.enabled = True
print(koloro.cyan("foo"))  # -> "\u001b[36mfoo\u001b[39m"

# color output off
koloro.enabled = False
print(koloro.cyan("foo"))  # -> "foo"

Stripping ANSI codes function is also provided:

import koloro

print(koloro.cyan("foo"))  # -> "\u001b[36mfoo\u001b[39m"
print(koloro.strip_ansi(koloro.cyan("foo")))  # -> "foo"

There is also functions for ANSI 256 colors output:

import koloro

# code number 12 from https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
print(koloro.ansi256(12)('foo'))  # -> "\u001b[38;5;12mfoo\u001b[0m"
import koloro

# code number 12 from https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
print(koloro.ansi256Bg(12)(koloro.black('foo')))  # -> "\u001b[48;5;12mfoo\u001b[0m"

API Reference

Below functions require one argument txt.

Modifiers

  • reset
  • bold
  • dim
  • italic
  • underline
  • inverse
  • hidden
  • strikethrough

Colors

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white

Background colors

  • bgBlack
  • bgRed
  • bgGreen
  • bgYellow
  • bgBlue
  • bgMagenta
  • bgCyan
  • bgWhite

Bright colors

  • grey
  • brightRed
  • brightGreen
  • brightYellow
  • brightBlue
  • brightMagenta
  • brightCyan
  • brightWhite

Bright background colors

  • bgGrey
  • bgBrightRed
  • bgBrightGreen
  • bgBrightYellow
  • bgBrightBlue
  • bgBrightMagenta
  • bgBrightCyan
  • bgBrightWhite

ANSI 256 colors

  • ansi256

    • Arguments:

      • n (int) - color code from ANSI 256
    • Returns:

      • a function who argument is the text to display color output
  • ansi256Bg

    • Arguments:

      • n (int) - color code from ANSI 256
    • Returns:

      • a function who argument is the text to display color output
  • strip_ansi

    • Arguments:

      • string (str) - ANSI colored string
    • Returns:

      • a string which no ANSI codes

License

MIT

Metadata

Release files for koloro 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

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

Release files / koloro-0.1.4-py3-none-any.whl

Download URL koloro-0.1.4-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f33f4de6e76c99e3fa1134d76d12665e94d073ba7b2311d146e3e87c7d3f94e0
BLAKE2b-256 checksum
How to use checksums
5a043986aba22f341b8b13b1ef2f1610c5d9bc0260c6f9f45fbbfdbcda84fbb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.10

Security for koloro 0.1.4

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