Skip to main content

High-Performance Asynchronous HTTP Client setting Requests on Fire 🔥

Project description

FireRequests 🔥

GitHub release PyPi version PyPI Downloads Open In Colab

FireRequests is a high-performance, asynchronous HTTP client library for Python, engineered to accelerate your file transfers. By harnessing advanced concepts like semaphores, exponential backoff with jitter, concurrency, and fault tolerance, FireRequests can achieve up to a 10x real-world speedup in file downloads and uploads compared to traditional synchronous methods and enables scalable, parallelized LLM interactions with providers like OpenAI and Google.

Features 🚀

  • Asynchronous I/O: Non-blocking network and file operations using asyncio, aiohttp, and aiofiles, boosting throughput for I/O-bound tasks.
  • Concurrent Transfers: Uses asyncio.Semaphore to limit simultaneous tasks, optimizing performance by managing system resources effectively.
  • Fault Tolerance: Retries failed tasks with exponentially increasing wait times, adding random jitter to prevent network congestion.
  • Chunked Processing: Files are split into configurable chunks for parallel processing, significantly accelerating uploads/downloads.
  • Parallel LLM Calls: Efficiently handles large-scale language model requests from OpenAI and Google with configurable parallelism.
  • Compatibility: Supports environments like Jupyter through nest_asyncio, enabling reusable asyncio loops for both batch and interactive Jupyter use.

Installation 📦

Install FireRequests using pip:

!pip install firerequests

Quick Start 🏁

Accelerate your downloads with just a few lines of code:

Python Usage

from firerequests import FireRequests

url = "https://mirror.clarkson.edu/zorinos/isos/17/Zorin-OS-17.2-Core-64-bit.iso"

fr = FireRequests()
fr.download(url)

Command Line Interface

!fr download https://mirror.clarkson.edu/zorinos/isos/17/Zorin-OS-17.2-Core-64-bit.iso

Parameters:

  • urls (required): The URL to download the file from.
  • --filenames (optional): The name to save the downloaded file. Defaults to filename from URL.
  • --max_files (optional): The number of concurrent file chunks. Defaults to 10.
  • --chunk_size (optional): The size of each chunk in bytes. Defaults to 2 * 1024 * 1024 (2 MB).
  • --headers (optional): A dictionary of headers to include in the download request.
  • --show_progress (optional): Whether to show a progress bar. Defaults to True for single file downloads, and False for multiple files.

Real-World Speed Test 🏎️

FireRequests delivers significant performance improvements over traditional download methods. Below is the result of a real-world speed test:

Normal Download 🐌: 100%|██████████| 3.42G/3.42G [18:24<00:00, 3.10MB/s]
Downloading on 🔥: 100%|██████████| 3.42G/3.42G [02:38<00:00, 21.6MB/s]

🐌 Download Time: 1104.84 seconds
🔥 Download Time: 158.22 seconds

[!TIP] For Hugging Face Hub downloads it is recommended to use hf_transfer for maximum speed gains! For more details, please take a look at this section.

Advanced Usage ⚙️

Downloading Files

from firerequests import FireRequests

urls = ["https://example.com/file1.iso", "https://example.com/file2.iso"]
filenames = ["file1.iso", "file2.iso"]

fr = FireRequests()
fr.download(urls, filenames, max_files=10, chunk_size=2 * 1024 * 1024, headers={"Authorization": "Bearer token"}, show_progress=True)
  • urls: The URL or list of URLs of the file(s) to download.
  • filenames: The filename(s) to save the downloaded file(s). If not provided, filenames are extracted from the URLs.
  • max_files: The maximum number of concurrent chunk downloads. Defaults to 10.
  • chunk_size: The size of each chunk in bytes. Defaults to 2 * 1024 * 1024 (2 MB).
  • headers: A dictionary of headers to include in the download request (optional).
  • show_progress: Whether to show a progress bar during download. Defaults to True for a single file, and False for multiple files (optional).

Uploading Files

from firerequests import FireRequests

file_path = "largefile.iso"
parts_urls = ["https://example.com/upload_part1", "https://example.com/upload_part2", ...]

fr = FireRequests()
fr.upload(file_path, parts_urls, chunk_size=2 * 1024 * 1024, max_files=10, show_progress=True)
  • file_path: The local path to the file to upload.
  • parts_urls: A list of URLs where each part of the file will be uploaded.
  • chunk_size: The size of each chunk in bytes. Defaults to 2 * 1024 * 1024 (2 MB).
  • max_files: The maximum number of concurrent chunk uploads. Defaults to 10.
  • show_progress: Whether to show a progress bar during upload. Defaults to True.

Comparing Download Speed

from firerequests import FireRequests

url = "https://example.com/largefile.iso"

fr = FireRequests()
fr.compare(url)

Generating Text with LLMs

FireRequests supports generating responses from LLMs like OpenAI’s and Google’s generative models in parallel batches. This currently doesn't work in Colab.

from firerequests import FireRequests

# Initialize FireRequests
fr = FireRequests()

# Set parameters
provider = "openai"
model = "gpt-4o-mini"
system_prompt = "Provide concise answers."
user_prompts = ["What is AI?", "Explain quantum computing.", "What is Bitcoin?", "Explain neural networks."]
parallel_requests = 2

# Generate responses
responses = fr.generate(
    provider=provider,
    model=model,
    system_prompt=system_prompt,
    user_prompts=user_prompts,
    parallel_requests=parallel_requests
)

print(responses)

License 📄

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

Sponsors ❤️

Become a sponsor and get a logo here. The funds are used to defray the cost of development.

bmc-button

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

firerequests-0.1.3.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

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

firerequests-0.1.3-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file firerequests-0.1.3.tar.gz.

File metadata

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

File hashes

Hashes for firerequests-0.1.3.tar.gz
Algorithm Hash digest
SHA256 d495389c06ed1af3945ff56d90f7bddaa7d8d8ecc3c33cea22bec17b774f3e3b
MD5 94c2c72130c802e2c03aad1c35c2903d
BLAKE2b-256 37b1c9c50f4f4467974cf184e3b449efdcbf1f9c7ca447b29d7dc23463aec656

See more details on using hashes here.

File details

Details for the file firerequests-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: firerequests-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for firerequests-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8e44889871c3103c1e8f3ff951fd85dbe4fbdb9fc2af65371e0e2bbc06372733
MD5 a211ed97c2375441c39acb684b4973a2
BLAKE2b-256 83ebecb4cb7ebd19c3f978efedb8d7140863b030fde39903b2271da9697dd64a

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