An API Wrapper For Every API
Project description
Fork of AnyAPI for our needs
AnyAPI
AnyAPI is a library that I developed for myself to have better looking code instead putting URLs to everywhere I used dynamic method calls to access a endpoint.
Features
- Have better looking code using dynamic method calls
- Filters to help you to modify request, raise errors or log requests instead of writing functions everywhere.
- Automatically changing proxy according to rate limits specified by you for every path
Examples
Making GET request to https://httpbin.org/anything/endpoint
from anyapi import AnyAPI
base_url = 'https://httpbin.org'
api = AnyAPI(base_url)
api.anything.endpoint.GET()
As you can see dots are pretended as slash and at the end you should put dot and HTTP method you want to use in capital letters.
Setting header before every request
import datetime
from anyapi import AnyAPI
def set_date_as_header(kwargs):
now = datetime.datetime.now()
kwargs['headers'].update({'date': now.strftime('%B %d %Y')})
return kwargs
api = AnyAPI('https://httpbin.org')
api._filter_request.append(set_date_as_header)
print(api.anything.endpoint.GET().json())
# output
{
'args': {},
'data': '',
'files': {},
'form': {},
'headers': {
'Accept-Encoding': 'identity',
'Connection': 'close',
'Date': 'January 16 2019',
'Host': 'httpbin.org'
},
'json': None,
'method': 'GET',
'origin': 'XX.XX.XX.XX',
'url': 'https://httpbin.org/anything/endpoint'
}
As you can see filter worked as expected and set Date
header.
Changing proxy automatically after they reach their rate limit
from anyapi import AnyAPI
proxy_configuration = {
'default': proxy0,
'proxies': [proxy0, proxy1, proxy2,....], # don't forget to add default proxy!
'paths': {
'/anything': rate_limit0,
'/anything/endpoint': rate_limit1
}
}
api = AnyAPI('https://httpbin.org', proxy_configuration=proxy_configuration)
for i in range(10):
print(api.anything.endpoint.GET().json())
If you check output of the all them you can see proxy changes when it reaches limit.
This library is not a new thing
There is a lot of libraries you can find out there for example Uplink, Hammock and many more
Installation
Library is avaible on PyPi so just run
pip install anyapi
To learn more about AnyAPI check wiki page
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
Built Distribution
File details
Details for the file SmoothAPI-1.0.3.tar.gz
.
File metadata
- Download URL: SmoothAPI-1.0.3.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.11.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1361659cb76ad09cefee13854c46c3987cc8107cb7090448c3fc8448791320d7 |
|
MD5 | 8c0fb5101ea0c42c3d6de89baa535cba |
|
BLAKE2b-256 | 0e0030b862adca4a4514f0310a4fe79181f6cfc9cf68e588d63cef025467d94d |
File details
Details for the file SmoothAPI-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: SmoothAPI-1.0.3-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.11.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6d72acf98994e2daf461f93ed5f4856a7fb95681cf526eb10fc556b340031cf |
|
MD5 | 80abdd6d66f3f4fe7f52618ba8a70044 |
|
BLAKE2b-256 | a53bd060ad16dcb4415d2c819e0261b726d46ff18a86597e3ac580d6e586dfa6 |