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.2.tar.gz (8.8 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.2-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: adrian_utils-0.1.2.tar.gz
  • Upload date:
  • Size: 8.8 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.2.tar.gz
Algorithm Hash digest
SHA256 5bcf5ff3c7a745cdc2943bce488570281efc157d959098c153c4629f6e2680dc
MD5 cee73096c136ba61d7b1c4b3f5f4176f
BLAKE2b-256 b3b6e6eaf86c64923a5d4e8a5f1cb17b7046d2e70a0540a8dee8039ccc804290

See more details on using hashes here.

Provenance

The following attestation bundles were made for adrian_utils-0.1.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: adrian_utils-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dc65d8c52a041e435e0a3fc49ac5f1d066305ca5a0c5404fa1e2e974e6bf81aa
MD5 df87410502c2d0aff52a10522a8a64a2
BLAKE2b-256 00e696217ce411d339f10f9e9b7b969d6d022a08c647ca358e76fdef7a75b8ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for adrian_utils-0.1.2-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