Python Star Wars API built with FastAPI, SQLModel, and Pydantic v2. Typed responses, richer data, and name-based routes.
- Descriptions and image URLs for every record
- Strict typing with Pydantic v2 and SQLModel
- Relations return names instead of URLs
- Name-based lookup (e.g.,
/api/characters/lukeinstead of/characters/1) - SQLite + ORM; auto-seeds from
assets/base_dataon startup - Custom Swagger UI at
/api/docs(OpenAPI at/api/openapi.json)
- FastAPI, SQLModel, Pydantic v2, Uvicorn
- SQLite (default file:
pyswapi.db), Pydantic Settings for overrides - Dockerfile for container builds
Prereqs: Python 3.11+ and pip.
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
uvicorn main:app --reload- API base: http://localhost:8000/api
- Docs: http://localhost:8000/api/docs
- Database:
pyswapi.dbis created and seeded automatically on first run.
- Override defaults via environment variables matching
env.pyfields:SQLITE_FILE_NAME(defaultpyswapi.db)SQLITE_URL(defaultsqlite:///pyswapi.db)IMAGES_BASE_URL(S3 base for image assets)
- You can also use a
.envfile; Pydantic Settings will pick it up.
docker build -t rotj-api .
docker run -p 8000:8000 rotj-apipytest
# or with coverage
pytest --cov=./api/characters/api/movies/api/planets/api/species/api/vehicles- OpenAPI schema:
/api/openapi.json