Skip to content

About

AiiDA Web API for data queries and workflow management.

Topics

Resources

Stars

11 stars

Watchers

2 watching

Forks

Repository files navigation

Build Status Coverage Status Docs status PyPI version

aiida-restapi

AiiDA REST API for data queries and workflow management.

Uses pydantic for models/validation and fastapi for the ASGI application. Serve e.g. using uvicorn.

Features

  • /users (GET/POST) and /users/<id> (GET) endpoints
  • User pydantic model for validation
  • Automatic documentation at http://127.0.0.1:8000/docs
  • Full specification at http://127.0.0.1:8000/openapi.json

Installation

pip install aiida-restapi

Usage

To start the REST API, run:

aiida_restapi start [OPTIONS]

Options

  • --root-path Root path for the API (default: /)
  • --host Host to listen on (default: 127.0.0.1)
  • --port Port to listen on (default: 8000)
  • --read-only Start the API in read-only mode (default: False)
  • --watch Watch for changes and reload (default: False)

CORS policy

By default, the API allows requests from localhost. You can configure the CORS policy by modifying CORS_ALLOW_ORIGIN_REGEX and/or CORS_ORIGIN_URLS in aiida_restapi/config.py. For more details, see FastAPI CORS documentation.

Examples

See the examples directory.

Collection queries

Resource collections use JSON:API-style query parameters:

GET /nodes?filter[node_type]=data.core.int.Int.&sort=-ctime&page[offset]=0&page[limit]=10
  • filter[field]=value and filter[field][==]=value test equality
  • filter[field][in]=["value1","value2"] tests membership
  • filter[field][<|<=|>|>=]=value compares numeric values
  • filter[field][like|ilike]=pattern matches strings using SQL % and _ wildcards
  • filter[field][contains]=["value1","value2"] tests array containment
  • filter[field][of_length|shorter|longer|has_key]=value filters arrays and dictionaries
  • filter[field][!operator]=value negates any supported leaf operator
  • sort=field,-other sorts ascending and descending, respectively
  • page[offset] and page[limit] control offset pagination
  • include=relationship,other includes related resources
  • Nested dictionary values use dot-separated fields, for example filter[attributes.config.timeout][>=]=30
  • in and contains operators, and their negated forms, require a non-empty JSON array
  • Values are decoded as JSON scalars when possible
  • Repeated constraints are combined with AND
  • Repeated in constraints are flattened
  • General boolean grouping (e.g., OR) is intentionally reserved for POST /querybuilder

Development

git clone https://github.com/aiidateam/aiida-restapi .
cd aiida-restapi

To reload the API on changes, run:

aiida_restapi start --watch

Setting up pre-commit

We use pre-commit to take care for the formatting, type checking and linting.

pip install -e .[pre-commit]  # install extra dependencies
pre-commit run # running pre-commit on changes
pre-commit run --all-files # running pre-commit on every file
pre-commit run pylint --all-files # run only the linter on every file

One can also set up pre-commit to be run on every commit

pre-commit install
# pre-commit uninstall # to disable it again

Running tests

With tox the tests can be run

pip install tox
tox -e py311 # run all tests for Python 3.11
tox -av # see all supported environments

tox will create a custom environment to run the tests in. If you want to run the tests inside your current environment

pip install -e .[testing]  # install extra dependencies
pytest -v

See the developer guide for more information.

License

MIT

Contact

leopold.talirz@gmail.com chrisj_sewell@hotmail.com

About

AiiDA Web API for data queries and workflow management.

Topics

Resources

Stars

11 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages