Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Python Fundamentals

Lesson 48 of 55 · Python

Database Access with SQLite

Duration: 20 minutes

Database Access with SQLite\n\nSQLite is a self‑contained, serverless SQL database that ships with Python—perfect for small to medium applications.\n\npython\nimport sqlite3\n\n# Connect (creates file if it doesn't exist)\nconn = sqlite3.connect('example.db')\ncur = conn.cursor()\n\n# Create a table\ncur.execute('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)')\n\n# Insert a row\ncur.execute('INSERT INTO users (name) VALUES (?)', ('Alice',))\nconn.commit()\n\n# Query all rows\ncur.execute('SELECT * FROM users')\nprint('Rows:', cur.fetchall())\n\nconn.close()\n\n\nFor larger projects you might prefer an ORM like SQLAlchemy to avoid raw SQL.\n

Previous: Building a Simple REST APINext: Introduction to Django