Skip to content

Instantly share code, notes, and snippets.

View noor-ul-amin0's full-sized avatar

Noor Ul Amin noor-ul-amin0

View GitHub Profile
@noor-ul-amin0
noor-ul-amin0 / fastapi_sqlalchemy_setup.py
Created September 18, 2023 11:35
FastAPI with SQLAlchemy: This Gist contains a basic setup for using FastAPI with SQLAlchemy. It includes the creation of a database engine, a session local, and a base class for declarative models. It also includes a dependency function for getting the DB session and an annotated DB dependency.
from fastapi import Depends
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, Session
from sqlalchemy.ext.declarative import declarative_base
from typing import Annotated
# Database URL
SQLALCHEMY_DATABASE_URL = 'Your database url'
# Create engine