DEV Community

Cover image for Connect the DataBase | SQLite-Python Series
Deepak Raj
Deepak Raj

Posted on • Updated on

Connect the DataBase | SQLite-Python Series

The DataBasešŸ’¾ is one of the essential parts of the program, software, website, games. We'll discuss the SQLite Database in the SQLite-Python series. SQLite is one of the lightweight RDBMS. In this series, we'll use python to create/insert/delete data from SQLite.

Improvements are always welcome. Feel free to improve the article. So be Ready šŸ to dive-in the Series.

SQLite has the following noticeable features:

  • self-contained: SQLite is self-contained means it requires minimal support from the operating system or external library. This makes SQLite usable in any environment especially in embedded devices like iPhones, Android phones, game consoles, handheld media players, etc.

  • serverless: SQLite doesn't need the server architecture.

  • zero-configuration: Because of the serverless architecture, you donā€™t need to ā€œinstallā€ SQLite before using it. There is no server process that needs to be configured, started, and stopped.

  • transactional: All transactions in SQLite are fully ACID-compliant. It means all queries and changes are Atomic, Consistent, Isolated, and Durable.

You can download the SQLite from here

SQLite Module is already available in the python standard library since py2.5.

Create an SQLite Database with Python.

import sqlite3


def create_connection(db_file):
    """ create a database connection to a SQLite Database"""
    try:
        with sqlite3.connect(db_file):
            print("Sqlite version :", sqlite3.sqlite_version)
    except Exception as e:
        print(e)


if __name__ == "__main__":
    create_connection("database.db")

"""
:memory: to the connect() function of the sqlite3 module,
it will create a new database that resides in the memory (RAM)
instead of a database file on disk.
"""
Enter fullscreen mode Exit fullscreen mode

Thanks for reading the articles.
Join the open-source community on discord for Python & Machine learning.
Py-Contributors Discord Server

Top comments (2)

Collapse
 
phpcoder profile image
Slava Semushin • Edited

I'd like to mention that sqlite3.version represents a version of SQLite module rather than database version. In order to get a version of SQLite, we should use sqlite3.sqlite_version instead.

Collapse
 
codeperfectplus profile image
Deepak Raj

thanks, I updated it.