restclient

a helper library to make writing REST clients in python extremely simple.

installation

if you have setuptools installed, just do "easy_install restclient"

documentation

restclient is very simple so the main documentation is in docstrings in the code itself. this page just serves as a quick starter.

from restclient import GET, POST, PUT, DELETE
r = GET("http://www.example.com/") # makes a GET request to the url. returns a string 
POST("http://www.example.com/") # makes a POST request
PUT("http://www.example.com/") # makes a PUT request
DELETE("http://www.example.com/") # makes a DELETE request
POST("http://www.example.com/",params={'foo' : 'bar'}) # passes params along
POST("http://www.example.com/",headers={'foo' : 'bar'}) # sends additional HTTP headers with the request
POST("http://www.example.com/",accept=['application/xml','text/plain']) # specify HTTP Accept: headers

restclient also handles multipart file uploads nicely:

f = open("foo.txt").read()
POST("http://www.example.com/",files={'file1' : {'file' : f, 'filename' : 'foo.txt'}})

by default, POST(), PUT(), and DELETE() make their requests asynchronously. IE, they spawn a new thread to do the request and return immediately. GET() is synchronous. You can change this behavior with the 'async' parameter:

POST("http://www.example.com/",async=False) # will wait for the request to complete before returning

doing an asynchronous GET would be silly and pointless so I won't give an example of that but I'm sure you could figure it out.

download

grab the egg from the cheeseshop.

credits

written by Anders Pearson at the Columbia Center For New Media Teaching And Learning.