Search code examples
sqlalchemyconnection-string

How can I get a connection URL from an SQLAlchemy Engine instance?


I begin a program by generating a URL object and passing it to create_engine. In a section of code far, far away I would like to find out what this engine is connected to, i.e. the connection URL.

Is there an easy way to do this? Using inspect I can only see how to get the driver type. I can understand if the password component of a connection string was no longer available, but I'm hoping everything else is still available.

Any ideas?


Solution

  • The Engine class has an attribute url. Although not documented, it is not 'underscore hidden' so I would assume safe to read.