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?
class sqlalchemy.engine. URL(*arg, **kw) Represent the components of a URL used to connect to a database. This object is suitable to be passed directly to a create_engine() call. The fields of the URL are parsed from a string by the make_url() function.
This works quite well for me:
log.info("* Using DB: %s" % (engine.url))
The Engine class has an attribute url
. Although not documented, it is not 'underscore hidden' so I would assume safe to read.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With