import pyodbc server = 'tcp:myserver.database.windows.net' database = 'mydb' username = 'myusername' password = 'mypassword' #Connection String cnxn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password) cursor = cnxn.cursor() #Sample select query cursor.execute("SELECT @@version;") row = cursor.fetchone() while row: print row[0] row = cursor.fetchone() #Sample insert query cursor.execute("INSERT SalesLT.Product (Name, ProductNumber, StandardCost, ListPrice, SellStartDate) OUTPUT INSERTED.ProductID VALUES ('SQL Server Express New 20', 'SQLEXPRESS New 20', 0, 0, CURRENT_TIMESTAMP )") row = cursor.fetchone() while row: print 'Inserted Product key is ' + str(row[0]) row = cursor.fetchone()