SQLite is a small C library that implements a self-contained SQL database engine. This article examines pysqlite, one of a number of libraries in Python, that is used as an interface with SQLite.
Now we're ready to begin working with pysqlite. To start using the library, it, of course, needs to be imported. It can be found under the name of pysqlite2, but we'll need the dbapi2 submodule. This should be imported under the name of sqlite for clarity:
>>> from pysqlite2 import dbapi2 as sqlite
Now we can begin using pysqlite. The first thing we'll do is create a new database to work with. This is done by creating a connection object and passing the name of a database file. If the database file does not exist, which, in our case, it doesn't, then it will be created. If it does exist, then it will be opened:
>>> connection = sqlite.connect('test.db')
It's also possible to create a temporary database that exists in memory:
>>> memoryConnection = sqlite.connect(':memory:')
Once we have a connection object, we must create a cursor object, which does the interaction for us. This is done by calling the cursor method of our connection object: