Skip to content

Instantly share code, notes, and snippets.

@peterkeen
Created June 14, 2011 15:59
Show Gist options
  • Save peterkeen/1025209 to your computer and use it in GitHub Desktop.
Save peterkeen/1025209 to your computer and use it in GitHub Desktop.
SQLAlchemy Session from DBAPI Connection
def session_from_connection(conn):
def passthrough_conn():
return conn
# note that the url here doesn't matter, but it has to parse correctly as a url
engine = create_engine('postgresql://foo@bar/abc', creator=passthrough_conn)
session = Session(bind=engine)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment