Antsi
A quick and user-friendly way to style your text using ANSI codes.
Built around a delightfully simple markup language, there's no messing about with codes or style resets. All the ANSI code conversion, handling of overlapping styles, and terminal support is automatically handled for you.
Usage
You can either download wheels from the Releases tab or install it from PyPI:
pip install antsi
The function you'll most likely care about is colorize. Colorize is responsible for converting any styled markup
within the provided source to ANSI escape sequences. The styled markup syntax can be found below.
You can use the following code to test that it's working as expected.
import antsi
print(antsi.colorize("Hello [fg:green](there!)"))
print(antsi.colorize("It looks like [fg:black;bg:white;deco:bold,blink](antsi) is working!"))
If you're planning on doing any string manipulation or templating with styled markup, you'll want to escape the
substituted text to prevent any unexpected colors or errors. The escape function ensures that any control characters
are properly escaped.
Styled Markup
Styled markup is a decidedly simple language that is make for ease of use and readability. There's no unruly sequences of numbers and characters that you'll forget what they mean in a week, just words and a couple memorable abbreviations.
Styled markup can appear anywhere within a piece of text. It can even be nested infinitely! The only requirements are that it start with a style specifier and is followed by some content. It will always be in the form:
[ <style specifier(s)> ]( <content> )
For example, Hello [fg:green](there), user! which will make only "there" be colored green. Everything else will be the
default text color.
Content
The content is what the style specifier applies to. It always immediately follows a style specifier and must be wrapped
in parentheses. Any whitespace within the content will be emitted as-is unless escaped using a
backslash (\).
The content can contain any characters, and it can even contain other styled markup! If you want to use any square brackets or parentheses in the content, they must be escaped.
Style Specifiers
Style specifiers are surrounded by square brackets ([]) and contain the directives for applying style to the content
immediately following them. They are essentially a list of key-value pairs, where the key denotes the type of style.
The styles within a specifier will ignore whitespace to facilitate readability. However, whitespace cannot exist in the
middle of a key or value (i.e. bl ue will cause an error). The benefit of this is that [ fg: red ; bg: blue ]
will be parsed the same as [fg:red;bg:blue], so use whatever style you prefer.
Examples:
| Style Specifier | Meaning |
|---|---|
[fg:red] |
Red foreground |
[bg:blue] |
Blue background |
[deco:bold] |
Bold text |
[deco:bold,blink] |
Bold and blinking |
[fg:red;bg:white] |
Red foreground and white background |
[bg:blue;fg:white;deco:bold] |
White foreground, blue background, and bold |
[deco:bold,underline;fg:cyan] |
Cyan foreground, bold, and underlined |
[fg:red;bg:white;fg:blue] |
Blue foreground and white background (last specifier wins) |
As show above, there are currently three specifiers that are allowed: fg (
foreground), bg (background), and deco (decoration).
Foreground color (fg)
Format: fg:<color>
Changes the color of the text itself. Currently only the standard color pallet is implemented, providing 8 colors with a
standard and a bright variant. The bright variant can be chosen by prefixing the color with bright-.
| Color | Standard Code | Bright Code |
|---|---|---|
| Default | default |
N/A |
| Black | black |
bright-black |
| Red | red |
bright-red |
| Green | green |
bright-green |
| Yellow | yellow |
bright-yellow |
| Blue | blue |
bright-blue |
| Magenta | magenta |
bright-magenta |
| Cyan | cyan |
bright-cyan |
| White | white |
bright-white |
Background color (bg)
Format: bg:<color>
Changes the color of the text background. It accepts the same colors as fg.
Text decoration (deco)
Format: deco:<decoration>,[<decoration>...]
Applies additional text decorations like bolding, dimming, blinking, etc. Unlike the foreground and background, multiple text decorations can be applied at the same time using a comma-separated list.
| Decoration | Code(s) |
|---|---|
| Bold | bold |
| Dim | dim, faint |
| Italic | italic |
| Underline | underline |
| Fast Blink | fast-blink, blink-fast |
| Slow Blink | slow-blink, blink-slow |
| Invert | invert, reverse |
| Hide | hide, conceal |
| Strikethrough | strike-through, strikethrough |
Escape Sequences
There are a handful of control characters that must be escaped to include them anywhere in your text. This includes text outside styled markup.
| Character | Sequence |
|---|---|
\ |
\\ |
[ |
\[ |
] |
\] |
( |
\( |
) |
\) |
Beyond these characters, you can also escape any whitespace (i.e. spaces, tabs, newlines, and carriage returns) to make
writing multi-line text easier. All you need to do is prefix it with a backslash (\).
Contributing
Any and all contributions are welcome! Some ideas if you can't think of anything:
- Improve the documentation
- Add some functionality that might be missing
- Report (or even fix) any bugs
If you don't have time to contribute yourself but still wish to support the project, sponsorship would be greatly appreciated!
License
Licensed under the MIT license (or http://opensource.org/licenses/MIT).
Metadata
Release files for antsi 0.2.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 | Provenance | Actions |
|---|---|---|---|---|
| antsi-0.2.1.tar.gz | 44.9 kB | Without provenance | Details for antsi-0.2.1.tar.gz |
Built distributions (wheels)
Total release size: 7.9 MB
Release files / antsi-0.2.1.tar.gz
| Download URL | antsi-0.2.1.tar.gz |
|---|---|
| Size | 44.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c8ffa86ada62ed163c718d7497419c413d5270ea9ac848eab12760270a70df47
|
|
BLAKE2b-256 checksum How to use checksums |
38e3d2438c04c9d3bedf849324b3655b3fe5e5ccbf09701c53cec32301b59d39
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.5.1
|
Release files / antsi-0.2.1-cp310-abi3-win_amd64.whl
| Download URL | antsi-0.2.1-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 195.4 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
7c506372762c9f4e4a191cdf77871c0b108b7bc44f3d01804da35ee5b10b6a6b
|
|
BLAKE2b-256 checksum How to use checksums |
01ed29221ebe82eb574b15cafb24bca6fe4a8eb68b259cd31cfeb3f940b83b58
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.5.1
|
Release files / antsi-0.2.1-cp310-abi3-win32.whl
| Download URL | antsi-0.2.1-cp310-abi3-win32.whl |
|---|---|
| Size | 189.1 kB |
| Tags | CPython 3.10 Windows x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
03bca8c0efe592c2a11919d3fb43e4890f3bf7fb058aae8fc161839e47cc1f8e
|
|
BLAKE2b-256 checksum How to use checksums |
99215d020ec1501e76c08c486a9eb9ffe9ea79e0f92a093bc25d53d728643a72
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.5.1
|
Release files / antsi-0.2.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | antsi-0.2.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
c0e8078851525773d1b37dc8b15a431b3246887ff84bfbb476697306f31b23ff
|
|
BLAKE2b-256 checksum How to use checksums |
5422bb316d1f13c358fcd5aba6cfcabc745861f0634e98d60f3a0cf6f281a44c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.5.1
|
Release files / antsi-0.2.1-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
| Download URL | antsi-0.2.1-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ IBM System/390x abi3 |
|
SHA-256 checksum How to use checksums |
74dbf45ea38e60ca64504966e33815c49e4334e85ecfce8a5e5c6331798287da
|
|
BLAKE2b-256 checksum How to use checksums |
035a81ad575c73e926523f49e8d3de020dfd73c928d52b90249dad914fad472d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.5.1
|
Release files / antsi-0.2.1-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
| Download URL | antsi-0.2.1-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ PowerPC 64-le abi3 |
|
SHA-256 checksum How to use checksums |
6d67943f872094688230de432ed4d0a770c8481eb9487f376a69655b0f08e2fd
|
|
BLAKE2b-256 checksum How to use checksums |
13e27d4c3929c84aaa4f2e4dce333c6c4319dc7e727de3469fc789b7c3938d15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.5.1
|
Release files / antsi-0.2.1-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
| Download URL | antsi-0.2.1-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
dd9d6e1f872d31f0513946cbfbc872bf5c41383628f400e51a8156ab6f02ee98
|
|
BLAKE2b-256 checksum How to use checksums |
9bdcb688b1c333d69dd1dc816cad3b5e97d73acee53d239b2a6aa1b556d0077c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.5.1
|
Release files / antsi-0.2.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | antsi-0.2.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
2e70b38a4c2d93f08a3c56583e1c17845e1fafa9bfa8c95963d3d6c4a3548eaa
|
|
BLAKE2b-256 checksum How to use checksums |
3e9619f7755d43fbabbf1ef4e00f1787a983bc5f7c338d433d3aa071c6f57266
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.5.1
|
Release files / antsi-0.2.1-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl
| Download URL | antsi-0.2.1-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.10 Linux glibc 2.5+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
1a0c5a2d8e66204d19b9d491071fc87e54244dda682e72bc9ee493ac08ae1941
|
|
BLAKE2b-256 checksum How to use checksums |
34fdd119eedfb8fd057c8c2aa3d425e5bcdc05e4a7db200b13112a34840db8c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.5.1
|
Release files / antsi-0.2.1-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | antsi-0.2.1-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 310.1 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
e755bbf64b747a8979e9ab8c0983f02c958cb31909ee224d09122e603583a370
|
|
BLAKE2b-256 checksum How to use checksums |
c6a5f9dc16dfecf65dea55f28d2ed7304308cbf890278385d62b1b640733e5c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.5.1
|
Release files / antsi-0.2.1-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | antsi-0.2.1-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 313.0 kB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
ad56e659e39a53c09485aeba9a2f0e2b20b0f6e4013c7f120941638632e5fe0b
|
|
BLAKE2b-256 checksum How to use checksums |
f20374103d17f1a5fbab7bb1b35fce20703347dc1428cbac2efd1554fad5a8f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.5.1
|
Security for antsi 0.2.1
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.