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


Release history Release notifications

History Node

0.1.5

History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

This version
History Node

0.1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
shad-0.1.0-py2.7.egg (6.0 kB) Copy SHA256 hash SHA256 Egg 2.7 Feb 11, 2016
shad-0.1.0.tar.gz (3.2 kB) Copy SHA256 hash SHA256 Source None Mar 3, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page