Skip to main content

Fast parallel HTTP requests with asyncio, retry logic, proxy rotation, and rate limiting

Project description

fastreq v2.0.2

PyPI Version Python Version License: MIT Test Coverage Tests

Fast parallel HTTP requests with asyncio, retry logic, proxy rotation, and rate limiting.

Features

  • Parallel Execution: Execute multiple HTTP requests concurrently with automatic async/sync handling
  • Multiple Backends: Support for niquests, aiohttp, httpx, and requests with automatic backend detection
  • Retry Logic: Exponential backoff with jitter for resilient request handling
  • Proxy Rotation: Automatic proxy management with support for authenticated proxies
  • Rate Limiting: Token bucket algorithm for precise request rate control
  • User-Agent Rotation: Built-in user agent string rotation
  • Cookie Management: Session-based cookie handling with set/reset methods
  • Flexible Response Parsing: Custom parse functions, keyed responses, and graceful failure handling
  • HTTP/2 Support: Full HTTP/2 support when using the niquests backend
  • Streaming: Efficient streaming of large responses

Installation

# Core library only
pip install fastreq

# With specific backend (recommended: niquests for HTTP/2 support)
pip install fastreq[niquests]  # Primary (recommended)
pip install fastreq[aiohttp]
pip install fastreq[httpx]
pip install fastreq[requests]

# All backends
pip install fastreq[all]

Quick Start

Sync Usage

from fastreq import parallel_requests

results = parallel_requests(
    urls=[
        "https://api.github.com/repos/python/cpython",
        "https://api.github.com/repos/python/cpython/issues",
        "https://api.github.com/repos/python/cpython/pulls",
    ],
    concurrency=3,
)

for result in results:
    print(result.json())

Async Usage

import asyncio
from fastreq import parallel_requests_async

async def main():
    results = await parallel_requests_async(
        urls=[
            "https://httpbin.org/delay/1",
            "https://httpbin.org/delay/2",
            "https://httpbin.org/delay/3",
        ],
        concurrency=5,
        timeout=10,
    )
    return results

results = asyncio.run(main())

Context Manager

from fastreq import ParallelRequests

async def main():
    async with ParallelRequests(concurrency=5) as client:
        results = await client.request(urls=["https://httpbin.org/get"] * 10)
    return results

Documentation

Examples

Visit the examples folder for 17 executable code samples covering all library features, including:

  • Basic requests and concurrency tuning
  • Rate limiting and retry configuration
  • Proxy and user-agent rotation
  • POST data and streaming downloads
  • Error handling and backend selection
  • Cookie management and keyed responses

Development

Versioning and Publishing

This project uses semantic versioning. To release a new version:

  1. Update the version in pyproject.toml
  2. Create a version tag:
# For patch release (e.g., v2.0.1)
git tag v2.0.1

# For minor release (e.g., v2.1.0)
git tag v2.1.0

# For major release (e.g., v3.0.0)
git tag v3.0.0
  1. Push the tag to trigger the automated workflow:
git push origin v2.0.1

The workflow will:

  • Run tests, linting, and type checking
  • Create a version tag and update CHANGELOG.md
  • Publish to PyPI

Backend Selection

The library automatically detects and uses the best available backend in this priority order:

  1. niquests - Recommended (HTTP/2 support, streaming, async native)
  2. aiohttp - Streaming support, async native
  3. httpx - Modern sync/async HTTP client
  4. requests - Sync-first, widely used

To explicitly select a backend:

from fastreq import parallel_requests

results = parallel_requests(
    urls=["https://httpbin.org/get"],
    backend="niquests",  # Explicit backend selection
)

License

MIT License - see LICENSE 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

fastreq-2.0.2.tar.gz (244.9 kB view details)

Uploaded Source

Built Distribution

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

fastreq-2.0.2-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

File details

Details for the file fastreq-2.0.2.tar.gz.

File metadata

  • Download URL: fastreq-2.0.2.tar.gz
  • Upload date:
  • Size: 244.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fastreq-2.0.2.tar.gz
Algorithm Hash digest
SHA256 5c245d04b1783227d88fd0de2fb93726a4a6ca5470541a4b4cfc15ccdc374912
MD5 7175e464e431cc2c77abb3c59cd5e6f4
BLAKE2b-256 d30e728f9c8c67ee9fab25de56c3a5a487546797a397f9efe782fefc14942742

See more details on using hashes here.

File details

Details for the file fastreq-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: fastreq-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 29.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fastreq-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0a960738c21d23ba48aef19683bd8ffb64afcee059938ae1d3b47e1cd228b91e
MD5 cc5c5640bb6d3149a99395ce649bd9a2
BLAKE2b-256 8113ccfa9f6a40448e463f561eaa41ccb12503242fb6ddf03d503a8e21adc411

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