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.2.tar.gz (3.2 kB view details)

Uploaded Source

File details

Details for the file shad-0.1.2.tar.gz.

File metadata

  • Download URL: shad-0.1.2.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for shad-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8f2fb1b27a3c23ae01f204757c96cca6aa054b55193ac1fac1988afc6e0c5325
MD5 89a470f4b6babc9c223a103328eae91d
BLAKE2b-256 cc39143fcdcdb1331b33741968a2ed2580a39fab3a099d56c7ec62a6bc73e814

See more details on using hashes here.

Supported by

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