Reputation: 91
So I am doing a assignment which is to connect to a database and do operations on it. For that I have chosen sqlite3 and for connecting to the database I found the ODBC driver for python is pyodbc.
My questions are, what is the difference between using pyodbc and doing it using the library sqlite3, i.e., import sqlite3
? And is the pyodbc driver integrated in sqlite3?
Upvotes: 1
Views: 1941
Reputation: 123654
The big advantage of using Python's built-in sqlite3
module is that it is built-in; there are no other dependencies. If your app uses pyodbc and SQLite ODBC then both of those external components must be available for the application to function.
If this is a personal project then you can obviously install what is necessary, but if this is ever going to be widely deployed then you will need to deal with the additional requirements if you choose pyodbc. Specifically, your [Python] app can register a dependency on pyodbc such that pip install your_app
also installs pyodbc, but it cannot (practically) accommodate the requirement for the SQLite ODBC driver automatically so your installation instructions will need to address that.
And is the pyodbc driver integrated in sqlite3?
No. The SQLite ODBC driver is completely separate from both Python [sqlite3] and pyodbc.
Upvotes: 0
Reputation: 11209
pyodbc is an API that allows you to interact with any database that provides provides a odbc driver for it's database. If you use the SQLite library directly and one day want to switch to another database, you will have to revise your code to either use pyodbc or the database specific API for the database you are migrating to.
You can alternatively connect to SQLite using pyodbc by using the SQLite pyodbc driver. See response here: Connect to SQLite3 server using PyODBC, Python
Upvotes: 1