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.1.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.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wardy_utils-0.3.1.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.1.tar.gz
Algorithm Hash digest
SHA256 82f7116f7a82032937fe97270738bd5be42e8cc868610d40c10d5336f9c54c8a
MD5 e40bb9cc72a9cc549e864497aaaff287
BLAKE2b-256 020ac99393105e06cf4a79cbc1c9ec904f7e00b6dc19cda855f1cf3c5355274b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wardy_utils-0.3.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fb327d20cb03778fb8dbd44783b49d3e303a6279cf52010ff72608a6ec732243
MD5 a22755cb0fe3ff7372cf5f2a6f8f578d
BLAKE2b-256 e2325b6282b24476778c670400109f3f803d4fa06937d6c2ddb06b6c612cd838

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