Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time
from json import load
from urllib2 import urlopen
from urllib import urlencode
from pandas import DataFrame
def query(sql, format='df'):
Submit an `sql` query (string) to and return a pandas DataFrame.
For example::
print('Operating cash balances for May 22, 2013')
print(treasuryio.query('SELECT * FROM "t1" WHERE "date" = \'2013-05-22\';'))
Return a dict::
treasuryio.query('SELECT * FROM "t1" WHERE "date" = \'2013-05-22\';', format='dict')
url = ''
query_string = urlencode({'q':sql})
handle = urlopen(url + '?' + query_string)
if handle.code == 200:
d = load(handle)
if format == 'df':
return DataFrame(d)
elif format == 'dict':
return d
raise ValueError('format must equal "df" or "dict"')
raise ValueError(