GitHub - callingmahendra/FastAPISample

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 code
    • database.py: Database configuration and session management
    • models.py: SQLAlchemy models for the application
    • routes/: API route definitions
      • customers.py: API routes for managing customers
      • users.py: API routes for managing users
      • employees.py: API routes for managing employees
    • schema.py: Pydantic schemas for request and response validation
    • services/: Service layer for business logic
      • customers.py: Customer service logic
      • users.py: User service logic
      • employees.py: Employee service logic
  • main.py: Entry point for the FastAPI application
  • requirements.txt: List of dependencies for the project
  • Dockerfile: Docker configuration for the application
  • docker-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

  1. Clone the repository:
git clone https://github.com/callingmahendra/FastAPISample.git
cd FastAPISample
  1. Create a virtual environment and activate it:
python -m venv venv
source venv/bin/activate  # On Windows, use `venv\Scripts\activate`
  1. Install the dependencies:
pip install -r requirements.txt

Running the Application Locally

  1. Start the FastAPI application:
  1. Open your browser and navigate to http://127.0.0.1:8000 to access the application.

  2. You can also access the automatically generated API documentation at http://127.0.0.1:8000/docs (Swagger UI) and http://127.0.0.1:8000/redoc (ReDoc).

Running the Application with Docker

  1. Build the Docker image:
docker build -t fastapi-sample .
  1. Start the application using Docker Compose:
  1. Open your browser and navigate to http://127.0.0.1:8000 to access the application.

  2. You can also access the automatically generated API documentation at http://127.0.0.1:8000/docs (Swagger UI) and http://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.