Wednesday, December 17, 2014

Tortilla, a Python API wrapper

By Vasudev Ram

tortilla is a Python library for wrapping APIs. It's headline says "Wrapping web APIs made easy."

It can be installed with:
pip install tortilla
I tried it out, and slightly modified an example given in its documentation, to give this:
import tortilla
github = tortilla.wrap('')
user = github.users.get('redodo')
for key in user:
    print key, ":", user[key]
That code uses the Github API (wrapped by tortilla) to get the information for user redodo, who is the creator of tortilla.
Here is the output of running:
bio : None
site_admin : False
updated_at : 2014-12-17T16:39:55Z
gravatar_id : 
hireable : True
id : 2227416
followers_url :
following_url :{/other_user}
blog : 
followers : 6
location : Kingdom of the Netherlands
type : User
email :
public_repos : 9
events_url :{/privacy}
company : 
gists_url :{/gist_id}
html_url :
subscriptions_url :
received_events_url :
starred_url :{/owner}{/repo}
public_gists : 0
name : Hidde Bultsma
organizations_url :
url :
created_at : 2012-08-27T13:03:15Z
avatar_url :
repos_url :
following : 2
login : redodo
print type(user)
to the end of, shows that the user object is of type bunch.Bunch.

Bunch is a Python module providing "a dictionary that supports attribute-style access, a la JavaScript."

Did you know that tortillas are roughly similar to rotis?

- Vasudev Ram - Dancing Bison Enterprises

Signup for news about new products from me.

Contact Page

No comments: