Skip to main content

Generic restful api -> Python function call adaptor

Project description

Shad
----

Small framework for building RESTful API wrappers.

Install
-------


Usage
-----

Define your base API class

from shad import BaseAPI, APIFunction, get_bind

class MyAPI(BaseAPI):
def __init__(self, api_key, base_url="http://example.com/"):
self.api_key = api_key
self.base_url = base_url

def update_parameters(self, params):
params["key"] = self.api_key
return params

`base_url` is required, and used by the method `get_base_url` to build the requests url. You can override `get_base_url` if you want to include variable constants in your base url in every request.

Next define your end points

bind = get_bind(MyAPI)

@bind
class mycall(APIFunction):
path = "accounts/login/"
method = "GET"

Then a user of your wrapper can do this:

api = MyAPI('THISISMYAPIKEY')
r = api.mycall(format='json')

By default, call return insteads of the Python requests libraries response objects, which you can call `.json` on to get back json if that is what you expect.

r.json
{'data':'awesome'}

This breaks the paradigm of just calling function and getting back a workable response, I need to change this such that we return an object which is by default the data in json form (or xml form), and you can also get the reponse back too.

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

shad-0.1.1.tar.gz (3.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page