fastapi-supabase
Integrate supabase to FastAPI with less effort
Installation
pip install fastapi-supabase
For local development:
uv sync
uv pip install -e .
Usage
This module needs to initialize the Supabase client object during the lifespan event. You can do it like this:
SUPABASE_URL = os.environ["SUPABASE_URL"]
SUPABASE_KEY = os.environ["SUPABASE_KEY"]
@asynccontextmanager
async def lifespan(app: FastAPI):
yield await fastapi_supabase.lifespan(SUPABASE_URL, SUPABASE_KEY)
app = FastAPI(
title="FastAPI Supabase",
lifespan=lifespan # Here we add a function to handle when the app starts up.
)
# You're all set!
We provide some dependency functions, which help you access supabase client on FastAPI endpoints.
SupabaseClient
This type helps you access supabase asynchronous clients.
Example usage:
@app.post("/login")
async def login(sp: SupabaseClient, form_data: Annotated[OAuth2PasswordRequestForm, Depends()]):
"""
Login and get access token
"""
# login using email
data = {
"email": form_data.username,
"password": form_data.password
}
resp = await sp.auth.sign_in_with_password(data)
if resp.user:
access_token = None
if resp.session:
access_token = resp.session.access_token
return {"access_token": access_token}
raise HTTPException(400, "Invalid username or password")
SupabaseSession
This type is same as SupabaseClient. The difference is this type adds access token to supabase client automatically and endpoint will be protected.
CurrentUser
This type is to get the current user object. And, if you use this type, your endpoint will not be accessible if the client request does not provide a Bearer access token. The access token must be valid on the supabase.
Example:
@app.get("/book")
async def list_book(sp: SupabaseSession, current_user: CurrentUser, page: int = 1, limit: int = 10):
"""
List of books with pagination.
"""
tbl = sp.table("books")
offset = (page - 1) * limit
resp = await tbl.select("*").eq("user_id", current_user.id).limit(limit).offset(offset).execute()
return resp.data
Metadata
Release files for fastapi-supabase 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastapi_supabase-0.2.0.tar.gz | 3.9 kB | With provenance | Details for fastapi_supabase-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_supabase-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for fastapi_supabase-0.2.0-py3-none-any.whl |
Total release size: 8.9 kB
Release files / fastapi_supabase-0.2.0.tar.gz
| Download URL | fastapi_supabase-0.2.0.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
84d3d52ce044087a0fd5225788d3cb9b1bab98e3327c8d610adca6828c46bc8b
|
|
BLAKE2b-256 checksum How to use checksums |
68edee796906878faa104bf1d74fa810fd3dda490a887d3d5ee2b5efb5e1a188
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2024.
Transparency logRelease files / fastapi_supabase-0.2.0-py3-none-any.whl
| Download URL | fastapi_supabase-0.2.0-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ea946395cfc40e1fc0475588423392b4b9f0ccd3ca86fd41889789c95abf6916
|
|
BLAKE2b-256 checksum How to use checksums |
b28765047fb34e555a82479552e273683105f0904864a73eb7cfdeb681e40edf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2024.
Transparency logSecurity for fastapi-supabase 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for fastapi_supabase-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2024.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.