Skip to content

Instantly share code, notes, and snippets.

@jonaslindmark
Created January 5, 2014 12:18
Show Gist options
  • Save jonaslindmark/8267555 to your computer and use it in GitHub Desktop.
Save jonaslindmark/8267555 to your computer and use it in GitHub Desktop.
from flask import Flask
from sqlalchemy import create_engine
import json
app = Flask("jsonapi")
engine = create_engine('mysql://root:@localhost:3306/testdb')
@app.route("/")
def item():
result = engine.execute("select * from lookups").fetchall()
d = {"result": [{"id": id, "val": val} for (id,val) in result]}
return json.dumps(d)
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment