-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83402a2
commit e51c83e
Showing
3 changed files
with
27 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ FIRST_SUPERUSER_PASSWORD=admin12345 | |
# API URL | ||
SUPABASE_URL=http://localhost:54321 | ||
# service_role key | ||
SUPABASE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU | ||
SUPABASE_KEY=eeyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU | ||
|
||
# Postgres | ||
# DB URL: postgresql://postgres:[email protected]:54322/postgres | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,185 +1,43 @@ | ||
<p align="center"> | ||
<img src="docs/assets/logo.png" alt="Logo"> | ||
</p> | ||
# FastAPI Supbase Template | ||
|
||
<p align="center"> | ||
<a href="https://opensource.org/licenses/MIT"> | ||
<img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"> | ||
</a> | ||
<a href="https://codecov.io/gh/Atticuszz/fastapi_supabase_template"> | ||
<img src="https://codecov.io/gh/Atticuszz/fastapi_supabase_template/branch/main/graph/badge.svg?token=YOUR_TOKEN" alt="codecov"> | ||
</a> | ||
<a href="https://github.com/Atticuszz/fastapi_supabase_template/actions"> | ||
<img src="https://github.com/Atticuszz/fastapi_supabase_template/actions/workflows/ci.yml/badge.svg" alt="CI"> | ||
</a> | ||
<a href="https://github.com/Atticuszz/fastapi_supabase_template/releases/"> | ||
<img src="https://img.shields.io/github/release/Atticuszz/fastapi_supabase_template.svg" alt="GitHub release"> | ||
</a> | ||
<img src="https://img.shields.io/badge/python-3.10|3.11|3.12-blue.svg" alt="Python"> | ||
<a href="https://supabase.com"> | ||
<img src="https://supabase.com/badge-made-with-supabase-dark.svg" alt="Made with Supabase"> | ||
</a> | ||
</p> | ||
## Environment | ||
|
||
# β‘SupaFastβ‘ | ||
### Python | ||
|
||
___ | ||
> supabase & fastapi crud template | ||
> [uv](https://github.com/astral-sh/uv) is an extremely fast Python package and project manager, written in Rust. | ||
![supafast.drawio.png](docs/assets/supafast.drawio.png) | ||
|
||
## Features π | ||
|
||
___ | ||
|
||
### FastAPI&supabase | ||
|
||
1. works of authorization all handled by supabase-py and fastapi **dependency** without any extra code | ||
2. supabase-py crud integration with **pydantic** model validation | ||
|
||
### Pytest | ||
|
||
1. pytest integration with **pytest-cov** | ||
2. pytest **fixtures** for fastapi client and supabase client | ||
3. pytest **fixtures** for access_token and refresh_token | ||
4. test for **CRUD** operations | ||
5. test for **api** operations | ||
|
||
### CI/CD | ||
|
||
1. **codecov** for coverage report | ||
2. **poetry** for dependency management and pytest integration | ||
3. **pre-commit** for code quality | ||
4. **latest_changes.yml** for auto update README.md | ||
5. **Semantic Release** for auto release and changelog | ||
6. **docker** for deployment | ||
|
||
## How to use it | ||
|
||
___ | ||
![](docs/assets/usage.gif) | ||
|
||
1. create your github repo and config it | ||
1. allow ci to access your repo | ||
![img.png](docs/assets/img.png) | ||
2. config ci_tokens | ||
1. `CODECOV_TOKEN` for codecov in `.github/workflows/ci.yml` ,`semantic-release` is optional for auto release | ||
2. `ATTICUS_PAT`should replace with your GitHub token for latest_changes.yml in `.github/workflows/latest_changes.yml` | ||
3. `DOCKER_USERNAME` and `DOCKER_PASSWORD` for docker-image.yml in `.github/workflows/docker-image.yml` | ||
4. replace `tags: atticuszhou/supafast:latest` with your docker repo in `.github/workflows/docker-image.yml` | ||
3. config fastapi setting in `your_project\src\app\core\config.py` | ||
4. config `pyproject.toml` with your project name and description,etc | ||
|
||
2. cd your repo and install dependencies with [uv](https://github.com/astral-sh/uv), which is an extremely fast Python package and project manager, written in Rust. | ||
|
||
```shell | ||
uv sync | ||
```bash | ||
cd backend | ||
uv sync --all-groups --dev | ||
``` | ||
|
||
3. [start your supabase locally](https://supabase.com/docs/guides/local-development/cli/getting-started?queryGroups=platform&platform=linux&queryGroups=access-method&access-method=postgres) | ||
### [Supabase](https://supabase.com/docs/guides/local-development/cli/getting-started?queryGroups=platform&platform=linux&queryGroups=access-method&access-method=postgres) | ||
|
||
install supabase-cli | ||
|
||
```bash | ||
# brew in linux https://brew.sh/ | ||
brew install supabase/tap/supabase | ||
supabase init | ||
supabase start | ||
``` | ||
|
||
4. set your supabase env | ||
launch supabase docker containers | ||
|
||
```shell | ||
export SUPABASE_URL=your_supabase_url | ||
export SUPABASE_KEY=your_supabase_key | ||
export SUPERUSER_EMAIL=your_superuser_email | ||
export SUPERUSER_PASSWORD=your_superuser_password | ||
```bash | ||
# under repo root dir | ||
supabase start | ||
``` | ||
|
||
5. config fastapi settings | ||
|
||
```python | ||
# 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) | ||
``` | ||
> [!NOTE] | ||
> modify the `.env` from the output of `supabase start` or run `supabase status` manually. | ||
6. run server | ||
## Test | ||
|
||
```shell | ||
uv run uvicorn app.main:app --reload | ||
```bash | ||
cd backend | ||
# test connection of db and migration | ||
scripts/pre-start.sh | ||
# unit test | ||
scripts/test.sh | ||
# test connection of db and unit test | ||
scripts/tests-start.sh | ||
``` | ||
|
||
## Roadmap π«Ά | ||
|
||
___ | ||
|
||
- [x] FastAPI backend | ||
- [x] **standard** structure | ||
for <a href="https://github.com/tiangolo/fastapi" class="external-link" target="_blank">**FastAPI**</a> project | ||
|
||
```text | ||
ββ 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 | ||
... | ||
``` | ||
|
||
- [x] **auto-auth** by fastapi dependency with supabase-auth | ||
- [x] **CRUD** operations pytest | ||
- [x] **api** requests pytest | ||
- [ ] Supabase integration | ||
- [x] crud supabase-postgresql | ||
- [ ] websocket with supabase-realtime | ||
- [ ] curd supabase-storage | ||
- [ ] supafunc integration | ||
- [x] deployment | ||
- [x] Full **Docker** integration (Docker based). | ||
- [ ] clone | ||
- [ ] cookiecutter | ||
|
||
## Release Notes π₯Έ | ||
|
||
___ | ||
|
||
### Latest Changes | ||
|
||
## License | ||
|
||
This project is licensed under the terms of the MIT license. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Generic single-database configuration. |