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

This section covers the fundamentals of working with SQL databases in Python, from raw SQL queries to using an ORM layer with SQLAlchemy.

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

Learn how to connect Python to specific database engines. You will work with MySQL, MongoDB, and Redis, covering connection setup, queries, and common patterns for each system.

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

Explore databases designed for analytical workloads and small projects. DuckDB handles large-scale data analysis, while TinyDB provides a simple JSON-based store for lightweight applications.

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

Learn how to store and query vector embeddings using ChromaDB, a common building block for AI-powered search and retrieval-augmented generation (RAG) applications.

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

Tutorial

Embeddings and Vector Databases With ChromaDB

Vector databases are a crucial component of many NLP applications. This tutorial will give you hands-on experience with ChromaDB, an open-source vector database that's quickly gaining traction. Along the way, you'll learn what's needed to understand vector databases with practical examples.

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

4 Resources ⋅ Skills: Python, Metaclasses, Descriptors, 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