Skip to main content
https://badge.fury.io/py/colored.png https://pypip.in/d/colored/badge.png https://pypip.in/license/colored/badge.png

colored

Very simple Python library for color and formatting in terminal.

Video Demo

https://raw.githubusercontent.com/dslackw/images/master/colored/video.png

The following colors works with most terminals and terminals emulators. ANSI/VT100 escape sequences can be used in every programming languages.

Set:

+-----+-------------+
|Code | Description |
+-----+-------------+
|  1  | bold        |
|  2  | dim         |
|  4  | underlined  |
|  5  | blink       |
|  7  | reverse     |
|  8  | hidden      |
+-------------------+

Reset:

+-----+-------------+
|Code | Description |
+-----+-------------+
|  0  | all         |
| 21  | bold        |
| 22  | dim         |
| 24  | underlined  |
| 25  | blink       |
| 27  | reverse     |
| 28  | hidden      |
+-----+-------------+

Foreground (text):

+-----+---------------+
|Code | Description   |
+-----+---------------+
| 39  | default       |
| 30  | black         |
| 31  | red           |
| 32  | green         |
| 33  | yellow        |
| 34  | blue          |
| 35  | magenta       |
| 36  | cyan          |
| 37  | light_gray    |
| 90  | dark_gray     |
| 91  | light_red     |
| 92  | light_green   |
| 93  | light_yellow  |
| 94  | light_blue    |
| 95  | light_magenta |
| 96  | light_cyan    |
| 97  | white         |
+-----+---------------+

Background:

+-----+---------------+
|Code | Description   |
+-----+---------------+
| 49  | default       |
| 40  | black         |
| 41  | red           |
| 42  | green         |
| 43  | yellow        |
| 44  | blue          |
| 45  | magenta       |
| 46  | cyan          |
| 47  | light_gray    |
| 100 | dark_gray     |
| 101 | light_red     |
| 102 | light_green   |
| 103 | light_yellow  |
| 104 | light_blue    |
| 105 | light_magenta |
| 106 | light_cyan    |
| 107 | white         |
+-----+---------------+

256 Colors Foreground (text):

256 fg colors

256 Colors Background:

256 bg colors

Installation

$ pip install colored

uninstall

$ pip uninstall colored

Dependencies

None, only Python progmamming language.

Usage Examples

How to use the module in your own python code:

Functions

colored.fg() Change foreground color,
colored.fg256() Change foreground color using 256 colors,
colored.bg() Change background color,
colored.bg256() Change background color using 256 colors,
colored.set() Set attribute combinations,
colored.reset() Reset attributes

Initialisation

>>> import colored
>>>
>>> red = colored.fg(31)
>>> default = colored.fg(39)
>>> print ('%s Hello World !!! %s') % (red, default)
 Hello World !!!

Use description:

>>> green = colored.fg('green')
>>> default = colored.fg('default')
>>> print ('%s Hello World !!! %s') % (green, default)
 Hello World !!!

Using format method:

>>> bold = colored.set('bold')
>>> print ('{0}{1} Hello World !!! {2}'.format(green, bold, default))
 Hello World !!!

Print 256 colors:

>>> color = colored.fg256(165)
>>> color
'\x1b[38;5;165m'
>>> print color + 'Hello World !!!' + colored.reset(0)
Hello World !!!
>>> bg_color = colored.bg256(115)
>>> print color + bg_color + 'Hello World !!!' + colored.reset(0)
Hello World !!!

Screenshot:

example

Metadata

Release files for colored 1.0.4

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

Source distribution (sdist)

Source distribution for colored 1.0.4
File Size Uploaded
colored-1.0.4.tar.gz 15.4 kB Details

Release files / colored-1.0.4.tar.gz

Download URL colored-1.0.4.tar.gz
Size 15.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5a0dbbde0aae253d4a113c9903b82df596b7e4757320c880a961a974a71ff4d6
BLAKE2b-256 checksum
How to use checksums
6393813de58a172ae64f348c075978cdfc1746fbf95ab8271e627d28ed977942
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

2.3.2

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.5

2 release files

2.2.4

2 release files

2.2.3

2 release files

2.2.2

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.4.4

1 release file

1.4.3

1 release file

1.4.2

1 release file

1.4.1

1 release file

1.4.0

1 release file

1.3.93

1 release file

1.3.92

1 release file

1.3.9

1 release file

1.3.8

1 release file

1.3.7

1 release file

1.3.6

1 release file

1.3.5

1 release file

1.3.4

1 release file

1.3.3

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.1.5

1 release file

1.1.4

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.9

1 release file

1.0.8

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

This release

1.0.4 This release

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

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