Using sqlalchemy

suggest change

To use sqlalchemy for database:

from sqlalchemy import create_engine
from sqlalchemy.engine.url import URL
url = URL(drivername='mysql',
          username='user',
          password='passwd',
          host='host',
          database='db')

engine = create_engine(url)  # sqlalchemy engine

Now this engine can be used, for example with pandas, to fetch dataframes directly from MySQL. URL(...) is the older constructor. Current SQLAlchemy uses URL.create(...). SQLAlchemy and pandas are not installed here, so this was not run.

import pandas as pd

con = engine.connect()
dataframe = pd.read_sql(sql=query, con=con)

query is not defined on this page.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents