escapyde
Yet another ANSI escape sequence library for Python - now modernised!
Installation
The package is readily available on PyPI. There are no dependencies, but Python 3.9 or newer is required.
On Windows:
py -m pip install escapyde
On other platforms:
pip3 install escapyde
Changelog
You can find the project changelog here.
Usage
For basic usage, pre-made colours are available for your convenience. Use them with the pipe operator on strings you want to colour. They end the colour changes automatically, too!
import escapyde
from escapyde.examples.text import SKULL
some_text = "Hello, world!"
print(f"I want to print this red: {escapyde.FRED | some_text}, and this yellow: {escapyde.FYELLOW | 'Hi!'}.")
print(f"Here's a cyan skull:\n{escapyde.FCYAN | SKULL}")
You can also colour backgrounds,
import escapyde
some_more_text = "This should have a blue background."
print(f"{escapyde.BBLUE | some_more_text}")
combine formatting options,
import escapyde
even_more_text = "Lorem Ipsum dolor sit amet."
print(f"{escapyde.FRED | escapyde.BWHITE | even_more_text}")
and even mix formatting options on the fly (although at present you need to separate strings with parentheses):
import escapyde
print(f"{(escapyde.FRED | 'Hello') | (escapyde.FBLUE | 'World')}")
It is possible to use custom foreground and background colours via the
escapyde.AnsiEscape class; these can be either valid ANSI literals or
RGB values:
from escapyde.ansi import AnsiEscape
from escapyde.colours import sequence_table
fg_white = sequence_table['fg_white'] # You can alternatively use raw integers, eg. 37 for white
gold = AnsiEscape(foreground_colour=(0xDB, 0xAC, 0x34))
white_gold = AnsiEscape(foreground_colour=fg_white, background_colour=(219, 172, 34))
print(gold | "This is gold!")
print(white_gold | "This is white text on gold background!")
The class defaults to the default colours of the terminal, so you don't need to set both values.
Finally, if you have a string with multiple substrings you wish to recolour, there's a function for that:
from escapyde.ansi import AnsiEscape, escape_format
mapping = {
'match': AnsiEscape(foreground_colour=(255, 0, 0)),
'case': AnsiEscape(foreground_colour=(255, 255, 0)),
'print': AnsiEscape(foreground_colour=(0, 255, 0)),
}
text = """
stuff = [3, 1, 4]
match stuff:
case [3, *rest]:
print("It's pi-like")
case _:
print("Not like pi")
"""
print(escape_format(string=text, escape_map=mapping, case_sensitive=True))
Screenshots
Metadata
Release files for escapyde 1.0.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 |
|---|---|---|---|---|
| escapyde-1.0.2.tar.gz | 11.2 kB | Without provenance | Details for escapyde-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| escapyde-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for escapyde-1.0.2-py3-none-any.whl |
Total release size: 22.5 kB
Release files / escapyde-1.0.2.tar.gz
| Download URL | escapyde-1.0.2.tar.gz |
|---|---|
| Size | 11.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
afe36c4a8876431773335043743d9b2d47c4eff5ed95c84c91c01149715a0067
|
|
BLAKE2b-256 checksum How to use checksums |
b23e5832cfd62fc988705943f901ed5816ce14e9894bbf34121fa10266a6a2ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.12.1 Linux/6.5.0-1025-azure
|
Release files / escapyde-1.0.2-py3-none-any.whl
| Download URL | escapyde-1.0.2-py3-none-any.whl |
|---|---|
| Size | 11.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f46de7290571491f64d8b71d99406a03b4d53ba980682fc5e3fe38f0ceb2a3f2
|
|
BLAKE2b-256 checksum How to use checksums |
3c4d9e4d81ec4f96331b2431a07af3c229d8b1b890d1f1c4599f399fb9c570bd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.12.1 Linux/6.5.0-1025-azure
|
Security for escapyde 1.0.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.