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

笑着哭i 提交于 2020-02-03 08:25:06

问题


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?


回答1:


This works quite well for me:

    log.info("* Using DB: %s" % (engine.url))



回答2:


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



来源:https://stackoverflow.com/questions/38631210/how-can-i-get-a-connection-url-from-an-sqlalchemy-engine-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!