Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dials/dials-rest
A RESTful API to a (limited) subset of DIALS functionality
https://github.com/dials/dials-rest
Last synced: about 14 hours ago
JSON representation
A RESTful API to a (limited) subset of DIALS functionality
- Host: GitHub
- URL: https://github.com/dials/dials-rest
- Owner: dials
- License: mit
- Created: 2022-11-17T14:27:19.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-06-29T09:26:38.000Z (over 1 year ago)
- Last Synced: 2024-11-24T19:14:57.514Z (2 months ago)
- Language: Python
- Size: 47.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# A RESTful API to a (limited) subset of DIALS functionality.
```
mamba env create -f environment.yml
mamba activate dials-rest
pip install -e .
```Generate a JWT secret and store it in the `DIALS_REST_JWT_SECRET` environment variable:
```
$ export DIALS_REST_JWT_SECRET=`openssl rand -hex 32`
```Create a new access token:
```
$ export TOKEN=`create-access-token --expiry 2023-06-01`
```Start the app:
```
$ uvicorn dials_rest.main:app --reload
```In another terminal:
```
curl -X 'POST' 'http://127.0.0.1:8000/export_bitmap/' -H 'accept: application/json' -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' -d '{
"filename": "/dls/i24/data/2022/cm31109-5/myoglobin_dithionite/myglobin_3_00001.cbf",
"image_index": 1,
"format": "png",
"binning": 4,
"display": "image",
"colour_scheme": "greyscale",
"brightness": 10,
"resolution_rings": {
"show": true,
"number": 10
}
}' -o image.png
```## Docker/podman
To build with docker/podman:
```
$ podman build -t dials-rest --format=docker .
```To create an access token:
```
$ podman run -e DIALS_REST_JWT_SECRET=$DIALS_REST_JWT_SECRET -it dials-rest /env/bin/create-access-token
```To run the server:
```
$ podman run -e DIALS_REST_JWT_SECRET=$DIALS_REST_JWT_SECRET -p 127.0.0.1:8081:80 dials-rest
```## Monitoring
Before starting the DIALS REST server export the environment variable `export DIALS_REST_ENABLE_METRICS=1` to enable a `/metrics` endpoint in [prometheus](https://prometheus.io/) format.Next add a simple `prometheus.yml` config file that tells prometheus where to scrape metrics from:
```
$ cat > prometheus.yaml << EOF
scrape_configs:
- job_name: "dials-rest"
scrape_interval: 15s
static_configs:
- targets: ["localhost:8000"]
EOF
```
Run prometheus via podman (or equivalently docker) exposed on port 9091:
```
$ podman run --network=host -v $PWD/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus --web.listen-address="localhost:9091" --config.file=/etc/prometheus/prometheus.yml
```## Unit tests
To run unit tests:
```
$ mamba install -y dials-data httpx pytest
$ pytest --regression
```