Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: accept sqlalchemy style connection URI #1391

Open
epa opened this issue Dec 10, 2024 · 0 comments
Open

Feature: accept sqlalchemy style connection URI #1391

epa opened this issue Dec 10, 2024 · 0 comments

Comments

@epa
Copy link

epa commented Dec 10, 2024

I understand that pyodbc uses a connection string looking like

DRIVER={ODBC Driver 18 for SQL Server};SERVER=myserver;DATABASE=mydb;UID=scott;PWD=tiger

But sqlalchemy has popularized its own URI scheme for database connections, something like

mssql+pyodbc://scott:tiger@myserver/mydb?driver=ODBC+Driver+18+for+SQL+Server

Of course, sqlalchemy is here acting as a layer on top of pyodbc. Sometimes I'd like to write using the pure pyodbc interface, but I have only a connection string in sqlalchemy format. Purely as a convenience, it would be great if pyodbc accepted the alternative format. Something like

cnxn = pyodbc.connect('mssql+pyodbc://scott:tiger@myserver/mydb?driver=ODBC+Driver+18+for+SQL+Server')
    # works
cnxn = pyodbc.connect('postgresql+psycopg2://scott:tiger@myserver/mydb')
    # Error: this looks like a URI but the URI scheme postgresql+psycopg2 is not handled.  Only URI schemes ending in +pyodbc are handled.

I understand that you don't want to get bogged down in handling all the weird options that sqlalchemy might accept in its connection string, nor in elaborately reproducing its behaviour. So this is kind of a best effort basis for the most common, vanilla URIs that use pyodbc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant