Skip to main content

A simple, transport-agnostic wrapper for retrying callables.

Project description

Invoker Guard

A simple, transport-agnostic wrapper for executing callables with robust, configurable retry logic, powered by tenacity.

It allows you to write your retry and validation logic once and apply it to different HTTP libraries like requests, httpx, and niquests.

Installation

Install the core library:

pip install invoker-guard

Then, install the support for the HTTP library you want to use:

# For requests support
pip install invoker-guard[requests]

# For httpx support
pip install invoker-guard[httpx]

# For everything
pip install invoker-guard[requests,httpx,niquests]

How to Use

The library's main function is invoke. You provide it with:

  1. A callable_action (a lambda that calls your HTTP library).
  2. A RetryConfig object defining your rules.
  3. A Transport object that matches your library.

Example with requests

import requests
from invoker_guard import invoke, RetryConfig, RetryError, REQUESTS_TRANSPORT

# Define rules
config = RetryConfig(expected_status_codes=[200])

# Define action
url = "https://api.example.com/data"
action = lambda: requests.get(url, timeout=10)

# Invoke it
try:
    response = invoke(action, config, transport=REQUESTS_TRANSPORT)
    print("Success:", response.json())
except RetryError as e:
    print("Failed after all retries:", e)

Example with httpx

The logic is identical—just swap the library and the transport object.

import httpx
from invoker_guard import invoke, RetryConfig, RetryError, HTTPX_TRANSPORT

# Define rules (can be the same config object)
config = RetryConfig(expected_status_codes=[200], required_json_keys=["id"])

# Define action for httpx
url = "https://api.example.com/data"
action = lambda: httpx.get(url, timeout=10)

# Invoke it
try:
    response = invoke(action, config, transport=HTTPX_TRANSPORT)
    print("Success:", response.json())
except RetryError as e:
    print("Failed after all retries:", e)

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

invoker_guard-0.3.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

invoker_guard-0.3.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file invoker_guard-0.3.0.tar.gz.

File metadata

  • Download URL: invoker_guard-0.3.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.8

File hashes

Hashes for invoker_guard-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b0c8c179bcbb4ff73245f90631d5d94243ce3572655cbfde391eb546312c7988
MD5 13e1e7fcf85c8bd778e0834d03363cc3
BLAKE2b-256 1cc6aee4af8b4f2af9bf51fa0dd9fbeb39ad564d3729fd0fa43f99d0b25a6a8d

See more details on using hashes here.

File details

Details for the file invoker_guard-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: invoker_guard-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.8

File hashes

Hashes for invoker_guard-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0d010e43f3fcc3a574ed7fa195cfd597f4eb773746d1e236647fc822d1a94bce
MD5 6d34e4ecd35bf27595a4fa055db9d137
BLAKE2b-256 6617b1790e53afc94b8ee0cdc34777b9b98ae47912926b058ea91166954fd898

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