10/10/25, 4:29 PM Python Database Tutorial - GeeksforGeeks
Search... Sign In
Python Database Python MySQL Python SQLite Python MongoDB PostgreSQL SQLAlchemy
Python Database Tutorial
Last Updated : 23 Jul, 2025
Python being a high-level language provides support for various
databases. We can connect and run queries for a particular database
using Python and without writing raw queries in the terminal or shell
of that particular database, we just need to have that database
installed in our system.
1/3
A database is an organized collection of data stored electronically. It is
managed by a Database Management System (DBMS) that allows
users to access, update, and manage data efficiently. Databases are
primarily categorized into two types:
1. Relational Databases (RDBMS)
Store data in structured tables with rows and columns. They support
relationships between data entities. Examples:
MySQL
PostgreSQL
SQLite
https://www.geeksforgeeks.org/python/python-database-tutorial/ 1/7
10/10/25, 4:29 PM Python Database Tutorial - GeeksforGeeks
2. Non-relational Databases (NoSQL)
Store data in various formats like documents, key-value pairs, or
graphs, offering more flexibility. For Examples:
MongoDB
Cassandra
In this tutorial, we will focus on how to use Python with the most
commonly used databases: MySQL, SQLite, and MongoDB. We will
cover how to connect to these databases, run queries, and manage
data efficiently using Python. Additionally, we will explore how to
work with JSON data in Python.
Python MySQL
Python MySQL Connector is a Python driver that helps to integrate
Python and MySQL. This Python MySQL library allows the conversion
between Python and MySQL data types. MySQL Connector API is
implemented using pure Python and does not require any third-party
library.
MySQL Basics
Install Python MySQL connector
Connect MySQL database using MySQL-Connector Python
Python MySQL Queries
Create Database
Create Table
Insert into Table
Select Query
Where Clause
Order By Clause
Delete Query
Drop Table
https://www.geeksforgeeks.org/python/python-database-tutorial/ 2/7
10/10/25, 4:29 PM Python Database Tutorial - GeeksforGeeks
Update Query
Limit Clause
Join
Commit & RollBack Operation in Python
Note: For more information, refer to our detailed Python MySQL
Tutorial
Python SQLite
Python SQLite3 module is used to integrate the SQLite database with
Python. It is a standardized Python DBI API 2.0 and provides a
straightforward and simple-to-use interface for interacting with
SQLite databases. There is no need to install this module separately
as it comes along with Python after the 2.5x version.
SQLite Basics
Introduction
Python SQLite – Connecting to Database
SQLite Datatypes and its Corresponding Python Types
Python SQLite Queries
Cursor Object
Create Table
Insert Data
Select Data from Table
WHERE Clause
ORDER BY Clause
LIMIT Clause
JOIN Clause
Deleting Data in Table
DROP Table
Update Data
Update Specific Column
https://www.geeksforgeeks.org/python/python-database-tutorial/ 3/7
10/10/25, 4:29 PM Python Database Tutorial - GeeksforGeeks
Note: For more information, refer to our detailed Python SQLite3
Tutorial
Python JSON
JSON JavaScript Object Notation is a format for structuring data. It is
mainly used for storing and transferring data between the browser
and the server. Python too supports JSON with a built-in package
called json. This package provides all the necessary tools for working
with JSON Objects including parsing, serializing, deserializing, and
many more.
JSON Basics
What is JSON?
Data types in JSON
Working With JSON Data in Python
Python JSON - Reading and Writing
Reading and Writing JSON to a File in Python
Append to JSON file using Python
Parsing JSON
How to Parse Data From JSON into Python?
How To Convert Python Dictionary To JSON?
Python – Convert JSON to string
Ways to convert string to json object
Convert JSON data Into a Custom Python Object
Python JSON - Serializing and Deserializing
Serializing JSON
json.dump()
json.dumps()
Deserialize JSON to Object
https://www.geeksforgeeks.org/python/python-database-tutorial/ 4/7
10/10/25, 4:29 PM Python Database Tutorial - GeeksforGeeks
json.load()
json.loads()
Encoding and Decoding Custom Objects in JSON
Serialize and Deserialize complex JSON
Note: For more information, refer to Python JSON Tutorials
Python MongoDB
MongoDB is one of the most popular NoSQL database. It is a cross-
platform, object-oriented database. Basically NoSQL means MongoDB
does not store data in the table or relational format rather provide a
different mechanism for storage and retrieval of data. This is called
BSON which is similar to JSON. That’s why MongoDB offers high
speed, high availability, and high scalability.
MongoDB Basics
MongoDB and Python
Guide to Install MongoDB with Python | Windows
What is a PyMongo Cursor?
Create a database in MongoDB using Python
Python MongoDB Queries
What is a MongoDB Query?
Insert and Update Data Query
insert_one
insert_many
Difference Between insert, insert_one, and insert_many queries in
Pymongo
Update_one
Update_many
insert, replace_one, replace_many Queries
Delete Data and Drop Collection
Delete_one
https://www.geeksforgeeks.org/python/python-database-tutorial/ 5/7
10/10/25, 4:29 PM Python Database Tutorial - GeeksforGeeks
Delete_many
Find
find_one
find_one_and_update
find_one_and_delete
find_one_and_replace
Sort
distinct
rename
bulk_write
$group (aggregation) Operation
Limit
Nested Queries in PyMongo
Python MongoDB Indexing
Indexing in MongoDB using Python
Create_index
How to create index for MongoDB Collection using Python
Get all the information of a Collection’s indexes using PyMongo
drop_index
How to Drop all the indexes in a Collection using PyMongo
How to rebuild all the indexes of a collection using PyMongo
Note: For more information, refer to Python MongoDB Tutorial
Comment A abhish… Follow 5
Article Tags : Python Python-database Tutorials
https://www.geeksforgeeks.org/python/python-database-tutorial/ 6/7
10/10/25, 4:29 PM Python Database Tutorial - GeeksforGeeks
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Pradesh
(201305)
Registered Address:
K 061, Tower K, Gulshan Vivante
Apartment, Sector 137, Noida, Gautam
Buddh Nagar, Uttar Pradesh, 201305
Company Explore
About Us POTD
Legal Job-A-Thon
Privacy Policy Connect
Careers Blogs
Contact Us Nation Skill Up
Corporate Solution
Campus Training Program
Tutorials Courses
Programming Languages IBM Certification
DSA DSA and Placements
Web Technology Web Development
AI, ML & Data Science Data Science
DevOps Programming Languages
CS Core Subjects DevOps & Cloud
GATE GATE
School Subjects Trending Technologies
Software and Tools
Offline Centers Preparation Corner
Noida Interview Corner
Bengaluru Aptitude
Pune Puzzles
Hyderabad GfG 160
Patna System Design
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
https://www.geeksforgeeks.org/python/python-database-tutorial/ 7/7