Skip to main content

fansi_text

A Python module for formatting text with ANSI escape codes.

Installation

pip install fansi_text

Usage

from fansi_text import Red

print(Red("Red text"))
from fansi_text import RGBColor

print(RGBColor("RGB Text", 200, 130, 60))

You can also form complex combinations of overlapping effects.

import fansi_text as ft

print(
    ft.Bold("Bold, " +
         ft.Green("green and bold. ")) + 
    "Then normal text. Then " +
    ft.Underline(ft.Overline("under and over lined. ")) +
    "Next " + 
    ft.Italic("italics. Add " + 
           ft.Yellow("yellow " + 
                  ft.Bold("and bold too! ") +
                  "Then back to yellow and italics, ") + 
           "then just italics, ") + 
    "and finally back to normal."
)

A demo_all method is provided to allow for testing all supported colours and effects in your terminal.

import fansi_text as ft
ft.demo_all()

The full list of colours and effects are shown below (notes per Wikipedia). Note that support for each code varies between terminals.

ANSI Code Name Example Note
0 Reset All attributes become turned off
1 Bold Bold Text As with faint, the color change is a PC (SCO / CGA) invention.
2 Faint Faint Text May be implemented as a light font weight like bold.
3 Italic Italic Text Not widely supported. Sometimes treated as inverse or blink.
4 Underline Underlined Text Style extensions exist for Kitty, VTE, mintty, iTerm2 and Konsole.
5 SlowBlink (Example not supported in README) Sets blinking to less than 150 times per minute
6 FastBlink (Example not supported in README) MS-DOS ANSI.SYS, 150+ per minute; not widely supported
7 Invert Inverted Swap foreground and background colors; inconsistent emulation
8 Conceal Not widely supported.
9 Strikethrough Strikethrough Text Characters legible but marked as if for deletion. Not supported in Terminal.app.
10 Font0 - Default Font
11 Font1 - Select alternative font n − 10
12 Font2 - Select alternative font n − 10
13 Font3 - Select alternative font n − 10
14 Font4 - Select alternative font n − 10
15 Font5 - Select alternative font n − 10
16 Font6 - Select alternative font n − 10
17 Font7 - Select alternative font n − 10
18 Font8 - Select alternative font n − 10
19 Font9 - Select alternative font n − 10
20 FrakturFont (Example not supported in README) Rarely supported
21 DoubleUnderlined Double Underline Double-underline per ECMA-48 but often disables bold intensity.
26 ProportionalSpacing - ITU T.61 and T.416, not known to be used on terminals
30 Black Black Text Set text colour to black
31 Red Red Text Set text colour to red
32 Green Green Text Set text colour to green
33 Yellow Yellow Text Set text colour to yellow
34 Blue Blue Text Set text colour to blue
35 Magenta Magenta Text Set text colour to magenta
36 Cyan Cyan Text Set text colour to cyan
37 White White Text Set text colour to white
38 RGBColor RGBColor(172,100,112) Use with parameters e.g. RGBColor('Text', 200, 130, 60)
40 BgBlack Text Set black background
41 BgRed Text Set red background
42 BgGreen Text Set green background
43 BgYellow Text Set yellow background
44 BgBlue Text Set blue background
45 BgMagenta Text Set magenta background
46 BgCyan Text Set cyan background
47 BgWhite Text Set white background
48 RGBBgColor RGBBgColor(172,100,112) Use with parameters e.g. RBGBgColor('Text', 200, 130, 60)
51 Framed Framed Text Implemented as "emoji variation selector" in mintty.
52 Encircled Encircled Text
53 Overlined Overlined Text Not supported in Terminal.app
58 UnderlineColor (Example not supported in README) Not in standard; implemented in Kitty, VTE, mintty, and iTerm2. Next arguments are 5;n or 2;r;g;b.
60–64 Ideogram effects (Example not supported in README) Rarely supported
73 Superscript Superscript Implemented only in mintty
74 Subscript Subscript
90 BrightBlack Bright Black Text Set text colour to bright black (gray)
91 BrightRed Bright Red Text Set text colour to bright red
92 BrightGreen Bright Green Text Set text colour to bright green
93 BrightYellow Bright Yellow Text Set text colour to bright yellow
94 BrightBlue Bright Blue Text Set text colour to bright blue
95 BrightMagenta Bright Magenta Text Set text colour to bright magenta
96 BrightCyan Bright Cyan Text Set text colour to bright cyan
97 BrightWhite Bright White Text Set text colour to bright white
100 BgBrightBlack Bright Black Background Set bright black (gray) background
101 BgBrightRed Bright Red Background Set bright red background
102 BgBrightGreen Bright Green Background Set bright green background
103 BgBrightYellow Bright Yellow Background Set bright yellow background
104 BgBrightBlue Bright Blue Background Set bright blue background
105 BgBrightMagenta Bright Magenta Background Set bright magenta background
106 BgBrightCyan Bright Cyan Background Set bright cyan background
107 BgBrightWhite Bright White Background Set bright white background

Metadata

Release files for fansi-text 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 fansi-text 0.1.3
File Size Uploaded
fansi_text-0.1.3.tar.gz 9.1 kB Details

Built distribution (wheel)

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

Total release size: 16.6 kB

Release files / fansi_text-0.1.3.tar.gz

Download URL fansi_text-0.1.3.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
cb74eedbee7462b9e9c849e49c7cffaef92f03991036b0ce0b183b5cbe65b022
BLAKE2b-256 checksum
How to use checksums
f17c5639d931a7c5bfe0b30d7cdbc28fb490f2535db31b0acc374e80ac440586
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Release files / fansi_text-0.1.3-py3-none-any.whl

Download URL fansi_text-0.1.3-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3288ff4602b171f90036cc184d3c4e0166f5daad377d034fa162a814dfab9d1a
BLAKE2b-256 checksum
How to use checksums
8dd22dc18b6d8be6dcf289565441b25147f06f29a0c8d26a854a374a88434a13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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