Forked from timmyreilly/ConnectingToAzureSQLFromPython
Created
April 20, 2021 22:04
-
-
Save chadmando/ac6f18d605671d22f8563ab8c8d8dea4 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