{
  "id": 19978589,
  "title": "📝 How to Use SQLite in Python (Without Installing a Database Server)",
  "url": "https://urgent.news/2026/11/14/how-to-use-sqlite-in-python-without-installing-a-database-server",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-14T12:38:53.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/ezenwa_christian_5243b406/how-to-use-sqlite-in-python-without-installing-a-database-server-17g9"
  },
  "original_language": "en",
  "account": "Developers often associate databases with heavy-duty options like PostgreSQL, MySQL, or MongoDB. They envision servers, ports, and intricate setups. However, when crafting a lightweight application, a local script, or an AI tool on resource-restricted hardware such as an Android phone via Termux, there is no need for a database server. SQLite suffices.\n\nSQLite is a C library that offers a lightweight, disk-based database. It does not require a separate server process and allows interaction via a nonstandard SQL variant. The best part? It is integrated into Python. Here is how to utilize it within 30 seconds.\n\nFirstly, the built-in module. The sqlite3 library is part of Python's Standard Library, so there is no need for additional installation. Simply import it using `import sqlite3`.\n\nSecondly, connecting to the database and creating a table. Upon attempting to connect to a database file, SQLite automatically generates it if it does not exist. To create a table named \"users\" with fields for id, name, and email, execute the following command:\n\n```\nconn = sqlite3.connect('app.db')\ncursor = conn.cursor()\ncursor.execute('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, email TEXT NOT NULL UNIQUE)')\nconn.commit()\n```\n\nThirdly, insert data securely. Do not use f-strings for inserting data into SQL as they expose your application to SQL injection attacks. Instead, utilize the '?' placeholder. To add a new user, utilize the following command:\n\n```\ncursor.execute('INSERT INTO users (name, email) VALUES (?, ?)', ('Ezenwa', 'ezenwa@example.com'))\nconn.commit()\n```\n\nNext, fetching data. After saving data, query it using `fetchall()` or `fetchone()`. Retrieve all rows from the \"users\" table using the following command:\n\n```\ncursor.execute('SELECT id, name, email FROM users')\nrows = cursor.fetchall()\nfor row in rows:\nprint(row)\n```\n\nLastly, always remember to close the connection when your script is complete to conserve system resources. Close the connection using the command `conn.close()`.\n\nWhy choose SQLite? If you are developing a mobile application, a command-line tool, or an AI script running on a local machine, SQLite is an excellent choice. It is zero-configuration, extremely fast for local data, and does not consume the memory that a comprehensive database server like PostgreSQL would. Have you integrated SQLite into your Python projects? Share your experiences below!",
  "summary": "When developers think of databases, they usually think of PostgreSQL, MySQL, or MongoDB. They think of servers, ports, and complex installations. But if you are building a lightweight app, a local script, or an AI tool on constrained hardware (like an Android phone via Termux), you don't need a database server. You need SQLite. SQLite is a C library that provides a lightweight disk-based…",
  "key_points": [
    "SQLite is a lightweight, disk-based database library in Python's Standard Library",
    "Connect to database file automatically creates it if it doesn't exist",
    "Use placeholders to prevent SQL injection when inserting data"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}