Versions

Description

Devourer is a generic API client. It features an object-oriented, declarative approach to simplify the communication. It depends on the brilliant requests package as the gateway to API server. A simple example: >>> from devourer import GenericAPI, APIMethod, APIError >>> >>> >>> class TestApi(GenericAPI): >>> posts = APIMethod('get', 'posts/') >>> comments = APIMethod('get', 'posts/{id}/comments') >>> post = APIMethod('get', 'posts/{id}/') >>> add_post = APIMethod('post', 'posts/') >>> >>> def __init__(self): >>> params = ('http://jsonplaceholder.typicode.com/', >>> None, # this can be ('user', 'password') >>> # or requests auth object >>> load_json=True, >>> throw_on_error=True) >>> super(TestApi, self).__init__(*params) >>> >>> api = TestApi() >>> posts = api.posts() >>> post = api.post(id=posts[0]['id']) >>> comments = api.comments(id=post['id']) >>> new_post_id = api.add_post(userId=1, >>> title='Breaking news', >>> body='I just got devoured.') >>> try: >>> post = api.post(id=new_post_id) >>> except APIError: >>> print('Oops, this API is not persistent!') The init function gives details so you don't need to repeat them elsewhere, enables parsing json responses and raising exceptions on error. You can also obtain raw string with `load_json=False` and silence errors getting None instead when they happen with `throw_on_error=False`.

Repository

https://github.com/bonnierpolska/devourer

Project Slug

devourer

Last Built

5 years, 3 months ago passed

Maintainers

Home Page

https://github.com/bonnierpolska/devourer

Badge

Tags

Project has no tags.

Short URLs

devourer.readthedocs.io
devourer.rtfd.io

Default Version

latest

'latest' Version

master