Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Database
  • Python MySQL
  • Python SQLite
  • Python MongoDB
  • PostgreSQL
  • SQLAlchemy
  • Django
  • Flask
  • SQL
  • ReactJS
  • Vue.js
  • AngularJS
  • API
  • REST API
  • Express.js
  • NodeJS
Open In App
Next Article:
How to Connect Python with SQL Database?
Next article icon

Python Database Tutorial

Last Updated : 15 Mar, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

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.

Python Database Tutorial

In this tutorial, we will discuss how to Python with the most commonly used relational databases such as MySQL, SQLite, NoSQL databases like MongoDB and we will also discuss how to deal with JSON using Python with the help of good examples.

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. 

Introduction

  • Install Python MySQL connector 
  • MySQL-Connector-Python module in Python 
  • Connect MySQL database using MySQL-Connector Python 

Python MySQL Queries

  • Python MySQL – Create Database 
  • Python: MySQL Create Table 
  • Python MySQL – Insert into Table 
  • Python MySQL – Select Query 
  • Python MySQL – Where Clause 
  • Python MySQL – Order By Clause 
  • Python MySQL – Delete Query 
  • Python MySQL – Drop Table 
  • Python MySQL – Update Query 
  • Python MySQL – Limit Clause 
  • Python MySQL – 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.

Introduction

  • Introduction to SQLite in Python
  • Python SQLite – Connecting to Database
  • SQLite Datatypes and its Corresponding Python Types

Python SQLite Queries

  • Python SQLite – Cursor Object
  • Python SQLite – Create Table
  • Python SQLite – Insert Data
  • Python SQLite – Select Data from Table
  • Python SQLite – WHERE Clause
  • Python SQLite – ORDER BY Clause
  • Python SQLite – LIMIT Clause
  • Python SQLite – JOIN Clause
  • Python SQLite – Deleting Data in Table
  • Python SQLite – DROP Table
  • Python SQLite – Update Data
  • Python SQLite – Update Specific Column

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.

Introduction

  • 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 in Python
  • json.dump() in Python
  • json.dumps() in Python
  • Python – Difference between json.dump() and json.dumps()
  • Deserialize JSON to Object in Python
  • json.load() in Python
  • json.loads() in Python
  • Difference Between json.load() and json.loads()
  • Encoding and Decoding Custom Objects in Python-JSON
  • Serialize and Deserialize complex JSON in Python

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.

Introduction

  • 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 Query
  • insert_many Query
  • Difference Between insert, insert_one, and insert_many queries in Pymongo
  • Update_one Query
  • Update_many Query
  • insert, replace_one, replace_many Queries
  • Delete Data and Drop Collection
  • Delete_one Query
  • Delete_many Query
  • Find Query
  • find_one Query
  • find_one_and_update Query
  • find_one_and_delete query
  • find_one_and_replace Query
  • Sort Query
  • distinct Query
  • rename Query
  • bulk_write Query
  • $group (aggregation) Operation
  • Limit Query
  • Nested Queries in PyMongo

Python MongoDB Indexing

  • Indexing in MongoDB using Python
  • Python MongoDB – create_index Query
  • How to create index for MongoDB Collection using Python?
  • Get all the information of a Collection’s indexes using PyMongo
  • drop_index Query
  • How to Drop all the indexes in a Collection using PyMongo?
  • How to rebuild all the indexes of a collection using PyMongo?


Next Article
How to Connect Python with SQL Database?
author
abhishek1
Improve
Article Tags :
  • Python
  • Python-database
  • Tutorials
Practice Tags :
  • python

Similar Reads

  • Python Database Tutorial
    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. In this t
    4 min read
  • How to Connect Python with SQL Database?
    In this article, we will learn how to connect SQL with Python using the MySQL Connector Python module. Below diagram illustrates how a connection request is sent to MySQL connector Python, how it gets accepted from the database and how the cursor is executed with result data. To create a connection
    2 min read
  • SQL using Python
    In this article, integrating SQLite3 with Python is discussed. Here we will discuss all the CRUD operations on the SQLite3 database using Python. CRUD contains four major operations - Note: This needs a basic understanding of SQL. Here, we are going to connect SQLite with Python. Python has a native
    7 min read
  • 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.  This Python MySQL tutorial will
    9 min read
  • 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
    4 min read
  • Python MongoDB Tutorial
    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 JSO
    3 min read
  • Introduction to Psycopg2 module in Python
    Psycopg is the most popular PostgreSQL adapter used in  Python.  Its works on the principle of the whole implementation of Python DB API 2.0 along with the thread safety (the same connection is shared by multiple threads). It is designed to perform heavily multi-threaded applications that usually cr
    4 min read
  • Top 7 Databases to Learn in 2025
    A database is just like a room in an office where all the files and important information can be stored related to a project. Every company needs a database to store and organize the information. The information that we store can be very sensitive, so we always have to be careful while accessing or
    10 min read
  • Interface Python with an SQL Database
    Python is an easy-to-learn language and connectivity of python with any SQL database is a much-desired option to have the persistence feature. Python is an object-oriented programming language and it is open source. Newcomers to the software industry including school children too can learn Python ea
    8 min read
  • Access Relation Databases with Python
    Databases are powerful tools for data scientists. DB-API is Python's standard API used for accessing databases. It allows you to write a single program that works with multiple kinds of relational databases instead of writing a separate program for each one. This is how a typical user accesses datab
    3 min read
geeksforgeeks-footer-logo
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
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences