MyTColor
MyTColor provides a lightweight, dependency-free interface for ANSI terminal formatting in Python. It offers a straightforward API for adding colors and styles to terminal output, suitable for logging, CUI (Console User Interface) development, and script enhancements.
Key features:
- Zero Dependencies: Pure Python implementation using standard libraries.
- Cross-Platform: Native support for ANSI sequences on Linux, macOS, and automatic Virtual Terminal processing on Windows.
- Performance: Uses static string constants for minimal runtime overhead.
- Type Safety: Compatible with standard Python type checking.
Installation
Install via pip:
pip install MyTColor
Usage
MyTColor exposes ANSI sequences as string constants through the MyT class. This design allows for seamless integration with Python's f-strings.
Basic Example
from MyTColor import MyT
# Success message
print(f"{MyT.GREEN}✔ Operation completed successfully.{MyT.RESET}")
# Error message with style
print(f"{MyT.RED}{MyT.BOLD}✖ Error: Connection failed.{MyT.RESET}")
Advanced Formatting
Combine background colors, styles, and foreground colors for rich output.
# Header style: Bold white text on blue background
header_style = f"{MyT.BOLD}{MyT.BG_BLUE}{MyT.WHITE}"
print(f"{header_style} SYSTEM STATUS {MyT.RESET}")
API Reference
The MyT class provides the following constants.
Foreground Colors
| Standard | Accessor | Bright | Accessor |
|---|---|---|---|
| Black | MyT.BLACK |
Black | MyT.L_BLACK |
| Red | MyT.RED |
Red | MyT.L_RED |
| Green | MyT.GREEN |
Green | MyT.L_GREEN |
| Yellow | MyT.YELLOW |
Yellow | MyT.L_YELLOW |
| Blue | MyT.BLUE |
Blue | MyT.L_BLUE |
| Magenta | MyT.MAGENTA |
Magenta | MyT.L_MAGENTA |
| Cyan | MyT.CYAN |
Cyan | MyT.L_CYAN |
| White | MyT.WHITE |
White | MyT.L_WHITE |
Background Colors
Prefix any color with BG_.
- Example:
MyT.BG_RED,MyT.BG_L_BLUE.
Styles
MyT.BOLD: BoldMyT.DIM: Dim/FaintMyT.ITALIC: ItalicMyT.UNDERLINE: UnderlineMyT.BLINK: BlinkMyT.REVERSE: Invert colorsMyT.HIDDEN: Hidden textMyT.STRIKETHROUGH: Strikethrough
Utilities
MyT.RESET: Resets all formatting. Essential to prevent style leakage.
Compatibility
MyTColor automatically enables standard ANSI support on Windows 10 and 11 terminals using ctypes. On Unix-like systems (Linux, macOS), it outputs standard ANSI sequences directly.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Metadata
Release files for MyTColor 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mytcolor-1.0.1.tar.gz | 6.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mytcolor-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.8 kB
Release files / mytcolor-1.0.1.tar.gz
| Download URL | mytcolor-1.0.1.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
40db7dbdbeab7c6feb2a9fd4220a3fbfef2085819eee59e0e61e7605edff7862
|
|
BLAKE2b-256 checksum How to use checksums |
b14a069bd76547bb218761e667957dccd480981c96e02a132cf6637b19bc417c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.6
|
Release files / mytcolor-1.0.1-py3-none-any.whl
| Download URL | mytcolor-1.0.1-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9db03b643fbc7f6916008ddf129a13ca66e2275ee0f5132f6bd90dd4fde96575
|
|
BLAKE2b-256 checksum How to use checksums |
81923cd689ce8ac9a1bd54f39b92cfbc9a1d08ba0e65dc53f3a259e53bbd1d22
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.6
|