Skip to content
/ fastapi-template Public template

Modern FastAPI template for scalable APIs with Docker, tests, and CI/CD for rapid development.

Notifications You must be signed in to change notification settings

johntranz/fastapi-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 

Repository files navigation

FastAPI Template

A modern FastAPI template project using uv for fast dependency management.

πŸš€ Features

  • FastAPI - Modern, fast web framework for building APIs
  • uv - Ultra-fast Python package installer and resolver
  • Python 3.10+ - Modern Python version support
  • Clean Structure - Organized project layout
  • Development Ready - Pre-configured for immediate development

πŸ“ Project Structure

fastapi-template/
β”œβ”€β”€ main.py              # Main FastAPI application
β”œβ”€β”€ pyproject.toml       # Project configuration and dependencies
β”œβ”€β”€ .python-version      # Python version specification
β”œβ”€β”€ .gitignore          # Git ignore rules
└── README.md           # This file

πŸ› οΈ Installation

Prerequisites

  • Python 3.10 or higher
  • uv package manager

Install uv

If you don't have uv installed, install it first:

On macOS and Linux:

curl -LsSf https://astral.sh/uv/install.sh | sh

On Windows:

powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

Or with pip:

pip install uv

Setup Project

  1. Clone the repository

    git clone <repository-url>
    cd fastapi-template
  2. Install dependencies with uv

    uv sync
  3. Activate the virtual environment

    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  4. Run the application

    uv run uvicorn main:app --reload

πŸš€ Quick Start

Add Dependencies

To add new dependencies to your project:

# Add a dependency
uv add fastapi uvicorn

# Add a development dependency
uv add --dev pytest ruff

# Add a specific version
uv add "fastapi>=0.100.0"

Run Commands

# Run the application
uv run uvicorn main:app --reload

# Run tests
uv run pytest

# Run any Python script
uv run python script.py

Update Dependencies

# Update all dependencies
uv sync --upgrade

# Update specific dependency
uv add "package-name@latest"

πŸ“š Development

Available Commands

  • uv sync - Install dependencies and sync virtual environment
  • uv add <package> - Add a new dependency
  • uv remove <package> - Remove a dependency
  • uv run <command> - Run a command in the virtual environment
  • uv lock - Generate lock file
  • uv export - Export requirements.txt

Virtual Environment

uv automatically manages a virtual environment for your project. The virtual environment is located in .venv/ and is automatically activated when using uv run.

Lock File

uv generates a uv.lock file that locks all dependencies to specific versions for reproducible builds. This file should be committed to version control.

πŸ”§ Configuration

The project is configured through pyproject.toml:

  • Dependencies - Listed in the dependencies array
  • Development Dependencies - Listed in the [project.optional-dependencies] section
  • Python Version - Specified in requires-python
  • Project Metadata - Name, version, description, etc.

🐳 Docker Support

To add Docker support, create a Dockerfile:

FROM python:3.10-slim

# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv

# Set work directory
WORKDIR /app

# Copy project files
COPY pyproject.toml uv.lock ./

# Install dependencies
RUN uv sync --frozen

# Copy source code
COPY . .

# Run the application
CMD ["uv", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests: uv run pytest
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License.

πŸ†˜ Support

If you encounter any issues:

  1. Check the uv documentation
  2. Review the FastAPI documentation
  3. Create an issue with detailed information

πŸ™ Acknowledgments

  • FastAPI - The web framework
  • uv - Ultra-fast Python package manager

About

Modern FastAPI template for scalable APIs with Docker, tests, and CI/CD for rapid development.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published