Created
October 13, 2017 23:02
-
-
Save timmyreilly/f4a351eda5dd45aa9d56411d27573d7c to your computer and use it in GitHub Desktop.
Using Flask_SQLAlchemy to connect to Azure SQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import urllib.parse | |
from flask import Flask | |
from flask_sqlalchemy import SQLAlchemy | |
# Configure Database URI: | |
params = urllib.parse.quote_plus("DRIVER={SQL Server};SERVER=sqlhost.database.windows.net;DATABASE=pythonSQL;UID=username@sqldb;PWD=password56789") | |
# initialization | |
app = Flask(__name__) | |
app.config['SECRET_KEY'] = 'supersecret' | |
app.config['SQLALCHEMY_DATABASE_URI'] = "mssql+pyodbc:///?odbc_connect=%s" % params | |
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True | |
# extensions | |
db = SQLAlchemy(app) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! I'll have to give that a try.