Skip to content

Instantly share code, notes, and snippets.

@JaimeEnergy
Created April 14, 2017 08:45
Show Gist options
  • Save JaimeEnergy/4dc8e4151139a9d601efb3e46a1e80d6 to your computer and use it in GitHub Desktop.
Save JaimeEnergy/4dc8e4151139a9d601efb3e46a1e80d6 to your computer and use it in GitHub Desktop.
Connect to SQL Server, Postgres, and SQLite3 in Python
import pypyodbc
import pandas as pd
CONNECTION_STRING = """
Driver={{{DRIVER}}};
Server={SERVER};
Database={DATABASE};
""".format(**locals())
df = pd.read_sql(con=pypyodbc.connect(CONNECTION_STRING), sql=sql)
# optional http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_sql.html
# index_col: str or list of str -> to set index
# columns: str or list of str -> to restrict columns selected
# chunksize: int -> stream a large table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment