I am trying to write a generic database connector class in python. For this I want to first check what drivers are installed on the machine and throw an error if the required drivers are missing in the machine.
Is there a way to do this in python?
Open the Windows Control Panel. Open the Administrative Tools folder. Double-click Data Sources (ODBC) to open the ODBC Data Source Administrator window. Click the Drivers tab and locate the SQL Server entry in the list of ODBC drivers to confirm that the driver is installed on your system.
pyodbc is an open source Python module that provides access to ODBC databases. pyodbc implements the Python DB API 2.0 specification. The Python DB API defines a database-neutral interface to data stored in relational databases.
pyodbc
has a method which returns a list of installed ODBC drivers. Granted, it's just a list of the driver names, so it's a bit fiddly getting to the most current driver, but hopefully this will help.
I use regex (via the built-in re
module) to filter down to the driver I need.
import pyodbc
pyodbc.drivers()
The output provides a list of installed ODBC drivers.
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