Skip to main content

This module makes writing client API for REST services as easy as GET('my_api/{some_param}')

Project description

prest documentation

Writing python API for REST service is a quite boring task.
prest is intended to do all monkey work for you. Take
a look at example:

from prest import EasyRestBase, GET, POST, DELETE

class MyRestfullAPI(EasyRestBase):
list_objs = GET('objects')
get_obj = GET('objects/{0}')
del_obj = DELETE('objects/{0}')
create_obj = POST('objects')
select_objs = GET('objects/filter')
objs_by_type = GET('objects/{type}')

conn = MyRestfullAPI("")

print conn.list_objs()

obj_id = conn.create_obj()['id']

There 6 basic functions for http methods:
requires relative path and returns function. This
function, in its turn, gets connection and a set of
parameters, insert some of them in url (if there a placeholders),
attach all the rest as GET/POST parameters and make
a http request. Receive a result, unpack it and return.

So you need only one line to make an API func for
each REST call.

In case if result of GET/... calls is assigned to
class method of class inherited from PRestBase
then call gets connection from self.

Meanwhile you can use it separately:

from prest import GET, Urllib2HTTP_JSON

get_cluster_data = GET('data/{cluster_id}')
conn = Urllib2HTTP_JSON("")
print get_cluster_data(conn, cluster_id=11)

Both Urllib2HTTP_JSON and PRestBase
accepts dictionary of additional headers end echo
parameters. Urllib2HTTP_JSON uses json.dumps and
json.loads to serialize and deserialize data accordingly.

There also an object-oriented API - please take
a look on I wrote no documentation
for it, as it currently breaks 17th rule of python Zen.

Project details

Download files

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

Files for prest, version 0.1
Filename, size File type Python version Upload date Hashes
Filename, size prest-0.1.tar.gz (6.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page