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:
# test_tortilla.py
import tortilla
github = tortilla.wrap('https://api.github.com')
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:
python test_tortilla.py
bio : None
site_admin : False
updated_at : 2014-12-17T16:39:55Z
gravatar_id : 
hireable : True
id : 2227416
followers_url : https://api.github.com/users/redodo/followers
following_url : https://api.github.com/users/redodo/following{/other_user}
blog : 
followers : 6
location : Kingdom of the Netherlands
type : User
email : dodo@gododo.co
public_repos : 9
events_url : https://api.github.com/users/redodo/events{/privacy}
company : 
gists_url : https://api.github.com/users/redodo/gists{/gist_id}
html_url : https://github.com/redodo
subscriptions_url : https://api.github.com/users/redodo/subscriptions
received_events_url : https://api.github.com/users/redodo/received_events
starred_url : https://api.github.com/users/redodo/starred{/owner}{/repo}
public_gists : 0
name : Hidde Bultsma
organizations_url : https://api.github.com/users/redodo/orgs
url : https://api.github.com/users/redodo
created_at : 2012-08-27T13:03:15Z
avatar_url : https://avatars.githubusercontent.com/u/2227416?v=3
repos_url : https://api.github.com/users/redodo/repos
following : 2
login : redodo
Adding:
print type(user)
to the end of test_tortilla.py, 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: