Simple OAuth2 Password Flow starter in fastAPI with SQLAlchemy and Postgres
- clone the repository
- Set up
DATABASE_URL
environment variable in the format 'postgresql+psycopg2://:@:/' - Run alembic migrations (
cd app && alembic upgrade head && cd ..
) - Create and activate virtualenv (
python3 -m venv venv && source venv/bin/activate
) - Install dependencies (
poetry install
) - Run the app (
python3 main.py
)
I just needed a quick starter template for setting up auth in my fastapi projects. The code here is mostly lifted from the wonderful FastAPI Docs. I just refactored it a bit to suit my general project structure.
- sqlalchemy 2.0 - ORM
- uvicorn - ASGI server
- alembic - Database Migrations
- psycopg2 - Postgres DB Driver
- python-jose - Handling JWT
- passlib - Password hashing
- poetry - Dependency management