Everything about SQLite

What is SQLite?

SQLite is a lightweight, serverless, self-contained, high-reliability, full-featured, SQL database engine. It is the most widely deployed database in the world, and is used in a wide variety of software applications, including web browsers, mobile apps, and embedded systems.

In last couple of years, SQLite has become a popular choice for mobile app developers due to its simplicity, reliability, and performance. It is also widely used in web development, data analysis, and other fields where a lightweight, easy-to-use database is needed.

How to use SQLite in python?

Python provides a built-in module called sqlite3 for working with SQLite databases. Here's an example of how to use this module to create a new SQLite database and insert some data into it:

import sqlite3

# Connect to the SQLite database (or create it if it doesn't exist)
conn = sqlite3.connect('example.db')

# Create a cursor object to interact with the database
cursor = conn.cursor()

# Create a table
cursor.execute('''
    CREATE TABLE IF NOT EXISTS users (
        id INTEGER PRIMARY KEY,
        name TEXT NOT NULL,
        age INTEGER NOT NULL
    )
''')

# Insert some data into the table
cursor.execute('''
    INSERT INTO users (name, age) VALUES ('Alice', 30)
''')

cursor.execute('''
    INSERT INTO users (name, age) VALUES ('Bob', 25)
''')

# Commit the changes
conn.commit()

# Retrieve and display the data
cursor.execute('SELECT * FROM users')
rows = cursor.fetchall()

for row in rows:
    print(row)

# Close the connection
conn.close()

Where to go next

FAQ