This is a project template which uses FastAPI, Alembic and async SQLModel as ORM.
- FastAPI
- SQLAlchemy 2.0 Models and ORM using AsyncSession and Async DB Statements
- Alembic with automatic Models Migration
- Pydantic with custom validation and Settings
- CORS
- Uvicorn and Gunicorn for Python web server
├── .env # Contains environment variables for the function
├── app # Main logic code
│ ├── apis # The views layer
│ │ ├── __init__.py
│ │ ├── applicant.py # The applicant endpoint
│ │ ├── job.py # The job endpoint
│ │ └── worker.py # The worker endpoint
│ ├── controllers # The controllers layer
│ │ ├── __init__.py
│ │ ├── applicant.py # The applicant controller
│ │ ├── job.py # The job controller
│ │ └── worker.py # The worker controller
│ ├── database # The models layer
│ │ ├── __init__.py
│ │ ├── config.py # Config naming convention for database
│ │ ├── depends.py # Add dependency for database
│ │ └── models.py # Declare models
│ ├── exceptions # Exception for app
│ │ ├── __init__.py
│ │ ├── configure_logging.py # Config for logging
│ │ └── handle_exception.py # Executes when an exception is thrown.
│ ├── schemas # Schemas for response models
│ │ ├── __init__.py
│ │ ├── applicant.py # The applicant schema
│ │ ├── job.py # The job schema
│ │ └── worker.py # The worker schema
│ ├── utils # Utility for app
│ │ ├── __init__.py
│ │ └── common.py # The common functions using for app
│ ├── __init__.py
│ ├── _version.py
│ ├── config.py # Config for main app (paging, database, app)
│ ├── configure_logging.py # Some reasonable defaults and handle those settings
│ └──main.py # Init app, declare route, swagger
├── migrations # Migrations database version
├── README.md
├── requirements.in
└── requirements.txt
Create an .env file on root folder and copy the content from .env.example. Feel free to change it according to your own configuration.
cp .env.example .env
docker-compose up -d --build
- Python 3.8.10
- PostgreSQL v12.x, create user and database to use using your favorite tools, (pdAdmin, DBeaver, Command, etc)
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Fixed model changes
alembic revision --autogenerate -m "<revision name>"
# Apply changes to database
alembic upgrade head
uvicorn main:app --reload
After running, you can access the documentation (Swagger) with the following path http://localhost:8080/api/v1