Wrapper around requests package, with extra API key management
Project description
requests-wrapper
Code quality checks | Status |
---|---|
CodeFactor | |
Github Workflows | |
Codecov |
This repo is a wrapper programme based python's requests package, adding a simple API key management capability.
It is designed to:
- Enable calling API endpoints using multiple API keys
- So that different API keys can be used for each consecutive call
- This can potentially benefit in cases where each API key is rate limiting
- When the rate limit is specified, this wrapper will automatically sleep accordingly until
the API key can be used again, reducing the chance of getting
a bad
429 Too Many Requests
error code
Installation
pip install requests-wrapper
Example
from requests_wrapper.requests_wrapper import RequestsWrapper
# Load API keys and rate limit when constructing the class instance
requests_wrapper = RequestsWrapper(
api_keys=["<api_key1>", "<api_key2>"],
call_limit_per_second=2
)
queries = ["search_term1", "search_term2", "search_term3"]
responses = []
for query in queries:
# Calling this is almost the same as calling requests,
# with the addition of specifying http_method and api_key_header
response = requests_wrapper.call(
http_method="get",
api_key_header="Authorization",
url="<my_url>",
params={"q": query}
)
responses.append(response)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
requests_wrapper-0.0.2.tar.gz
(3.1 kB
view hashes)
Built Distribution
Close
Hashes for requests_wrapper-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c4b520e500ee2c897aaaa65ae6740c32e60f719fad7f9f3d7d2bc1d957bf789 |
|
MD5 | a98fa63affe5e43efbc118c5dc344fd7 |
|
BLAKE2b-256 | 0b49beb2477aa89f8045eb12685a5bb4652cf1da0f165159d758172d5f342a90 |