Skip to content

Instantly share code, notes, and snippets.

@stuartlynn
Created August 3, 2017 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuartlynn/8788f628c85d30ccbaa20cba3e6b3f4b to your computer and use it in GitHub Desktop.
Save stuartlynn/8788f628c85d30ccbaa20cba3e6b3f4b to your computer and use it in GitHub Desktop.
CartoQuery
# Run a query over the CARTO SQL api
def carto_query(query,username,api_key):
params = {'q' : query, 'format':'csv'}
if api_key:
params['api_key'] = api_key
url = 'https://{}.carto.com/api/v2/sql?'.format(username) + urlencode(params)
return pandas.read_csv(url)
# Take a matplotlib figure and turn it in to a response from the server
def mpl2img(fig):
canvas = FigureCanvas(fig)
img = StringIO()
canvas.print_png(img)
res = make_response(img.getvalue())
res.headers['Content-Type'] = 'image/png'
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment