A simple REST client for Python.
Install Crest
with pip
:
$ pip install python-crest
Install development version from GitHub
:
$ git clone https://github.com/RussellLuo/crest.git
$ cd crest
$ python setup.py install
Create an API resource:
from crest import Resource
# a simple API
api = Resource('http://example.com/api')
# an API required authentication
api = Resource('http://example.com/api', auth=('username', 'password'))
# GET http://example.com/api
api.get()
Get a resource within the API:
users = api.users
# GET http://example.com/api/users
users.get()
# GET http://example.com/api/users?name=russell
users.get(params={'name': 'russell'})
# POST http://example.com/api/users (payload: {"name": "russell"})
users.post(json={'name': 'russell'})
# GET http://example.com/api/users/1
users[1].get()
# PATCH http://example.com/api/users/1 (payload: {"name": "russell"})
users[1].patch(json={'name': 'russell'})
Get a sub resource of users
:
operations = users[1].operations
# GET http://example.com/api/users/1/operations
operations.get()
# GET http://example.com/api/users/1/operations/1
operations[1].get()
Crest
is based on kennethreitz's requests, and is inspired by adnam's resources. Thank you guys!