Python Tutorial

Step-by-Step Connecting SQLite Database in Python

How to Connect to SQLite Database in Python?

The Python code below demonstrates how to connect to an existing database. If the database does not already exist, it will be built before a database object is returned.


import sqlite3

conn = sqlite3.connect('test.db')

print "Opened database successfully";

To build a database in RAM, you can also specify database name as the special name:memory:. Let's now use the aforementioned command to create the database test.db in the current directory. 

You have the option to adjust your course based on your needs. Keep the above code in the file and run it like this: If the database is successfully built, the following message will appear.

$chmod +x


Open database successfully

Did you find this article helpful?