DEV Community

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

Posted on • Edited on

3 2

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

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

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.

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay