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
Metadata
Release files for colex 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| colex-0.3.2.tar.gz | 7.6 kB | Without provenance | Details for colex-0.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| colex-0.3.2-py3-none-any.whl | Python 3 | none | any | Details for colex-0.3.2-py3-none-any.whl |
Total release size: 17.3 kB
Release files / colex-0.3.2.tar.gz
| Download URL | colex-0.3.2.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6d5fe4aa89e89e73d023ef6fc64f61a420559da12b87c0d5762706495e195311
|
|
BLAKE2b-256 checksum How to use checksums |
9970b377989b046e1c524d47f5e488ca7dd461c4e7209d89cfee4f7f2dcacd6a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.15
|
Release files / colex-0.3.2-py3-none-any.whl
| Download URL | colex-0.3.2-py3-none-any.whl |
|---|---|
| Size | 9.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
970063bbc998ea0180373344e6e6ad01fc71ba055b0127de54e73c69d739916c
|
|
BLAKE2b-256 checksum How to use checksums |
1251eafe56feac3f3293ff2d429352686c8a552410534c300c3a114b172d821d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.15
|
Security for colex 0.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.