Skip to main content

nyx's utility library

Project description

nyxcore

personal utility library

modules

module description
nyxcore.color ANSI color support — named colors, 256-color, true color, Windows compat, auto-strip
nyxcore.logger Configurable logger with colored console output, file logging, custom formats

nyxcore.color

ANSI escape code helpers. Zero dependencies.

colors

code fg bg
30/40 fg.black bg.black
31/41 fg.red bg.red
32/42 fg.green bg.green
33/43 fg.yellow bg.yellow
34/44 fg.blue bg.blue
35/45 fg.magenta bg.magenta
36/46 fg.cyan bg.cyan
37/47 fg.white bg.white
90/100 fg.gray bg.gray
91/101 fg.bright_red bg.bright_red
92/102 fg.bright_green bg.bright_green
93/103 fg.bright_yellow bg.bright_yellow
94/104 fg.bright_blue bg.bright_blue
95/105 fg.bright_magenta bg.bright_magenta
96/106 fg.bright_cyan bg.bright_cyan
97/107 fg.bright_white bg.bright_white
39/49 fg.reset bg.reset
print(f"{fg.cyan}hello{fg.reset}")

attr — text styles

attr.bold, attr.dim, attr.italic, attr.underline, attr.blink, attr.reverse, attr.hidden, attr.strikethrough, attr.reset

print(f"{attr.bold}{fg.red}bold red{attr.reset}")

extended colors

function description
fg256(code) 256-color foreground (0–255)
bg256(code) 256-color background
fgrgb(r, g, b) 24-bit true color foreground
bgrgb(r, g, b) 24-bit true color background
print(f"{fg256(196)}bright red{fg.reset}")
print(f"{fgrgb(255, 100, 50)}orange{fg.reset}")

strip(text)

Remove all ANSI escape sequences.

clean = strip("\x1b[31mhello\x1b[0m")  # "hello"

init(strip_auto=True)

Enable Windows console ANSI support. Call once at startup.

On Windows: enables virtual terminal processing via Win32 API.
When strip_auto=True: non-TTY streams (piped/redirected) are wrapped to strip ANSI codes automatically.

from nyxcore.color import init
init()

nyxcore.logger

Configurable logger on top of stdlib logging. Supports colored console output, file output, custom formats.

Logger(name, level, *, colorize, fmt, file)

param type default description
name str "nyxcore" logger name
level str or int "INFO" DEBUG/INFO/WARNING/ERROR/CRITICAL or a logging constant
colorize bool or None auto True = colors on, False = plain, None = TTY-detect
fmt str or None default see format
file str or Path None path to a log file (appends)
from nyxcore.logger import Logger

log = Logger("myapp")
log.info("hello")
log.warning("careful")
log.error("oops")

set_level(level)

Change minimum log level at runtime.

log.set_level("DEBUG")

add_file(path, level=None)

Add a file handler after construction. File output is never colorized.

log.add_file("app.log")
log.add_file("errors.log", level="ERROR")

format

Placeholders: {time}, {level}, {name}, {message}. Python format specifiers work ({level:^8} centers in 8 chars).

Default:

[{time}] {level:^8} | {name} | {message}

Custom:

log = Logger("app", fmt="{level} | {message}")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nyxcore-0.1.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nyxcore-0.1.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file nyxcore-0.1.0.tar.gz.

File metadata

  • Download URL: nyxcore-0.1.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for nyxcore-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dc4fff070271ad4b1d0949b3555218e00e3a1a36cb55c1a8d5055357b28844db
MD5 a9f5b8d54bd067fb23470eda9ed63708
BLAKE2b-256 eea583c6296f1ac658dad1f8ad7d00e5919971cf8660fe09e00e0c285c0f00be

See more details on using hashes here.

File details

Details for the file nyxcore-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: nyxcore-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for nyxcore-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f708d9d0b00e9ca77a763ef0246f69c9b82b50249c6ed8258a4d35d5c659d64f
MD5 306a2de496fa15e4f9212b2419566fd5
BLAKE2b-256 f8c17009ebc647de1113e39743d46e5b0de401bf18b69bc08945f2c0b54d9519

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page