Skip to main content

Generic Python utilities (DX-first terminal logger, XDG directories, number/percentage/currency formatting). Python 3.12+.

Project description

adrian-utils

Generic Python utilities — DX-first terminal logger, XDG directories, number/percentage/currency formatting. Python 3.12+.

Install

pip install adrian-utils
# or with uv
uv add adrian-utils

Install (local dev)

uv add -e .

Usage

from py_utils import log, xdg, usd, percentage

# XDG directories
config_file = xdg.config / "myapp" / "config.toml"
data_file = xdg.data / "myapp" / "database.db"
cache_dir = xdg.cache / "myapp"

# Narration
log.info("Connected to postgres:5432")

# Task with steps
with log.task("Build assets"):
    log.step("Transpiling")
    log.step("Bundling")

# Status
log.success("Deployed")
log.warn_once("Flag --fast is deprecated")

# Progress
with log.task("Sync"):
    p = log.progress(total=3, title="Uploading")
    p.tick(); p.tick(); p.tick(); p.done(success=True)

# Formatting
usd(1234.56)                  # "+$1,234.56" (color and + by default)
usd(1234.56, signed=False)    # "$1,234.56" (no leading +)
percentage(15.234)            # "+15.2%"
percentage(15.234, signed=False)  # "15.2%"

Colors automatically disable when stdout is not a TTY. To override:

from py_utils import set_color_enabled

set_color_enabled(True)   # force color on
set_color_enabled(False)  # force color off
set_color_enabled(None)   # return to auto detection

Run the bundled demo:

# After `uv add -e .`
uv run python example_usage.py

Linting / Formatting

uv run ruff check src
uv run ruff format src

TODO

  • Port the KEV environment manager (see ts-utils/src/platform/kev.ts and go-utils/kev.go).

Part of the utils suite by Adrian Galilea.

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

adrian_utils-0.1.1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

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

adrian_utils-0.1.1-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file adrian_utils-0.1.1.tar.gz.

File metadata

  • Download URL: adrian_utils-0.1.1.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for adrian_utils-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2d955ed36c54fc0132ccce26d4e40fb98528f08e44f0f803ebc6b2625c7f8aeb
MD5 3b82d11a1a959010bc364485af4d20b4
BLAKE2b-256 e45f5e0b24c37317af984b3da854ac50f1be81558f4cfae5e6bac0390a258a65

See more details on using hashes here.

Provenance

The following attestation bundles were made for adrian_utils-0.1.1.tar.gz:

Publisher: release.yml on adriangalilea/py-utils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file adrian_utils-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: adrian_utils-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for adrian_utils-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 26615282b0cadea9e62359bb195a289abca80952681524e20f59605173cca487
MD5 7a3613271353dc613cee1105385dac56
BLAKE2b-256 67512e278c01675b17d90dae0f6552833526dff20aab4d0e2dadcd9d7af35cf8

See more details on using hashes here.

Provenance

The following attestation bundles were made for adrian_utils-0.1.1-py3-none-any.whl:

Publisher: release.yml on adriangalilea/py-utils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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