pip install nbsapi
Ensure that you have uv installed.
- Clone the repo
- Inside the repo, create a new virtual env,
.venv, if you use Conda / Anaconda you can create a environment there and activate it. - Activate it
- Run
uv syncto install packages - Run tests using
pytest . - You can now run the FastAPI server using
uv run python src/nbsapi/main.py - The API is available on
http://127.0.0.1:8000and docs athttp://127.0.0.1:8000/docs
If you make changes to the API's public endpoints you must re-generate the API conformance verification tests:
- run
uv run nbsapi conform SPEC_PATHfrom the repo root, whereSPEC_PATHis the path to the generated OpenAPI spec - Copy the generated Tavern YAML tests (located in
conformance/by default) into thenbsapi_verifyrepo, to the pathsrc/nbsapi_verify/tests/ - Cut a new release of
nbsapi, then tag and publish a new release ofnbs_verifyto PyPI (Github Actions will auto-publish when a new tag is pushed). The API and the conformance testing tool are now in sync.
We're using SQLAlchemy and alembic. To run the reference app, you will need PostgreSQL data base with the PostGIS extension installed e.g on Ubuntu.
- You'll need a Postgres database named
nbsapi, with a user and password both set asnbsapi. - Ensure that the
.envfile reflects your database settings. A example .env.sample is provided - Ensure that PostGIS is installed for your database: in a SQL console:
CREATE EXTENSION postgis; - Once that's set up, run
uv run alembic upgrade headto migrate to the current state of the DB.
SQL commands for creation of database and enabling the PostGIS are mentioned above are shown below:
``` sql
CREATE DATABASE nbsapi;
ALTER DATABASE nbsapi SET search_path=public,postgis,contrib;
\connect nbsapi;
CREATE SCHEMA postgis;
CREATE EXTENSION postgis SCHEMA postgis;
CREATE USER nbsapi;
ALTER ROLE nbsapi WITH PASSWORD 'nbsapi';
grant all privileges on database nbsapi to nbsapi;
```
To run a migration:
- Make changes to models under
src/nbsapi/models/(don't forget to import them insrc/nbsapi/models/__init__.py) - Generate a revision using uv run alembic revision --autogenerate -m "description of change"
- Inspect the generated revision in
src/alembic/versions - When you're happy, apply it:
uv run alembic upgrade head(you should also run this after you pull changes)