Skip to main content

Yet another ANSI color text library for Python. Provides “auto colors” for dark/light terminals. Works on Linux, OS X, and Windows. For Windows support you just need to call Windows.enable() in your application.

On Linux/OS X autocolors are toggled by calling set_light_background() and set_dark_background(). On Windows this can be done automatically if you call Windows.enable(auto_colors=True).

In Python2.x this library subclasses unicode, while on Python3.x it subclasses str.

  • Python 2.6, 2.7, 3.3, and 3.4 supported on Linux and OS X.

  • Python 2.7, 3.3, and 3.4 supported on Windows (both 32 and 64 bit versions of Python).

Tested on Windows XP and Windows 10 technical preview.

Build Status Windows Build Status Coverage Status Latest Version Downloads

Quickstart

Install:

pip install colorclass

Example Implementation

Example Script Screenshot Example Windows Screenshot

Source code for the example code is: example.py

Usage

Different colors are chosen using curly-bracket tags, such as {red}{/red}. For a list of available colors, call colorclass.list_tags().

The available “auto colors” tags are:

  • autoblack

  • autored

  • autogreen

  • autoyellow

  • autoblue

  • automagenta

  • autocyan

  • autowhite

  • autobgblack

  • autobgred

  • autobggreen

  • autobgyellow

  • autobgblue

  • autobgmagenta

  • autobgcyan

  • autobgwhite

Methods of Class instances try to return sane data, such as:

from colorclass import Color
color_string = Color('{red}Test{/red}')

color_string
u'\x1b[31mTest\x1b[39m'

len(color_string)
4

color_string.istitle()
True

There are also a couple of helper attributes for all Color instances:

color_string.value_colors
'\x1b[31mTest\x1b[39m'

color_string.value_no_colors
'Test'

Changelog

1.2.0

1.1.2

  • Maintaining Color type through .encode() and .decode() chains.

1.1.1

  • Fixed Python 2.7 64-bit original colors bug on Windows.

  • Fixed resetting colors when reset_atexit is True.

  • Improved sorting of list_tags().

1.1.0

  • Added native Windows support and automatic background colors.

1.0.2

  • Added ability to disable/strip out all colors.

1.0.1

  • Fixed splitlines() method.

1.0.0

  • Initial release.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

colorclass-1.2.0.tar.gz (13.3 kB view details)

Uploaded Source

File details

Details for the file colorclass-1.2.0.tar.gz.

File metadata

  • Download URL: colorclass-1.2.0.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for colorclass-1.2.0.tar.gz
Algorithm Hash digest
SHA256 2fb10c87aa2a242d8a8467136d68a3e266a5b7b545bc88bd1585e663c87ef584
MD5 190754d4698f97c3a90c518410e359f0
BLAKE2b-256 263788a4855ee9c1334592c503f161317c845c7961fa67a648f60037c00200b6

See more details on using hashes here.

Release history Release notifications | RSS feed

2.2.2

2 files

2.2.1

2 files

2.2.0

1 file

2.1.1

1 file

2.1.0

1 file

2.0.0

1 file

This release

1.2.0 This release

1 file

1.1.2

1 file

1.1.1

1 file

1.1.0

1 file

1.0.2

1 file

1.0.1

1 file

1.0.0

1 file

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