Write quickly and easily HTTP API clients.
pip install apize
from apize.apize import Apize
Accept 3 args:
- api_url (str) : your url base (ex: https://myapi.com/api)
- headers (dict) : http headers (for any API requests)
- verify_cert (bool or str) : disable SSL cert verification or get certfile path. (default True)
from apize.apize import Apize
app = Apize('https://myapi.com/api')
## With auto-signed ssl cert and allowed verification.
app_https = Apize('https://myapi.com/api', verify_cert='/path/to/certfile')
Accept 2 args:
- path (str) : requests path (ex: /foo/bar/)
- method (str) : http method (default: GET)
Your function must be decorated by call method and must be return a dict.
Dict may contain 8 elements:
- data (dict or str) : body request
- args (dict) : args to parse url (ex: /foo/:bar/)
- params (dict) : params in url (ex: ?id=12)
- headers (dict) : override Apize.headers for special case
- cookies (dict) : http cookies
- timout (int) : set a timeout for request (default: 8 seconds)
- is_json (bool) : define if data args must be parsed in json.
- verify_cert (bool or str) : override Apize.verify_cert for special case
from apize.apize import Apize
app = Apize('https://myapi.com/api')
@app.call('/maps/:lat/:long/')
def get_map(key, zoom)
args = {'lat': '47.331881', 'long': '5.032221'}
params = {'zoom': 12}
## Final url :
## https://myapi.com/api/maps/47.331881/5.032221,12/?zoom=12
return {'args': args, 'params': params}
from apize.decorators import apize_raw
Use apize_raw decorator (same as call decorator but without Apize object).
from apize.decorators import apize_raw
@apize_raw('https://myapi.com/api/maps/:lat/:long/')
def get_map(key, zoom)
args = {'lat': '47.331881', 'long': '5.032221'}
params = {'zoom': 12}
## Final url :
## https://myapi.com/api/maps/47.331881/5.032221,12/?zoom=12
return {'args': args, 'params': params}
more examples in examples/ directory.