Skip to content

Proac-Tee/fastapi-server-template

Repository files navigation

FastAPI Application

This repository contains a FastAPI application that can be run locally or using Docker.


Requirements

For Local Development

  • Python 3.9+
  • pip
  • (Recommended) virtualenv or venv

For Docker

  • Docker 20+
  • Docker Compose (optional but recommended)

Project Structure (Example)

.
├── app/
│   ├── main.py          # FastAPI entry point
│   ├── __init__.py
│   └── routers/
├── requirements.txt
├── Dockerfile
├── docker-compose.yml   # optional
└── README.md

Running the App Locally

1. Clone the Repository

git clone https://github.com/Proac-Tee/fastapi-server-template.git
cd fastapi-server-template

2. Create and Activate a Virtual Environment

python -m venv venv

# Linux / macOS
source venv/bin/activate

# Windows
venv\\Scripts\\activate

3. Install Dependencies

pip install -r requirements.txt

4. Run the Application

uvicorn app.main:app --reload

The API will be available at:


Running the App with Docker

1. Build the Docker Image

docker build -t fastapi-app .

2. Run the Container

docker run -d \
  --name fastapi-container \
  -p 8000:8000 \
  fastapi-app

The API will be available at:


Running with Docker Compose (Optional)

If you are using docker-compose.yml:

docker-compose up --build

To stop the services:

docker-compose down

Example Dockerfile

FROM 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"]

Environment Variables

You can use environment variables for configuration.

Example:

export ENV=development
export DATABASE_URL=postgresql://user:password@localhost/db

Or with Docker:

docker run

About

Production-ready FastAPI API with JWT authentication, SQLAlchemy, Docker, and Pytest.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published