Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

SQLite and SQLAlchemy in Python (Overview)

All programs process data in one form or another, and many need to be able to save and retrieve that data from one invocation to the next. Python, SQLite, and SQLAlchemy give your programs database functionality, allowing you to store data in a single file without the need for a database server.

You can achieve similar results using flat files in any number of formats, including CSV, JSON, XML, and even custom formats. Flat files are often human-readable text files—though they can also be binary data—with a structure that can be parsed by a computer program. You’ll explore using SQL databases and flat files for data storage and manipulation and learn how to decide which approach is right for your program.

In this video course, you’ll learn how to use:

  • Flat files for data storage
  • SQL to improve access to persistent data
  • SQLite for data storage
  • SQLAlchemy to work with data as Python objects

Sample Code (.zip)

10.7 KB

Course Slides (.pdf)

1.3 MB

00:00 Welcome to Data Management with Python and SQLAlchemy. My name is Christopher, and I will be your guide. This course is all about interacting with databases in Python through the third party library SQLAlchemy.

00:14 In this course, you’ll learn about SQL, also known as sequel, the language used to interact with most relational databases, and then dive into SQLAlchemy, a library for using SQL concepts in Python.

00:28 SQLAlchemy breaks down into two parts: core, which allows you to write SQL statements directly or use functions to do the same, and the second part, the ORM, an object-relational mapping implementation that lets you treat rows in a database as objects.

00:48 The code in this course was tested using Python 3.10, SQLAlchemy 1.4.36, and SQLite 3.37.0. SQLAlchemy is undergoing revisions heading to a new way of doing things in its 2.0 form, which at the time of recording was still in beta.

01:05 Luckily, 1.4 is pretty close to the 2.0 concepts, so you’re future-proofed. But you definitely don’t want to be following along with 1.3 or earlier. There are some big differences.

01:19 What is software besides a set of rules for manipulating data? And oftentimes you want that data to persist between execution of your program or to be passed between programs. You may have used a text file, also known as a flat file data representation for storing data.

01:36 These can be useful but often have limitations. A database provides a more robust way of representing data objects and their interrelations. There are actually different kinds of databases, but the most common is what is called a relational database.

01:52 If someone just says database to you, they probably mean the relational kind. Most relational databases support the structured query language or a dialect of it for managing the contents of that database.

02:06 SQLite is a popular self-contained, single-file database engine. One of the beauties of it, especially if you’re just learning databases, is that it doesn’t require a server.

02:16 It has all the power of a database, except it’s local to your file system.

02:22 And seeing as you’re here at Real Python, the question probably is: Great, but how do I use it with Python? Yep. Well, there are actually many libraries that can help you interact with databases.

02:33 I’ll be covering SQLAlchemy, a third-party library with several different styles of interaction.

02:40 Next up, I’ll introduce you to data storage through the use of CSV files. Got to walk before you can run.

Become a Member to join the conversation.