Search code examples
pythonpysqlite

'from sqlite3 import dbapi2 as sqlite3' vs 'import sqlite3'?


When I see the examples for pysqlite, there are two use cases for the SQLite library.

from sqlite3 import dbapi2 as sqlite3

and

import sqlite3

Why there are two ways to support the sqlite3 api? What's the difference between the two? Are they the same? In normal use, which would be preferred.

ADDED

I knew that they are different in terms of namespace, and I wanted ask if they are the same in terms of usage, I mean, do they have the same API set?


Solution

  • They are the same. In the Lib/ directory of my Python installation (v2.6), the sqlite3 package contains a __init__.py file with this:

    from dbapi2 import *
    

    Which means that the two ways of importing are absolutely identical.

    That said, I definitely recommend just using import sqlite3 - as this is the documented approach.