Library with constants and functions for working with colors
Project description
Colex
Library with constants and functions for working with colors
Installation
Install using either pip or rye:
pip install colex
rye install colex
Getting started
import colex # Every public namespace is available under `colex`
print(colex.RED + "Hello red!")
print("Still red...")
print(colex.RESET, "Back to normal")
# Optionally, you can import submodules or constants like this
from colex import color, style, RESET
print(style.ITALIC + color.GREEN + "Hello italic green" + RESET)
# You may want to use this helper function to have color param at the end
from colex import colorize
print(colorize("Hello blue!", colex.BLUE))
# Note that `colex` is using ANSI escape codes,
# therefore any string can be annotated with `ColorValue`
from colex import ColorValue
my_color: ColorValue = "\x1b[31m" # The ANSI code for red
print(my_color + "Hello red, again")
Rational
Originally, using colors in my projects was done by simply printing "\x1b[31m" and such. Eventually, the color strings were assigned to constants with understandable names, like RED. They were put in a seperate module, a color.py, that was copied around projects when I needed to do colors. After some time, I found it messy when it ended up looking:
import color
from color import ColorValue
class Color: # This was used as a mixin component
color: ColorValue = color.RED # Too many occurances of "color" for me to stay sane
It was then nice in itself to distinguish the namespace colex from color. I then ended up with:
import colex
from colex import ColorValue
class Color:
color: ColorValue = colex.RED
Having a different namespace was nice, but the main advantage was having colex on PyPI. This way, I didn't need to copy over a color.py file everytime, but I could instead just install it using the desired package manager.
It also became easier to develop charz, as the color aspect was split into it's own package.
Includes
- Annotations
ColorValueColorCodeHexCode
- Functions
colorizefrom_ansifrom_hexfrom_randomfrom_rgb
- Constants
NONERESET
- Modules with constants
color- HTML/CSS named colors
styleBOLDFAINTITALICUNDERLINEBLINKRAPID_BLINKREVERSECONCEALSTRIKETHROUGH
Versioning
colex uses SemVer, according to The Cargo Book.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file colex-0.3.2.tar.gz.
File metadata
- Download URL: colex-0.3.2.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d5fe4aa89e89e73d023ef6fc64f61a420559da12b87c0d5762706495e195311
|
|
| MD5 |
d0a9e7ef1721c2787d81e5d0cbffc75e
|
|
| BLAKE2b-256 |
9970b377989b046e1c524d47f5e488ca7dd461c4e7209d89cfee4f7f2dcacd6a
|
File details
Details for the file colex-0.3.2-py3-none-any.whl.
File metadata
- Download URL: colex-0.3.2-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
970063bbc998ea0180373344e6e6ad01fc71ba055b0127de54e73c69d739916c
|
|
| MD5 |
ad95552bc18792c16ad46a55caae1515
|
|
| BLAKE2b-256 |
1251eafe56feac3f3293ff2d429352686c8a552410534c300c3a114b172d821d
|