Development
TIP
Project requires minimum Python version of 3.10
Configuration
For local development please make sure to install
- Poetry,
- Install dependencies
poetry install
, - Generate keys,
- Postgres.
Since for local development it is enough to use local file system as storage, configuration below should be sufficient to run API (can be served via .env
file)
DB_URI=postgresql+asyncpg://postgres:postgres@localhost:5432/observer
STORAGE_KIND=fs
KEYSTORE_PATH=/ABS/PATH/TO/keys
STORAGE_ROOT=/ABS/PATH/TO/uploads
Running
First you need to apply database migrations
python -m observer db upgrade
To run server you need to activate virtualenv created by poetry then start server using the following command
python -m observer server start --port 3000
# OR
make serve
Postgres with docker
If you have docker installed you can consider to use the following docker compose file instead of installing Postgres in your main system
version: "3.1"
services:
db:
image: postgres:14.5
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports: # expose postgres into host
- "127.0.0.1:5432:5432"
volumes:
# for persistence between restarts
postgres_data: {}
Running tests
To run tests you can use make test
command and yet you will need to create test database.
Generating swagger
All API schema changes should be reflect in OpenAPI schema. To do this please run make swagger
.
Migrations
To generate a migration you can use python -m observer db revision -m "migration name"
this will create migration file, to apply migrations you can call python -m observer db upgrade
.
For more please look at CLI/migrations.