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.
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:
2. Non-relational Databases (NoSQL)
Store data in various formats like documents, key-value pairs, or graphs, offering more flexibility. For Examples:
In this tutorial, we will focus on how to use Python with the most commonly used databases:MySQL,SQLite, andMongoDB. We will cover how to connect to these databases, run queries, and manage data efficiently using Python. Additionally, we will explore how to work withJSONdata 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
Python MySQL Queries
Note:For more information, refer to our detailedPython 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
Python SQLite Queries
Note:For more information, refer to our detailedPython 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
Python JSON - Reading and Writing
Parsing JSON
Python JSON - Serializing and Deserializing
Note:For more information, refer toPython 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
Python MongoDB Queries
Python MongoDB Indexing
Note:For more information, refer toPython MongoDB Tutorial