Skip to main content

An enhanced wrapper for the requests library with retry, timeout, and logging capabilities

Project description

Requests Enhanced

CI PyPI version Python Versions License

An enhanced wrapper for the popular requests library with additional features for improved reliability and convenience in Python HTTP requests.

Features

  • Automatic Retries: Built-in retry mechanism with configurable backoff strategy
  • Timeout Handling: Enhanced timeout configuration and error handling
  • Improved Logging: Customizable logging with formatted output
  • Utility Functions: Simplified JSON request handling

Installation

# From PyPI
pip install requests-enhanced

# From source (development)
git clone https://github.com/khollingworth/requests-enhanced.git
cd requests-enhanced
pip install -e ".[dev]"

Quick Start

from requests_enhanced import Session

# Create a session with default retry and timeout settings
session = Session()

# Simple GET request
response = session.get("https://api.example.com/resources")
print(response.json())

# POST request with JSON data
data = {"name": "example", "value": 42}
response = session.post("https://api.example.com/resources", json=data)

Utility Functions

For quick, one-off requests:

from requests_enhanced.utils import json_get, json_post

# GET request that automatically returns JSON
data = json_get("https://api.example.com/resources")

# POST request with automatic JSON handling
result = json_post("https://api.example.com/resources", data={"name": "example"})

Error Handling

from requests_enhanced import Session
from requests_enhanced.exceptions import RequestTimeoutError, RequestRetryError

try:
    session = Session()
    response = session.get("https://api.example.com/resources")
except RequestTimeoutError as e:
    print(f"Request timed out: {e}")
    print(f"Original exception: {e.original_exception}")
except RequestRetryError as e:
    print(f"Retry failed: {e}")

Documentation

Detailed documentation is available in the docs directory:

Development

Setup Development Environment

# Clone the repository
git clone https://github.com/khollingworth/requests-enhanced.git
cd requests-enhanced

# Create a virtual environment (recommended)
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install development dependencies
pip install -e ".[dev]"

Running Tests

# Run all tests
pytest

# Run with coverage report
pytest --cov=src/requests_plus --cov-report=term-missing

# Run specific test file
pytest tests/test_sessions.py

Code Style

This project uses black for code formatting and flake8 for linting:

# Format code
black src tests examples

# Check code style
flake8 src tests examples

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

requests_enhanced-0.1.4.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

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

requests_enhanced-0.1.4-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file requests_enhanced-0.1.4.tar.gz.

File metadata

  • Download URL: requests_enhanced-0.1.4.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for requests_enhanced-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ed984ea5823c20950fb0f78ac5ae33a7e68ee4ac330b4fbfc8b24bd2e5bfb601
MD5 e06e7157dfbfa3b0e34ec977966b0585
BLAKE2b-256 4dad45a650f118ad4bf273097a64dcd24709be2aa7b15eb06cc564436a5582fa

See more details on using hashes here.

File details

Details for the file requests_enhanced-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for requests_enhanced-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c4b013170f0cc58cdd2dc7d76ed7fc0228808daa5a5d4334133af3f643e4a665
MD5 0f287a00b8a68e22c437e8e0a0f176ab
BLAKE2b-256 cfe0b4c19e94d7ed9d4a9dbaa87ca534a866a051ff271dfebbcc79eb22cb3313

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