Skip to content

Instantly share code, notes, and snippets.

@cosmic-cortex

cosmic-cortex/fastapi_sqlalchemy.py Secret

Last active May 29, 2020
Embed
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()
@app.get("/")
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