Skip to content

Instantly share code, notes, and snippets.

@Tishka17
Created March 29, 2022 07:53
Show Gist options
  • Select an option

  • Save Tishka17/c07bdc8954e34540dae24ee36f8659db to your computer and use it in GitHub Desktop.

Select an option

Save Tishka17/c07bdc8954e34540dae24ee36f8659db to your computer and use it in GitHub Desktop.
Fastapi Depends example
import uuid
from fastapi import FastAPI, Depends
app = FastAPI()
class Session:
pass
class R1:
pass
class R2:
pass
@app.get("/")
async def root(r1: R1 = Depends(), r2: R2 = Depends()):
return {"message": "Hello World"}
def new_r1(s: Session = Depends()):
print("r1", s)
def new_r2(s: Session = Depends()):
print("r2", s)
def new_s():
return uuid.uuid4()
app.dependency_overrides[Session] = new_s
app.dependency_overrides[R1] = new_r1
app.dependency_overrides[R2] = new_r2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment