This repository demonstrates a basic CRUD (Create, Read, Update, Delete) application built using FastAPI and MySQL.
- FastAPI Framework: Utilizes FastAPI for building the API leveraging its automatic data validation and interactive API documentation.
- MySQL Database: Integrates with a MySQL database to store and manage data.
- CRUD Operations: Implements standard CRUD operations for managing information.
- Data Models: Defines Pydantic models for data validation and serialization.
- SQLAlchemy ORM: Uses SQLAlchemy for interacting with the MySQL database.
-
Clone the repository:
git clone https://github.com/panoschron97/FastAPI_Crud_App_MySQL.git cd FastAPI_Crud_App_MySQL -
Create a virtual environment (recommended):
python3 -m venv venv source venv/bin/activate # On Linux/macOS venv\Scripts\activate # On Windows
-
Install the dependencies:
pip install -r requirements.txt
-
Set up your MySQL database. Ensure that you have MySQL installed and running. Create a database named
application. -
Configure the database connection: Modify the
database.pyfile to reflect your MySQL credentials:db_url = "mysql://<your_mysql_username>:<your_mysql_password>@<host>:<port>/<your_mysql_databasename>"
-
Run the FastAPI application:
uvicorn main:app --reload
This command starts the FastAPI server, enabling hot reloading for development.
-
Access the interactive API documentation at
http://localhost:8000/docsorhttp://localhost:8000/redocto test the API endpoints.
- FastAPI: A modern, fast (high-performance), web framework for building APIs.
- SQLAlchemy: A SQL toolkit and Object-Relational Mapping (ORM) library.
- MySQL Connector: A driver to connect Python applications to MySQL databases.
- Pydantic: A data validation and settings management library.
- Uvicorn: An ASGI (Asynchronous Server Gateway Interface) server for running FastAPI applications.
- Python-dotenv: Reads key-value pairs from a
.envfile and can set them as environment variables.