A set of useful utilities for Python
Project description
PyColorUtils
A set of useful utilities for Python. Same vibe as C-Utils and Utils.js.
Install via pip install pycolorutils
Color
Color Preset Strings
Format strings for console printing.
C.RstResetC.BrBrightC.DiDimC.UnUnderscoreC.BlBlinkC.RvReverseC.BlkBlackC.RedRedC.GrnGreenC.YloYellowC.BluBlueC.MagMagentaC.CyaCyanC.WhiWhiteC.BgBlkBgBlackC.BgRedBgRedC.BgGrnBgGreenC.BgYloBgYellowC.BgBluBgBlueC.BgMagBgMagentaC.BgCyaBgCyanC.BgWhiBgWhite
Logging & Errors
msg(*m)Likeprint()but automatically appendsC.Rstto the end.err(e: Any, ex: int=0)Prints an error to the console (stderr) in red. Ifexis non-zero, also exits with exit code.warn(w: Any)Prints a warning to the console (stderr) in yellow.eInfo(e: Exception)Returns a human-readable string for the exception.onMsg = callable(m: str)If defined, redirects output frommsg()onErr = callable(e: str)If defined, redirects output fromerr()
Main & Exit
execMain(main: callable)Wrapsmainso that when it ends, all atexit functions are run, even if an exception or interrupt occurs.atexit(f: callable)Runfbefore exit. More reliable than builtinatexitmodule ifexecMain()is used, falls back on atexit otherwise.exit(ex: int=0)Overrides builtinexitto exit cleanly, with optional exit code.
Misc
getDictKey(d: dict, val: Any)Returns the first key indwhose value isval. Raises ValueError if not found.
UUID
Python port of the 64-bit ChuID UUID format. ChuID outputs as a compact, 11 character Base64 string. It's made for situations where a longer 128-bit format like UUIDv4 is overkill.
Format: <U8 Uptime><U8 Magic><U8 CryptoRand><U8 Counter><U32 Date>
from uuid import UUID
#Current date, magic value 15
id = UUID.genUUID(None, 15)
print(id.id, f"String: {id}\n",
id.date(), id.magic())
Methods
UUID(id)Construct ID from bytes or strUUID.genUUID([date[, magic]])Generate new random UUID w/ optional date and magic
Reader
TODO Detailed help coming soon!
FancyTable
Render a fancy table in the console w/ colored borders and a header row.
table(title: str, width: int, colNames: list[str], data: list[list[str]], color: str=None)
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 pycolorutils-1.2.7.tar.gz.
File metadata
- Download URL: pycolorutils-1.2.7.tar.gz
- Upload date:
- Size: 19.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
728de5f938cee75ffeb2ea0b489a1f72617636fd19d2960d9adc09d906405a5f
|
|
| MD5 |
95857f1e395f47628882ce33b8d6df77
|
|
| BLAKE2b-256 |
88d4fe9a80dbe7fc049f2a9ec78fb038c4da1eeed0f1e5490dc6293e73831bdb
|
File details
Details for the file pycolorutils-1.2.7-py3-none-any.whl.
File metadata
- Download URL: pycolorutils-1.2.7-py3-none-any.whl
- Upload date:
- Size: 19.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d3244baf5de5e592d2d7672db20a3179dd537672c1a983f024aa5136c1f9b18
|
|
| MD5 |
2d0cb8c74251f9b6c223fa016acc25fa
|
|
| BLAKE2b-256 |
1ee0bc968ca42a6a2e8ec483b428a38c0653d951f59b5f82a70ae5a7be2133e0
|