PyTColor: Python Terminal Color
1.0.0.1
Added support to python >= 3.0.0
1.0.0.0
PyTColor: A simple python package to get color terminal outputs.
color_print can be used to substitute the python print with keywords color, bg_color, style.
color_print is api compatible with python print.
ColoredStreamHandler can be used instead of python StreamHandler in logging to get colored logs.
Dependancies
python>=3.0.0
QuickStart
Installation and Basic Configuration
Install PyTColor: Python Terminal Color by running pip install PyTColor.
There is no specific configuration needed to use PyTColor.
# color_print
from pytcolor import color_print
color_print("PyTColor", color='green', bg_color='red', style='underline', end=' ')
color_print("Python", "Terminal", color='magenta', bg_color='None', style='underline')
color_print("Python Terminal Color", color='cyan', bg_color='grey', style='bold')
# ColoredStreamHandler
import logging
logger = logging.getLogger('test')
logger.setLevel(logging.DEBUG)
ch = ColoredStreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
logger.debug('debug message')
logger.info('info message')
logger.warning('warn message')
logger.error('error message')
logger.critical('critical message')
Basic Usage
Below are some basic ussage for PyTColor package.
example:
>>>from pytcolor import color_print
>>>color_print("PyTColor", color='green', bg_color='red', style='underline', end=' ')
PyTColor # \033[4m\033[41m\033[32mPyTColor\033[0m
>>>from pytcolor.constants import COLORS_NAME, STYLES_NAME
>>>COLORS_NAME
['grey', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white']
>>>STYLES_NAME
['bold', 'dark', 'underline', 'blink', 'reverse', 'concealed']
>>>from pytcolor import ColoredStreamHandler
>>>class CustomColoredStreamHandler(ColoredStreamHandler):
... def __init__(self, *args, **kwargs):
... super().__init__(*args, **kwargs) # important to call first
... self._level_color_mapping = {
... "50:*": ("red", None, "underline"), # critical and above
... "40:50": ("red", None, None), # error and above till critical but not critical
... "30:40": ("yellow", None, None), # warning and above till error but not error
... "20:30": ("cyan", None, None), # info and above till warning but not warning
... "10:20": ("cyan", None, "underline") # debug and above till info but not info
... }
Metadata
Release files for pytcolor 1.0.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 | |
|---|---|---|---|
| pytcolor-1.0.0.1.tar.gz | 4.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytcolor-1.0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.3 kB
Release files / pytcolor-1.0.0.1.tar.gz
| Download URL | pytcolor-1.0.0.1.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9e1dfdc6e1ce3e099a9feeaf8bd7a7e1b775ce6b03b79397e4149406d826c608
|
|
BLAKE2b-256 checksum How to use checksums |
589b7e590345d35034e971ce01e18a7f5b3fa37c90c8754f2c3b361ad408b585
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.7.9
|
Release files / pytcolor-1.0.0.1-py3-none-any.whl
| Download URL | pytcolor-1.0.0.1-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
044a28c9a1207544a049c516a3554b3b4b9de38ab3800738e961719108b07430
|
|
BLAKE2b-256 checksum How to use checksums |
18b02293c1f441d6b4a3f05ff84f95153e8b64ea394b86ef0eb78f7350ce2395
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.7.9
|