Skip to main content

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]

# 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 to APP_ENVIRONMENTREFLEX_ENV_MODENODE_ENVENVIRONMENT

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 client
  • sync_force_client: Sync client that ignores origin cache headers
  • async_client: Default async client
  • async_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.

Requirements

  • Python 3.14 or higher

License

This project is licensed under the MIT License.

Author

Created by Wardy Email: wardy3+gitlab@gmail.com

Download files

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

Source Distribution

wardy_utils-0.6.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

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

wardy_utils-0.6.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file wardy_utils-0.6.0.tar.gz.

File metadata

  • Download URL: wardy_utils-0.6.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","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}

File hashes

Hashes for wardy_utils-0.6.0.tar.gz
Algorithm Hash digest
SHA256 c035d80ea6a8c0f0e30794f332106bf7bd50bde0aec8f35d94516d981dc81f88
MD5 fe263cb9aa2184d4b6fe4ea8e3d181a8
BLAKE2b-256 7807390296eb5fafca2133eb03ed90f993c5cae4c1f19bceecb29a5b55ff5cee

See more details on using hashes here.

File details

Details for the file wardy_utils-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: wardy_utils-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","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}

File hashes

Hashes for wardy_utils-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0c03ca701ef35f0a64121d04ff02d4c8f93c086cf49480c5445f4a1f4710835b
MD5 d5ca2ff756ce685935d3767734c3035f
BLAKE2b-256 f52d9b5b71891d934569c938e7251860e9fc61a2be1b59fc6e1f570dade9ac39

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 files

0.5.4

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page