Skip to content

mpulsemobile/fast-api-demo

Repository files navigation

FastAPI Demo (Modernized)

A minimal FastAPI template using SQLAlchemy 2.0, Pydantic v2, Alembic, and GitHub Actions.

Quick start

  • Requirements: Python 3.12+, pipenv, PostgreSQL
  • Install deps:
pipenv sync --dev
  • Environment:
cp .env.example .env
# Edit .env to point to your DB
  • Migrate DB:
pipenv run alembic upgrade head
  • Run API:
pipenv run uvicorn main:app --reload --host 0.0.0.0 --port 8000

Server: http://localhost:8000

  • API base: http://localhost:8000/api/
  • Docs: http://localhost:8000/docs

Endpoints (examples)

Note: routes use trailing slashes; /api/v1/users will 307 -> /api/v1/users/.

# List users
curl http://localhost:8000/api/v1/users/

# Create a user
curl -X POST http://localhost:8000/api/v1/users/ \
  -H "Content-Type: application/json" \
  -d '{"name":"John"}'

Docker (local)

docker compose -f docker/docker-compose-local.yml up --build
# API: http://localhost:3000/api/

Tests & formatting

pipenv run pytest -v
pipenv run black --check .
pipenv run isort --check-only .

CI/CD

  • GitHub Actions: lockfile-enforced installs (pipenv sync), Postgres service, Alembic migrations, tests, lint, Docker build.

Notes

  • SQLAlchemy 2.0 patterns: DeclarativeBase, Mapped[...], mapped_column, select() + scalars()
  • Pydantic v2 patterns: field_validator, ConfigDict(from_attributes=True), pydantic-settings for config

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •