This is the backend of Karp, SBX:s tool for managing lexical data and other structured data.
The basic structure in Karp is a resource, which is a collection of entries. Each resource may be configured according to the format of the data and other needs.
The backend consists of two parts. The command-line interface (CLI), used to manage resources and the web API for modifying and querying the data.
There is also a frontend, contact SBX for more information.
Follow the steps in getting started.
Use the CLI to create or modify resources, publish resources and do bulk editing. To view the CLI documentation, use:
karp-cli --help
The resource configuration is documented here.
There is also a tutorial describing creation of a resource.
The API documentation for the current version is available here.
Using the API (with credentials) one can:
- add an entry to a resource
- modify existing entries
- delete an entry from a resource (discard, actual data is retained)
All edits are stored, along with time and the editor. The history of an entry is also available through the API.
Searching is done with our custom query language.
Searching supports sorting and pagination.
This is the version 7 of Karp backend, for the legacy version (v5).
We use MariaDB for storage and Elasticsearch for search.
This project uses poetry.
A Makefile is provided to simplify tasks.
-
First clone this repo:
git cloneorgh repo clone(if using github-cli). -
Install dependencies:
make dev (or make install-dev)
-
Install MariaDB and create a database
-
Setup environment variables (can be placed in a
.envfile in the root and then ?poetry runsets those):export DB_DATABASE=<name of database> export DB_USER=<database user> export DB_PASSWORD=<user's password> export DB_HOST=localhost export AUTH_JWT_PUBKEY_PATH=/path/to/pubkey -
Activate the virtual environment by running:
poetry shell -
Run
karp-cli db upto initialize database -
Run
make serveormake serve-w-reloadto start development serveror
poetry shelland thenuvicorn --factory karp.karp_v6_api.main:create_app -
To setup Elasticsearch, download Elasticsearch 8.x and run the following commands from the
elasticsearch-8.XXXdirectory:bin/elasticsearch-plugin install analysis-icuThen run
bin/elasticsearch -Expack.security.enabled=falseto start it. -
Add environment variables
export ELASTICSEARCH_HOST=http://localhost:9200
poetry shelland then:karp-cli resource create assets/testing/config/places.yamlkarp-cli entries add places assets/testing/data/places.jsonl- Do the same for
municipalities karp-cli resource publish places 1karp-cli resource publish municipalities 1
- Python >= 3.10
- Poetry >= 1.3
- FastAPI
- SQLAlchemy
- Typer
- Elasticsearch
- Elasticsearch DSL
- MariaDB
- Elasticsearch
Run type checking with make type-check or just basedpyright.
We use basedpyright which is like Pyright, but without a NodeJS dependency.
Currently actual type checking is only done on selected files, but basedpyright provides "syntax and sematic errors" for all files.
The tests are organized in unit, integration and end-to-end tests.
These test should have no infrastructure dependencies and should run fast.
Run them by: make test (or make unit-tests)
These test have some infrastructure dependencies and should run slower.
Run them by: make integration-tests
These test have all infrastructure dependencies and should run slowest.
Run them by: make e2e-tests
These test have all infrastructure dependencies and should run slowest. They also start with a type checking pass.
Run them by: make all-tests
Linting and formatting is done by ruff.
Run linter with make lint. Settings are in ruff.toml.
Run formatter with make fmt, check if formatting is needed make check-fmt.
Usual commands for ruff is:
ruff --fix <path>tries to fix linting problems.ruff --add-noqa <path>add noqa:s (silence lint) to each line that needs
Update version in the following files: