Request Forge Documentation

PyPI version Python versions License: MIT Tests

Welcome to Request Forge

Request Forge is a production-ready, thread-safe Request Forge library for Python with advanced features including:

  • Automatic Retry Strategies - Exponential backoff, circuit breaker patterns

  • Token Management - Automatic token caching, refresh, and expiration handling

  • Multi-Step Authentication - Pipeline-based authentication for complex OAuth flows

  • Lifecycle Hooks - Extensible request/response interception

  • Thread-Safe - Safe for use in multi-threaded environments (Django, Flask, FastAPI)

  • Comprehensive Error Handling - Rich exception hierarchy with detailed context

  • Type Hints - Full type annotations for IDE autocomplete

Quick Example

from requestforge import HttpClient, HttpClientConfigBuilder

# Create configured client
config = (
    HttpClientConfigBuilder()
    .with_base_url('https://api.example.com')
    .with_retry(max_retries=3)
    .with_logging()
    .build()
)

client = HttpClient(config)

# Make requests
response = client.get('/users/1')
if response.is_success:
    user = response.json()
    print(f"User: {user['name']}")

Table of Contents

User Guide

API Reference

Examples

Features

Core Features

  • Clean API: Intuitive interface for all HTTP methods

  • Thread-Safe: Connection pooling and thread-local sessions

  • Builder Pattern: Fluent configuration interface

  • Context Managers: Clean resource management

  • Type Hints: Full type annotations

Authentication

  • Token Management: Automatic caching and refresh

  • Multi-Step Pipelines: Chain multiple auth steps

  • Auto-Retry on 401: Automatic token refresh and retry

  • Multiple Auth Types: Bearer, API Key, Basic, Custom

Retry Strategies

  • Exponential Backoff: Configurable with jitter

  • Circuit Breaker: Prevent cascade failures

  • Custom Strategies: Implement your own logic

  • Status Code Retry: Retry on specific HTTP codes

Indices and tables