Skip to main content

General Utilities

Project description

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.

Features

Logging Utilities

  • log: Flexible logging setup using Loguru, with optional Logfire integration for cloud logging and metrics. Includes helpers to intercept standard logging and route it through Loguru for unified log handling.

HTTP Utilities

  • http: A high-level HTTP client built on top of httpx and hishel, setting some caching and timeout comment settings.

Installation

To install Wardy Utils, use pip:

pip install wardy-utils

Logging extras

To use logging features, install with the appropriate extras:

  • For Loguru logging:
     pip install wardy-utils[loguru]
    
  • For Logfire integration:
     pip install wardy-utils[logfire]
    

Usage

Logging Example

wardy_utils.log provides flexible logging setup using Loguru, with optional Logfire integration for cloud logging and metrics. It can intercept standard Python logging and route it through Loguru for unified log handling.

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 and system metrics
  • Customizable log formats, rotation, and retention

Basic usage:

from wardy_utils.log import configure_logging

# Set up logging to both stderr and a rotating file
configure_logging("myapp")

from loguru import logger
logger.info("Hello from Loguru!")

# Standard logging is also intercepted:
import logging
logging.warning("This will also go to Loguru!")

Logfire Integration

If the environment variable LOGFIRE_TOKEN is set, Logfire will be configured automatically for cloud log aggregation and system metrics. You can also set REFLEX_ENV_MODE to prefix the service name.

Customization

You can customize log formats, rotation, and retention:

configure_logging(
	"myapp",
	standard_format="[{time}] {level} - {message}",
	detail_format="{time} {file}:{line} {level} {message}",
	log_rotation="1 day",
	log_retention="7 days",
)

HTTP Client Example

from wardy_utils.web import cached_client

client = cached_client()
response = client.get("https://example.com")
print(response.text)

Convenience singletons live in wardy_utils.web if you want ready-made instances without wiring:

  • 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 overrides for the HTTP client:

Variable Description Default
WARDY_UTILS_CACHE_DIR Directory for the sqlite cache file. In-memory
WARDY_UTILS_CACHE_FILENAME Filename for the sqlite cache file when a cache directory is set. wardy-utils-cache.sqlite
WARDY_UTILS_CACHE_TTL Cache TTL in seconds. 1800
WARDY_UTILS_TIMEOUT Request timeout in seconds. 45
WARDY_UTILS_FORCE_CACHE If truthy, ignore origin cache-control headers. Disabled
WARDY_UTILS_HTTP2 Enable or disable HTTP/2. Enabled

Proxy behaviour: the client inherits proxy settings from standard http_proxy, https_proxy, and all_proxy environment variables, so you can point traffic via your organisation's proxy without code changes.

Requirements

  • Python 3.13.3 or higher

Contributing

Contributions are welcome! Run the test suite with coverage via:

pytest --cov=src --cov-report=xml

Feel free to open issues or submit pull requests to improve the library.

License

This project is licensed under the MIT License.

Author

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

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

wardy_utils-0.3.2.tar.gz (5.8 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.3.2-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wardy_utils-0.3.2.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.23 {"installer":{"name":"uv","version":"0.9.23","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.3.2.tar.gz
Algorithm Hash digest
SHA256 972aa577ad0423dc3028108c4a1abcb64af196899a8d6946d0f5f2d416def711
MD5 3595c416b462a00828a5e5d3f5f2f468
BLAKE2b-256 ffb60fad0197a5017e8f7598212293e885c346bd9796579f81b806005a29fa6a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wardy_utils-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.23 {"installer":{"name":"uv","version":"0.9.23","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.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c58332d83acf1caedc188c419d61cf0feaa146ebe2f05262303e18cbfb1b5045
MD5 c7a5f5aca2d3cf914a5f8c4aa9870789
BLAKE2b-256 502980f1d9c6586d951db8628b04995ec1a478b42a6b68667b4bbd165cc8ee05

See more details on using hashes here.

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