A lite client for restful APIs.
Project description
restful-client-lite 
A lite client for RESTFul APIs with limited features.
It provides:
restful_client_lite.APIClient
: client for eve token-auth appsrestful_client_lite.contrib.AliyunApiGatewayClient
: client for apis generated by aliyun DataService (onlyGET
is supported)restful_client_lite.contrib.WangduoyunApiClient
: client for Wangduoyun apis by WangDuoYun
WIP.(not stable before v0.1.0)
Installation
Lastest release 
pipenv:
pipenv install restful_client_lite
pip:
pip install restful_client_lite
Dev
pipenv:
pipenv install -e git+https://github.com/huandzh/restful-client-lite#egg=restful-client-lite
pip:
pip install -e git+https://github.com/huandzh/restful-client-lite#egg=restful-client-lite
Usage
Assume that we have a restful api requiring Authorization:<token>
in the header and using etag to control writes.
Create an API client:
from restful_client_lite import APIClient
api = APIClient("<api_root>", {"token": "<token>"})
Get from url:
res_get = api.get("<url>")
Post to url:
res_post = api.post("<url>", data={"<key>": "<value>"})
Patch url:
res_patch = api.patch("<url>", "<etag>", data={"<key>": "<value>"})
Patch url (fetch etag automatically in advance):
res_patch = api.patch_auto_etag("<url>", data={"<key>": "<value>"})
Delete url:
res_delete = api.delete("<url>", "<etag>")
Delete url (fetch etag automatically in advance):
res_delete = api.delete_auto_etag("<url>")
Subclass APIClient
to create custom api client:
def sign(url):
"""some function return signature"""
...
return <signed url>
class CustomAPIClient(APIClient):
"""custom api client"""
def auth_headers(self, f: Callable) -> Callable:
"""custom auth headers"""
@wraps(f)
def wrapper(*args, **kwargs):
headers = kwargs.get("headers", {}).copy()
url = args[0]
headers.update({"Signature": sign(url)})
kwargs["headers"] = headers
return f(*args, **kwargs)
3rd-party APIs
aliyun api gateway
AliyunApiGatewayClient
:
- support
GET
from aliyun-api-gateway apis (apis may generated by DataService) - handle authorization headers
- doesn't sort url params
from restful_client_lite.contrib.aliyun import AliyunApiGatewayClient
api = AliyunApiGatewayClient(
'<api_root>',
{"app_id": '<app_id>',
"app_secret": '<app_secret>'})
# make sure params in <url> are sorted
res = api.get('<url>')
wangduoyun api
WangduoyunApiClient
:
- support account apis
- support graphql apis
# client adds required authorization data for POST
api = WangduoyunApiClient(
"<api_root>",
{"user_key": "<user_key>",
"user_secret": "<user_secret>"})
res = api.post("<url>")
# client provides `get_sign` to get authorization params
api = WangduoyunApiClient(
"<api_root>",
{"user_key": "<user_key>",
"user_secret": "<user_secret>"})
sign, timestamp = api.get_sign()
url = "?user_key={user_key}×tamp={timestamp}&sign={sign}&source_id={source_id}&query={query}".format(
user_key=api.auth['user_key'],
timestamp=timestamp,
sign=sign,
source_id="<source_id>",
query="<query>")
res = api.get(url)
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 restful-client-lite-0.0.5.tar.gz
.
File metadata
- Download URL: restful-client-lite-0.0.5.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
2fc728eb0231d77351aa54635c71009cc8c9c71af2383b0bf47507bb6ed9149a
|
|
MD5 |
9288f9a4ff5639b1f476542875a1b097
|
|
BLAKE2b-256 |
d20ecc97e1b86173775f9e0c16778c125abf0b6b61296a44bfb560a497dabf28
|
File details
Details for the file restful_client_lite-0.0.5-py2.py3-none-any.whl
.
File metadata
- Download URL: restful_client_lite-0.0.5-py2.py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
ba479d1ef665eeb47d1c71510dd18245becc4c82a6d94736c632e0d308d35e83
|
|
MD5 |
8f90815d1bf7b3a3c279126abd6dc680
|
|
BLAKE2b-256 |
3b8ec1cde19b416c5692d06cb3cd6de5db1833c974a5504028f912731c592ef6
|