A FastAPI-based asynchronous REST API for Star Wars data, featuring films, characters, and starships. Data is synchronized from the public API https://swapi.info and stored in a PostgreSQL database. The project uses SQLModel ORM, Alembic for migrations, and is containerized with Docker.
- Async FastAPI backend
- PostgreSQL database (via Docker)
- SQLModel ORM
- Alembic migrations
- SWAPI sync endpoint
- Paginated endpoints for films, characters, starships
- Typed responses with Pydantic schemas
- Unit tests with pytest and httpx
git clone https://github.com/yourusername/starwars-api.git
cd starwars-apiCopy .env.example to .env and fill in your database credentials:
cp .env.example .env
# Edit .env with your settings (see example below)Example .env:
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=starwars_db
docker compose up --buildThis will start both the PostgreSQL database and the FastAPI app.
Open a shell in the API container:
docker compose exec srv-starwars-api bashRun Alembic migrations:
uv run alembic upgrade headUse the /api/sync endpoint to fetch and store SWAPI data:
curl -X POST http://localhost:8000/api/sync- API docs: http://localhost:8000/docs
- Example endpoints:
GET /api/filmsGET /api/charactersGET /api/starshipsPOST /api/sync
Tests are located in starwars-api-app/app/tests/.
To run all tests:
docker compose exec srv-starwars-api bash
uv run pytest --cov=app