1import pyodbc
2server = '<server>.database.windows.net'
3database = '<database>'
4username = '<username>'
5password = '<password>'
6driver= '{ODBC Driver 17 for SQL Server}'
7
8with pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT=1433;DATABASE='+database+';UID='+username+';PWD='+ password) as conn:
9 with conn.cursor() as cursor:
10 # code...
11 # ex: cursor.execute("SELECT TOP 3 name, collation_name FROM sys.databases")
12