The cartodb-python project is a Python client for the CartoDB SQL API that supports authentication using OAuth.
You can install cartodb-python by cloning this repository or by using Pip, a Python package installer similar to easy_install.
pip install cartodbor if you want to use the development version
pip install -e git+git://github.com/javisantana/cartodb-python.git#egg=cartodbNote that cartodb-python depends on the ouath2 module
pip install oauth2and if you're running python < 2.6 you need to install simplejson
pip install simplejsonThe following example requires your CartoDB API consmer key and consumer secret. Refer to the CartoDB Authentication documentation for details.
from cartodb import CartoDB, CartoDBException
user = 'me@mail.com'
password = 'secret'
CONSUMER_KEY='YOUR_CARTODB_CONSUMER_KEY'
CONSUMER_SECRET='YOUR_CARTODB_CONSUMER_SECRET'
cartodb_domain = 'YOUR_CARTODB_DOMAIN'
cl = CartoDB(CONSUMER_KEY, CONSUMER_SECRET, user, password, cartodb_domain)
try:
print cl.sql('select * from mytable')
except CartoDBException as e:
print ("some error ocurred", e)