Skip to content

Instantly share code, notes, and snippets.


cosmic-cortex/ Secret

Last active May 29, 2020
What would you like to do?
from fastapi import FastAPI, Depends
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
engine = create_engine("sqlite:///./database.db")
Session = sessionmaker(bind=engine)
def get_db():
return Session()
app = FastAPI()
def an_endpoint_using_sql(db = Depends(get_db)):
# ...
# do some SQLAlchemy
# ...
return {"msg": "an exceptionally successful operation!"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment