A modern FastAPI template project using uv for fast dependency management.
- 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
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
- Python 3.10 or higher
- uv package manager
If you don't have uv installed, install it first:
On macOS and Linux:
curl -LsSf https://astral.sh/uv/install.sh | shOn Windows:
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"Or with pip:
pip install uv-
Clone the repository
git clone <repository-url> cd fastapi-template
-
Install dependencies with uv
uv sync
-
Activate the virtual environment
source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Run the application
uv run uvicorn main:app --reload
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 the application
uv run uvicorn main:app --reload
# Run tests
uv run pytest
# Run any Python script
uv run python script.py# Update all dependencies
uv sync --upgrade
# Update specific dependency
uv add "package-name@latest"uv sync- Install dependencies and sync virtual environmentuv add <package>- Add a new dependencyuv remove <package>- Remove a dependencyuv run <command>- Run a command in the virtual environmentuv lock- Generate lock fileuv export- Export requirements.txt
uv automatically manages a virtual environment for your project. The virtual environment is located in .venv/ and is automatically activated when using uv run.
uv generates a uv.lock file that locks all dependencies to specific versions for reproducible builds. This file should be committed to version control.
The project is configured through pyproject.toml:
- Dependencies - Listed in the
dependenciesarray - Development Dependencies - Listed in the
[project.optional-dependencies]section - Python Version - Specified in
requires-python - Project Metadata - Name, version, description, etc.
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"]- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
uv run pytest - Submit a pull request
This project is licensed under the MIT License.
If you encounter any issues:
- Check the uv documentation
- Review the FastAPI documentation
- Create an issue with detailed information