This repository contains a FastAPI application that can be run locally or using Docker.
- Python 3.9+
pip- (Recommended)
virtualenvorvenv
- Docker 20+
- Docker Compose (optional but recommended)
.
├── app/
│ ├── main.py # FastAPI entry point
│ ├── __init__.py
│ └── routers/
├── requirements.txt
├── Dockerfile
├── docker-compose.yml # optional
└── README.md
git clone https://github.com/Proac-Tee/fastapi-server-template.git
cd fastapi-server-templatepython -m venv venv
# Linux / macOS
source venv/bin/activate
# Windows
venv\\Scripts\\activatepip install -r requirements.txtuvicorn app.main:app --reloadThe API will be available at:
- API: http://127.0.0.1:8000
- Swagger UI: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
docker build -t fastapi-app .docker run -d \
--name fastapi-container \
-p 8000:8000 \
fastapi-appThe API will be available at:
If you are using docker-compose.yml:
docker-compose up --buildTo stop the services:
docker-compose downFROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]You can use environment variables for configuration.
Example:
export ENV=development
export DATABASE_URL=postgresql://user:password@localhost/dbOr with Docker:
docker run