supabase & fastapi crud template
- works of authorization all handled by supabase-py and fastapi dependency without any extra code
- supabase-py crud integration with pydantic model validation
- pytest integration with pytest-cov
- pytest fixtures for fastapi client and supabase client
- pytest fixtures for access_token and refresh_token
- test for CRUD operations
- test for api operations
- codecov for coverage report
- poetry for dependency management and pytest integration
- pre-commit for code quality
- latest_changes.yml for auto update README.md
- Semantic Release for auto release and changelog
- docker for deployment
-
create your github repo and config it
- allow ci to access your repo
- config ci_tokens
CODECOV_TOKEN
for codecov in.github/workflows/ci.yml
,semantic-release
is optional for auto releaseATTICUS_PAT
should replace with your GitHub token for latest_changes.yml in.github/workflows/latest_changes.yml
DOCKER_USERNAME
andDOCKER_PASSWORD
for docker-image.yml in.github/workflows/docker-image.yml
- replace
tags: atticuszhou/supafast:latest
with your docker repo in.github/workflows/docker-image.yml
- config fastapi setting in
your_project\src\app\core\config.py
- config
pyproject.toml
with your project name and description,etc
-
cd your repo and install dependencies with uv, which is an extremely fast Python package and project manager, written in Rust.
uv sync --all-extras --dev
- set your supabase env
export SUPABASE_URL=your_supabase_url
export SUPABASE_KEY=your_supabase_key
export SUPERUSER_EMAIL=your_superuser_email
export SUPERUSER_PASSWORD=your_superuser_password
- config fastapi settings
# src/app/core/config.py
class Settings(BaseSettings):
API_V1_STR: str = "/api/v1"
SUPABASE_URL: str = Field(default_factory=lambda: os.getenv("SUPABASE_URL"))
SUPABASE_KEY: str = Field(default_factory=lambda: os.getenv("SUPABASE_KEY"))
SUPERUSER_EMAIL: str = Field(default_factory=lambda: os.getenv("SUPERUSER_EMAIL"))
SUPERUSER_PASSWORD: str = Field(default=lambda: os.getenv("SUPERUSER_PASSWORD"))
# SERVER_NAME: str
SERVER_HOST: AnyHttpUrl = "https://localhost"
SERVER_PORT: int = 8000
BACKEND_CORS_ORIGINS: list[AnyHttpUrl] = []
PROJECT_NAME: str = "fastapi supabase template"
Config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True)
- run server
uv run uvicorn src.app.main:app --reload
- FastAPI backend
- standard structure for FastAPI project
ββ src β βββ app β βββ api β β βββ api_v1 β β β βββ endpoints β β β β βββ __init__.py β β β β βββ items.py β β β βββ __init__.py β β β βββ api.py β β βββ __init__.py β β βββ deps.py β βββ core β β βββ __init__.py β β βββ config.py β β βββ events.py β βββ crud β β βββ __init__.py β β βββ base.py β β βββ crud_item.py β βββ schemas β β βββ __init__.py β β βββ auth.py β β βββ base.py β β βββ item.py β β βββ msg.py β βββ services β β βββ __init__.py β βββ utils β β βββ __init__.py β βββ __init__.py β βββ main.py ...
- auto-auth by fastapi dependency with supabase-auth
- CRUD operations pytest
- api requests pytest
- Supabase integration
- crud supabase-postgresql
- websocket with supabase-realtime
- curd supabase-storage
- supafunc integration
- deployment
- Full Docker integration (Docker based).
- clone
- cookiecutter
This project is licensed under the terms of the MIT license.