Database Access With Python

Learning PathSkills: SQL Libraries, SQLite, SQLAlchemy, Redis, MySQL, MongoDB, ChromaDB, Data Management, NoSQL Databases, Vector Databases, DuckDB, TinyDB, SQL Security

A person sitting on a chair and working on a computer that controls a large machine that is linked up to a big database

In this learning path, you will connect Python to a range of SQL and NoSQL database systems. You will write raw SQL queries, use SQLAlchemy as an ORM, and work with MySQL, MongoDB, and Redis. You will also explore DuckDB for analytical workloads, TinyDB for lightweight JSON storage, and ChromaDB for vector embeddings.

Database Access With Python

Learning Path ⋅ 9 Resources

Getting Started With Databases

You’ll start with the SQL databases you’re most likely to meet first. You’ll write raw SQL queries against SQLite, MySQL, and PostgreSQL, use SQLAlchemy as an ORM layer, and learn to parameterize queries so user input can’t rewrite them. Those safety habits carry into every database system that follows.

Title image for Introduction to Python SQL Libraries (Introduction to Python SQL Libraries)

Tutorial

Introduction to Python SQL Libraries

Learn how to connect to different database management systems by using various Python SQL libraries. You'll interact with SQLite, MySQL, and PostgreSQL databases and perform common database queries using a Python application.

Title image for SQLite and SQLAlchemy in Python: Move Your Data Beyond Flat Files (Data Management With Python, SQLite, and SQLAlchemy)

Course

SQLite and SQLAlchemy in Python: Move Your Data Beyond Flat Files

Learn how to store and retrieve data using Python, SQLite, and SQLAlchemy as well as with flat files. Using SQLite with Python brings with it the additional benefit of accessing data with SQL. By adding SQLAlchemy, you can work with data in terms of objects and methods.

Title image for Preventing SQL Injection Attacks With Python (Preventing SQL Injection Attacks With Python)

Tutorial

Preventing SQL Injection Attacks With Python

SQL injection attacks are one of the most common web application security risks. In this step-by-step tutorial, you'll learn how you can prevent Python SQL injection. You'll learn how to compose SQL queries with parameters, as well as how to safely execute those queries in your database.

Connecting to Specific Database Systems

You’ve worked with SQL through both raw queries and an ORM. Next, you’ll connect Python to three engines built on different models: MySQL for relational tables, MongoDB for JSON-like documents, and Redis for in-memory key-value storage. Working through them back to back shows you which kind of question each engine answers well.

Title image for MySQL Databases and Python (Python and MySQL Database: A Practical Introduction)

Course

MySQL Databases and Python

Learn how to connect your Python application with a MySQL database. You'll design a movie rating system and perform some common queries on it. You'll also see best practices and tips to prevent SQL injection attacks.

Title image for Python and MongoDB: Connecting to NoSQL Databases (Introduction to MongoDB and Python)

Tutorial

Python and MongoDB: Connecting to NoSQL Databases

Learn how to use Python to interface with the NoSQL database system MongoDB. You'll get an overview of the differences between SQL and NoSQL, and you'll also learn about related tools, including PyMongo and MongoEngine.

Title image for How to Use Redis With Python (How to Use Redis With Python)

Tutorial

How to Use Redis With Python

In this step-by-step tutorial, you'll cover how to use both Redis and its Python client library. You'll learn a bite-sized slice of Redis itself and master the redis-py client library.

Analytical and Lightweight Databases

MySQL, MongoDB, and Redis all run as separate servers you connect to. The two databases here run inside your own process instead. DuckDB gives you fast analytical queries over large local datasets, while TinyDB stores small collections as plain JSON, so you can reach for an embedded option when a server would be overkill.

Title image for Starting With DuckDB and Python (Introducing DuckDB)

Course

Starting With DuckDB and Python

Learn how to use DuckDB in Python to query large datasets with SQL or its Python API, handle files like Parquet or CSV, and integrate with pandas or Polars.

Title image for Introducing DuckDB (Introducing DuckDB)

Interactive Quiz

Introducing DuckDB

Title image for TinyDB: A Lightweight JSON Database for Small Projects (TinyDB: A Lightweight JSON Database for Small Projects)

Tutorial

TinyDB: A Lightweight JSON Database for Small Projects

If you're looking for a JSON document-oriented database that requires no configuration for your Python project, TinyDB could be exactly what you need.

Vector Databases and Embeddings

So far you’ve queried data by matching values. Here the question becomes similarity. You’ll turn text into embeddings and store them in ChromaDB, a vector database built for nearest-neighbor search, which is the storage layer behind semantic search and retrieval-augmented generation.

Title image for Vector Databases and Embeddings With ChromaDB (Embeddings and Vector Databases With ChromaDB)

Course

Vector Databases and Embeddings With ChromaDB

Learn how to use ChromaDB, an open-source vector database, to store embeddings and give context to large language models in Python.

Congratulations on completing this learning path! You now know how to connect Python to a variety of SQL and NoSQL databases, from SQLite and MySQL to MongoDB, Redis, DuckDB, TinyDB, and ChromaDB.

Continue your advanced Python journey with the next learning path:

Learning Path

Python Metaprogramming

8 Resources ⋅ Skills: Python, Descriptors, Metaclasses, Abstract Base Classes, Protocols, Duck Typing, Introspection, Dynamic Code Execution, exec(), eval()

You might also be interested in these related learning paths:

Got feedback on this learning path?

Looking for real-time conversation? Visit the Real Python Community Chat or join the next “Office Hours” Live Q&A Session. Happy Pythoning!

« Browse All Learning Paths