Database Access With Python
Learning Path ⋅ Skills: SQL Libraries, SQLite, SQLAlchemy, Redis, MySQL, MongoDB, ChromaDB, Data Management, NoSQL Databases, Vector Databases, DuckDB, TinyDB, SQL Security
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.
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.
Interactive Quiz
Introduction to Python SQL Libraries
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.
Interactive Quiz
Data Management With Python, SQLite, and SQLAlchemy
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.
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.
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.
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.
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.
Interactive Quiz
Introducing DuckDB
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.
Interactive Quiz
TinyDB: A Lightweight JSON Database for Small Projects
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.
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.
Interactive Quiz
Embeddings and Vector Databases With ChromaDB
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!