how to create a global async supabse client to be used through out the fastapi project. #28843
|
i want to have something like this and import the supabase instance into all my apis for crud usage from supabase._async.client import AsyncClient as Client, create_client
async def create_supabase() -> Client:
return await create_client(SUPABASE_URL, SUPABASE_KEY)
supabase = await create_supabase() |
Answered by
silentworks
Aug 23, 2024
Replies: 1 comment
|
FastAPI is huge on dependency injection, you should be using from fastapi import Depends
from api.supabase_client import create_supabase, Client
@app.get("/")
async def home(
supabase: Client = Depends(create_supabase),
):
response = (
await supabase.table("tbl").select("*").execute()
)
return response |
0 replies
Answer selected by
Spritan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FastAPI is huge on dependency injection, you should be using
Dependsin the endpoint you will pass this function into.