Wardy Utils
Wardy Utils is a collection of general-purpose utilities designed to simplify and enhance your Python scripting experience. This library provides reusable components that can be integrated into your projects to save time and effort.
Installation
pip install wardy-utils
The base package only includes pydantic-settings. Install extras for additional functionality:
# Logging with Loguru
pip install wardy-utils[log]
# HTTP client with caching
pip install wardy-utils[web]
# Neon free-plan usage check
pip install wardy-utils[neon]
# Both
pip install wardy-utils[log,web]
Features
Logging (wardy-utils[log])
Flexible logging setup using Loguru, with optional Logfire integration for cloud logging and metrics.
Key features:
- Simple setup for rotating file and stderr logging
- Intercepts standard Python logging and redirects to Loguru
- Optional Logfire integration for cloud log aggregation
- Automatic instrumentation of available libraries (system-metrics, psycopg, httpx, sqlalchemy, redis, asyncpg)
Basic usage:
from wardy_utils.log import configure_logging, logger
# Set up logging to both stderr and a rotating file
configure_logging("myapp")
logger.info("Hello from Loguru!")
# Standard logging is also intercepted:
import logging
logging.warning("This will also go to Loguru!")
With Logfire cloud logging:
from wardy_utils.log import configure_logging, logger
# service_name defaults to the current working directory name
configure_logging("my-app")
# Or specify explicitly
configure_logging("my-app", service_name="my-app", environment="prod")
logger.info("This goes to Logfire too!")
Set WARDY_UTILS_LOG_LOGFIRE_TOKEN to enable Logfire. You must have logfire installed separately:
pip install logfire[system-metrics,psycopg,httpx] # with desired extras
Customization:
from wardy_utils.log import configure_logging, LogConfig
config = LogConfig(
file_level="INFO",
standard_format="[{time}] {level} - {message}",
detail_format="{time} {file}:{line} {level} {message}",
rotation="1 hour",
retention="14 days",
)
configure_logging("my-app", service_name="my-app", config=config)
Environment variables:
| Variable | Description | Default |
|---|---|---|
WARDY_UTILS_LOG_LOGFIRE_TOKEN |
Token for Logfire cloud logging | (disabled) |
WARDY_UTILS_LOG_LOGFIRE_SERVICE_NAME |
Service name for Logfire | (cwd name) |
WARDY_UTILS_LOG_LOGFIRE_ENVIRONMENT |
Environment name for Logfire | (cascaded) |
Cascade behavior when not explicitly set:
LOGFIRE_SERVICE_NAME: Falls back to the current working directory name (e.g.beer-cloud)LOGFIRE_ENVIRONMENT: Falls back toAPP_ENVIRONMENT→REFLEX_ENV_MODE→NODE_ENV→ENVIRONMENT
HTTP Client (wardy-utils[web])
A high-level HTTP client built on httpx and hishel with built-in caching.
Basic usage:
from wardy_utils.web import cached_client
client = cached_client()
response = client.get("https://example.com")
print(response.text)
Pre-configured singletons:
from wardy_utils.web import sync_client, async_client
# Sync client with default settings
response = sync_client.get("https://example.com")
# Or use async
async def fetch():
response = await async_client.get("https://example.com")
Available singletons:
sync_client: Default sync clientsync_force_client: Sync client that ignores origin cache headersasync_client: Default async clientasync_force_client: Async client that ignores origin cache headers
Environment variables:
| Variable | Description | Default |
|---|---|---|
WARDY_UTILS_WEB_CACHE_DIR |
Directory for the sqlite cache file | In-memory |
WARDY_UTILS_WEB_CACHE_FILENAME |
Filename for the sqlite cache file | wardy_cache.db |
WARDY_UTILS_WEB_CACHE_TTL |
Cache TTL in seconds | 1800 (30 min) |
WARDY_UTILS_WEB_TIMEOUT |
Request timeout in seconds | 45 |
WARDY_UTILS_WEB_FORCE_CACHE |
If truthy, ignore origin cache-control headers | Disabled |
WARDY_UTILS_WEB_HTTP2 |
Enable or disable HTTP/2 | Enabled |
Proxy support: The client inherits proxy settings from standard http_proxy, https_proxy, and all_proxy environment variables.
Neon usage (wardy-utils[neon])
Checks a Neon project's compute usage against the free plan's monthly CU-hour allowance, and projects the month-end total from the rate since the 1st. Calling Neon's API does not wake the database. Nothing is logged; HTTP and parsing errors (httpx.HTTPError, KeyError, ValueError) propagate for the caller to handle.
from wardy_utils.neon import get_usage
usage = await get_usage("my-project-id", api_key, allowance=100)
print(usage.cu_hours, usage.pct_used, usage.projected_cu_hours, usage.projected_pct)
With several worker processes, claim_usage_lock(path) lets only one of them call Neon: it returns an open lock file while held, or None if another process has it.
Requirements
- Python 3.12 or higher
- Linux or macOS (
wardy_utils.neonusesfcntlfor its usage lock)
License
This project is licensed under the MIT License.
Author
Created by Wardy Email: wardy3+gitlab@gmail.com
Metadata
Release files for wardy-utils 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| wardy_utils-1.0.0.tar.gz | 14.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| wardy_utils-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.1 kB
Release files / wardy_utils-1.0.0.tar.gz
| Download URL | wardy_utils-1.0.0.tar.gz |
|---|---|
| Size | 14.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fcadc94520a630a42c87e7f11ac3d93a11775729a13ae1d42ed0d2762c115399
|
|
BLAKE2b-256 checksum How to use checksums |
a8ed66e39c8cfc2a52e175f5e8897d25e17f1562275f219e1157ac640bae1395
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / wardy_utils-1.0.0-py3-none-any.whl
| Download URL | wardy_utils-1.0.0-py3-none-any.whl |
|---|---|
| Size | 15.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
23aeeca3f993d505c6d305c175abec4ec428045d2bb5eb5c4ad7439cb1d1f971
|
|
BLAKE2b-256 checksum How to use checksums |
95473d0e9dcf62aa662e92b9e4f913bea4002413541380362cb1658c24849212
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for wardy-utils 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.