Run the project
What you need
- Python 3.11 or newer, and pip.
- PostgreSQL is optional locally: without it, the API uses SQLite.
Without Docker, with SQLite
This is the fastest way to start:
sh
cd api
python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
DB_HOST= python manage.py migrate
DB_HOST= python manage.py runserver 0.0.0.0:8000Check http://127.0.0.1:8000/health, then the product list at http://127.0.0.1:8000/api/products/. Django REST Framework shows a browsable page, with a form to create a product.
Why DB_HOST= in front of each command? The example .env file points to PostgreSQL. Emptying DB_HOST switches the API to SQLite. See Configuration and startup.
With PostgreSQL
If you have a running PostgreSQL, fill DB_NAME, DB_USER, DB_PASSWORD, DB_HOST in api/.env, then:
sh
python manage.py migrate
python manage.py runserver 0.0.0.0:8000With Docker
From the repository root:
sh
# Dev: runserver
docker build -f api/Dockerfile.dev -t trinity-api:dev api
docker run -p 8000:8000 -e DB_HOST= trinity-api:dev
# Prod: Gunicorn, the exact image that goes to production
docker build -f api/Dockerfile.prod -t trinity-api:local apiThe prod image refuses to start without SECRET_KEY when DEBUG=False, and it expects a PostgreSQL. See Configuration and startup.
Useful commands
Command (in api/) | What it does |
|---|---|
python manage.py runserver | Development server |
python manage.py makemigrations | Writes a migration after a model change |
python manage.py migrate | Applies migrations |
python manage.py createsuperuser | Creates an account for /admin/ |
DB_HOST= pytest | Runs the tests |
flake8 products trinity_api | Lint |