Skip to main content

Concurrent request HTTP execution library

Project description

coollogo_com-289063340

Concurrent request HTTP execution library Python Package using Conda

What is it?

hyper-requests is a Python library, enabling multithreading of API calls using asyncio. It takes a list of URLs and a list of parameters as input and then uses the requests library to make these calls asynchronously (https://pypi.org/project/requests/).

Usage

Installation

Install hyper-requests using pip:

pip install hyper-requests

Example

import hyper_requests

# Define the request parameters
params = [
    {'url': 'http://httpbin.org/get' , 'data': 'value1'},
    {'url': 'http://httpbin.org/get' , 'data': 'value3'},
    {'url': 'http://httpbin.org/get' , 'data': 'value5'},
    {'url': 'http://httpbin.org/get' , 'data': 'value7'},
    {'url': 'http://httpbin.org/get' , 'data': 'value9'}
]

# Create an instance of AsyncRequests and execute the requests
returned_data = hyper_requests.get(request_params=params, workers=10)

# Process the returned data
for response in returned_data:
    print(response)

This example demonstrates the usage of hyper-requests to perform asynchronous HTTP(s) requests.

First, make sure you have installed hyper-requests by running the command pip install hyper-requests.

Next, import hyper_requests and utilise the .get() function.

Create a list of request parameters using dictionaries, where each dictionary represents a set of parameters for an individual request. In this example, each request MUST have a URL specified with the 'url' key, all other paramters must match the classic request template.

These must now be inputed to the .get() function, with the number of concurrent worker threads to use with the workers argument (in this case, workers=10). The return value is a list of json responses.

Finally, process the returned data as desired. In this example, each response is printed, but you can perform further operations based on your specific needs.

Performance

It is hyper fast!

Within the test/performance directory there is a performance test that makes 20 API calls to the random joke generator api: https://official-joke-api.appspot.com/random_joke.

Using hyper requests the time taken to make these calls is ~2 second, using synchronous api calls takes ~16 seconds.

============================= test session starts ==============================
collecting ... collected 1 item

test_performance.py::PerformanceTest::test_api_performance

============================== 1 passed in 17.76s ==============================

Process finished with exit code 0
PASSED        [100%]
Asynchronous Execution time: 1.845513105392456 seconds
Asynchronous Data length: 20
Synchronous Execution time: 15.81911015510559 seconds
Synchronous Data length: 20

TODO

  • Create input to .get() more intuitive e.g. mirror the requests functionality
  • Add time limit on requests to deal with request limits

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

hyper_requests-0.0.12.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

hyper_requests-0.0.12-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file hyper_requests-0.0.12.tar.gz.

File metadata

  • Download URL: hyper_requests-0.0.12.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for hyper_requests-0.0.12.tar.gz
Algorithm Hash digest
SHA256 e768c93b085f7dec0144f4ab6f23882c8b361d67b7f27fd54b07a898706a9501
MD5 c2a71c460536703b0947a5f57bce2a51
BLAKE2b-256 fa58d7986d0598fdbb48a37b418b80599371120bea279092aef3cbc83c92da71

See more details on using hashes here.

File details

Details for the file hyper_requests-0.0.12-py3-none-any.whl.

File metadata

File hashes

Hashes for hyper_requests-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 167cbc3187cea19521aac0129c87b2d97c94d5a3c2a1bcd2e00e8c0449c2c212
MD5 b4dbdaf99c831c7a39635681058815b7
BLAKE2b-256 d9f53d34bd17f3e4ae55c6088dfff8e74cf1d1c588aa2bed9ef8698c9d5cc57e

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