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_enhanced --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.6.tar.gz (12.2 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.6-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: requests_enhanced-0.1.6.tar.gz
  • Upload date:
  • Size: 12.2 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.6.tar.gz
Algorithm Hash digest
SHA256 4b1f5b253b4dc052ad046d022c2056ac8f842cd98bb14da5b11ab92c91fee334
MD5 ab7022539c0114449bbcab4248a17ac9
BLAKE2b-256 1a32864a27e3ea7d2d247c50a0fc44c6044087223612cef3fc5922a4c7f3da08

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for requests_enhanced-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 acd1c0c5b3a932710e2dd4997c0c6b52fb3549e79d49c84e4f252fc90d101952
MD5 5956d5983b5a0440500d3bbc39a83511
BLAKE2b-256 ab670816795700e7c63a5ebc14420c6785bf2c1c8218bfc3c14da121959c5f78

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