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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for requests_enhanced-0.1.0.tar.gz
Algorithm Hash digest
SHA256 819d7a0f2f0ccd1441ebe93a89ca87db5da59d224f146be38d94d99bca55b2b9
MD5 4bbb309c71d474b150ecc0df104b2f82
BLAKE2b-256 4afdbf34e354fa2b6985d1d543cebcbdeb421e73a62adf7670a913f25004d9b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for requests_enhanced-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f035fd94f06257c5538505e7e2680df3ed7b67c0e055874158bdc1e9a268c1d0
MD5 b89557973a1f2cd2b591671bb5025421
BLAKE2b-256 5a1319f4805c0b7c30c55a09838afcefe9cac6f058eea7e4cfb43fdca628f4af

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