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.tsandgo-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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d955ed36c54fc0132ccce26d4e40fb98528f08e44f0f803ebc6b2625c7f8aeb
|
|
| MD5 |
3b82d11a1a959010bc364485af4d20b4
|
|
| BLAKE2b-256 |
e45f5e0b24c37317af984b3da854ac50f1be81558f4cfae5e6bac0390a258a65
|
Provenance
The following attestation bundles were made for adrian_utils-0.1.1.tar.gz:
Publisher:
release.yml on adriangalilea/py-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
adrian_utils-0.1.1.tar.gz -
Subject digest:
2d955ed36c54fc0132ccce26d4e40fb98528f08e44f0f803ebc6b2625c7f8aeb - Sigstore transparency entry: 661766854
- Sigstore integration time:
-
Permalink:
adriangalilea/py-utils@258ef504203d822c343f4b6c1a3810bf5b8bb7c9 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/adriangalilea
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@258ef504203d822c343f4b6c1a3810bf5b8bb7c9 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26615282b0cadea9e62359bb195a289abca80952681524e20f59605173cca487
|
|
| MD5 |
7a3613271353dc613cee1105385dac56
|
|
| BLAKE2b-256 |
67512e278c01675b17d90dae0f6552833526dff20aab4d0e2dadcd9d7af35cf8
|
Provenance
The following attestation bundles were made for adrian_utils-0.1.1-py3-none-any.whl:
Publisher:
release.yml on adriangalilea/py-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
adrian_utils-0.1.1-py3-none-any.whl -
Subject digest:
26615282b0cadea9e62359bb195a289abca80952681524e20f59605173cca487 - Sigstore transparency entry: 661766860
- Sigstore integration time:
-
Permalink:
adriangalilea/py-utils@258ef504203d822c343f4b6c1a3810bf5b8bb7c9 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/adriangalilea
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@258ef504203d822c343f4b6c1a3810bf5b8bb7c9 -
Trigger Event:
push
-
Statement type: