This release is a pre-release and may not be stable for production use.
What
apap makes you can ap ply RESTful ap i to your client handy.
Required
python3.7+
About
This exposes apap.Client class to define your api client. apap.Client must be defining api_base_url and _method_map as class attribute.
import apap
class YourAPI(apap.Client):
api_base_url = 'https://your.api.com/v1'
_method_map = apap.MethodMap(
('get_all', apap.Method.Get, 'things'), # all resources from GET http method.
('get_one', apap.Method.Get, 'things/:id'), # one of resources filterd by id from GET http method.
('create', apap.Method.Post, 'things'), # create a new item from POST http method.
('update', apap.Method.Put, 'things/:id'), # update something filterd by id from PUT http method.
('delete', apap.Method.Delete, 'things/:id'), # delete something filterd by id from Delete http method.
)
...
You know apap.MethodMap makes your client declarative.
apap.MethodMap is just a tuple of client method name, HTTP method and endpoint url.
At last, you need to register your client to entrypoint via apap.apply.
Those request returns requests’s Response object (because apap uses requests internally).
import apap
client = apap.apply(YourAPI)()
client.get_all() # same as `curl https://your.api.com/v1/things`
client.get_one(id=1)() # same as `curl https://your.api.com/things/1`
client.create(x=1, y=2) # same as `curl -X POST -d "x=1" -d "y=2" https://your.api.com/things`
client.update(id=1)(x=10) # same as `curl -X PUT -d "x=1" https://your.api.com/things/1`
client.delete(id=1)() # same as `curl -X DELETE https://your.api.com/things/1`
When you need to set any headers for requesting, you can use header_map attribute to translate actual header from python world.
So if you want to use Authorization as http-header, please define header_map looks like below.
class YourAPI(apap.Client):
header_map = {'Authorization': 'auth_key'}
...
apap.apply(YourAPI)(headers={'auth_key': 'token xxxxx'})
Example
All you need is just creating a class which inherits apap.Client class.
import os
from apap import MethodMap, Client, Method, apply
class GithubAPI(Client):
api_base_url = 'https://api.github.com'
header_map = {'Authorization': 'access_token'}
class UserRepo(GithubAPI):
name = 'user_repo'
_method_map = MethodMap(
('get', Method.Get, 'users/:username/repos'),
)
class MyRepo(GithubAPI):
name = 'my_repo'
_method_map = MethodMap(
('get', Method.Get, 'user/repos'),
)
access_token = os.environ['ACCESS_TOKEN']
endpoints = [UserRepo, MyRepo]
gh_client = apply(*endpoints)(headers={'access_token': f'token {access_token}'})
user_repo_resp = gh_client.user_repo.get(username='mtwtkman')()
my_repo_resp = gh_client.my_repo.get(visibility='private')
Metadata
Release files for apap 0.0.0b3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| apap-0.0.0b3.tar.gz | 4.7 kB | Without provenance | Details for apap-0.0.0b3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| apap-0.0.0b3-py3-none-any.whl | Python 3 | none | any | Details for apap-0.0.0b3-py3-none-any.whl |
Total release size: 9.2 kB
Release files / apap-0.0.0b3.tar.gz
| Download URL | apap-0.0.0b3.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
49940eba4356bec46ef9089e689f06fddc1ce9cf25269ab0001640cc16c1d343
|
|
BLAKE2b-256 checksum How to use checksums |
09c93fb5d34d90ba7deed847ebddd3ba272562dbc7f80d5ec2cf5b20217e1fa6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.17 CPython/3.7.4 Linux/4.19.57-microsoft-standard
|
Release files / apap-0.0.0b3-py3-none-any.whl
| Download URL | apap-0.0.0b3-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dc59a433d42a7e473c3dea06f042c1af23d27bbf67f961db18c28c619ac14839
|
|
BLAKE2b-256 checksum How to use checksums |
b6a17b75e1120f8b128f3d521349f5b9bc7dddf81abd33622055e426b7bce934
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.17 CPython/3.7.4 Linux/4.19.57-microsoft-standard
|
Security for apap 0.0.0b3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.