Skip to main content

Python Terminal Color

Project description

PyTColor: Python Terminal Color

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

QuickStart

Installation and Basic Configuration

  1. Install PyTColor: Python Terminal Color by running pip install PyTColor.

  2. 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
...        }

Project details


Download files

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

Source Distribution

pytcolor-1.0.0.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytcolor-1.0.0.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file pytcolor-1.0.0.0.tar.gz.

File metadata

  • Download URL: pytcolor-1.0.0.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for pytcolor-1.0.0.0.tar.gz
Algorithm Hash digest
SHA256 9c7b8c9a56362b77e192d89ab7e09a26acaa8a6bf86e1274864f06bba823a32d
MD5 bfc7d386356a0f16cc1adf41e08c395d
BLAKE2b-256 2f8031bfcf5027922b35ead0e683fcbd132e5ee14da4fbbaa634ced6040abc19

See more details on using hashes here.

File details

Details for the file pytcolor-1.0.0.0-py3-none-any.whl.

File metadata

  • Download URL: pytcolor-1.0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for pytcolor-1.0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 446baaa91669fa7dcde9b6bdb4023ad28ec3527292e9f756ae59a8e88bd47722
MD5 fa7f507988a203e8804c3d0055e9443a
BLAKE2b-256 845dddd7f32e3c7348cddc845af0b1c6099f9f2c43b42caea5f1b09f049ab866

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page