ISPyB backend server based on python flask-restx.
- Python 3.5+ / pypy2
- flask-restx (+ flask)
- sqlalchemy (+ flask-sqlalchemy) - Database ORM.
- marshmallow
- ruamel.yaml
In case of MySQL or MariaDB you might have to install dev tools:
sudo apt-get install -y python3-mysqldb
or
apt-get install libmariadbclient-dev
Install python dependencies:
sudo pip install -r requirements.txt
cp ispyb_core_config_example.yml ispyb_core_config.yml
If you do not have a running ispyb database then you can create one by running:
scripts/create_core_db.sh
cd scripts
./generate_core_models.sh PATH_TO_CONFIG_FILE.yml
python3 generate_core_schemas.py
cd ..
python3 wsgi.py
invoke app.run
Now you can go to http://localhost:5000/ispyb/api/v1/doc and explore py-ispyb via swagger ui. For authentication json web tokens (jwt) are used. In the web browser call http://localhost:5000/ispyb/api/v1/auth/login , enter user credentials and retrieve access token from the response:
{
"token": "YOUR_JWT_TOKEN",
"roles": [
"user"
]
}
Corresponding curl command:
curl -u USER:PASS -i -H "Accept:application/json" http://localhost:5000/ispyb/api/v1/auth/login
In the case of dummy authentication username user will grant user role and manager will grant user and manager roles.
For requests use the token in the Authorization
header: Bearer YOUR_JWT_TOKEN
. For example to retrieve proposals call:
curl -X GET -H 'Authorization: Bearer YOUR_JWT_TOKEN' -i http://localhost:5000/ispyb/api/v1/proposals
- Swagger documentation: https://raw.githubusercontent.com/ispyb/py-ispyb/master/docs/swagger.json
- For deployment options see
deploy
directory. - Status codes: https://www.flaskapi.org/api-guide/status-codes/