Skip to content

Instantly share code, notes, and snippets.

@Tarliton
Last active February 26, 2023 12:58
Show Gist options
  • Save Tarliton/f4da871b13be8cb73c10f6ac1dae91e8 to your computer and use it in GitHub Desktop.
Save Tarliton/f4da871b13be8cb73c10f6ac1dae91e8 to your computer and use it in GitHub Desktop.
Quick sqlalchemy reflect whole database
from sqlalchemy import create_engine
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import sessionmaker
url = 'mysql://<user>:<password>@<ip>:<port>/<name>'
engine = create_engine(url, echo=True)
Base = automap_base()
Base.prepare(autoload_with=engine)
Session = sessionmaker(bind=engine)
session = Session()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment