This project is a sample FastAPI application that demonstrates how to create and manage users and customers using FastAPI, SQLAlchemy, and SQLite.
Project Structure
app/: Contains the main application codedatabase.py: Database configuration and session managementmodels.py: SQLAlchemy models for the applicationroutes/: API route definitionscustomers.py: API routes for managing customersusers.py: API routes for managing usersemployees.py: API routes for managing employees
schema.py: Pydantic schemas for request and response validationservices/: Service layer for business logiccustomers.py: Customer service logicusers.py: User service logicemployees.py: Employee service logic
main.py: Entry point for the FastAPI applicationrequirements.txt: List of dependencies for the projectDockerfile: Docker configuration for the applicationdocker-compose.yml: Docker Compose configuration for the application.devcontainer.json: Devcontainer configuration for the application.devcontainer/devcontainer.json: Devcontainer configuration for the application.gitignore: Git ignore file
Prerequisites
- Python 3.9 or higher
- Docker (optional, for running the application in a container)
Installation
- Clone the repository:
git clone https://github.com/callingmahendra/FastAPISample.git
cd FastAPISample- Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
- Install the dependencies:
pip install -r requirements.txt
Running the Application Locally
- Start the FastAPI application:
-
Open your browser and navigate to
http://127.0.0.1:8000to access the application. -
You can also access the automatically generated API documentation at
http://127.0.0.1:8000/docs(Swagger UI) andhttp://127.0.0.1:8000/redoc(ReDoc).
Running the Application with Docker
- Build the Docker image:
docker build -t fastapi-sample .- Start the application using Docker Compose:
-
Open your browser and navigate to
http://127.0.0.1:8000to access the application. -
You can also access the automatically generated API documentation at
http://127.0.0.1:8000/docs(Swagger UI) andhttp://127.0.0.1:8000/redoc(ReDoc).
License
This project is licensed under the terms of the GNU General Public License v3.0. See the LICENSE file for details.