Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Romain Sacchi committed Apr 12, 2019
2 parents 3ea87bc + b1b9221 commit 3a69b9f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ COPY . /app

RUN pip install gunicorn
RUN pip install -e .
ENTRYPOINT gunicorn -b :5000 bonsai_api:"create_app()"
ENTRYPOINT gunicorn -b :5000 bonsai_api:app
74 changes: 52 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[![Coverage Status](https://coveralls.io/repos/github/BONSAMURAIS/bonsai_api/badge.svg?branch=master&service=github)](https://coveralls.io/github/BONSAMURAIS/bonsai_api?branch=master&service=github) [![Build Status](https://travis-ci.org/BONSAMURAIS/bonsai_api.svg?branch=master)](https://travis-ci.org/BONSAMURAIS/bonsai_api) [![Build Status](https://ci.appveyor.com/api/projects/status/github/BONSAMURAIS/bonsai_api)](https://ci.appveyor.com/api/projects/status/github/BONSAMURAIS/bonsai_api)
[![Coverage Status](https://coveralls.io/repos/github/BONSAMURAIS/bonsai_api/badge.svg?branch=master&service=github)](https://coveralls.io/github/BONSAMURAIS/bonsai_api?branch=master&service=github) [![Build Status](https://travis-ci.org/BONSAMURAIS/bonsai_api.svg?branch=master)](https://travis-ci.org/BONSAMURAIS/bonsai_api) [![Build Status](https://ci.appveyor.com/api/projects/status/github/BONSAMURAIS/bonsai_api?branch=master)](https://ci.appveyor.com/project/romainsacchi/bonsai-api)

# Bonsai API
## Documentation
See [documentation](https://bonsamurais.github.io/bonsai_api/build/html/index.html).
See [API specifications](https://api.bonsai.uno/v1/ui/) and [documentation](https://bonsamurais.github.io/bonsai_api/build/html/index.html).

## What is it?
This is a Flask API using Flask-RESTful that serves requests on the BONSAI graph database and LCA results.
Expand All @@ -12,30 +12,25 @@ The idea is to give users easy-to-use endpoints to quickly query data from the B
For example, using a Python interpreter:

import requests
r = requests.post('http://api.bonsai.uno/do_lca/',
r = requests.post('http://api.bonsai.uno/v1/do_lca/',
json={"functional unit": [("http://rdf.bonsai.uno/someUri1",1.0,"kilogram"), ("http://rdf.bonsai.uno/someUri2",1.0,"kilogram")],
"method":"CML 2001", "algorithm":"attributional"})
r.json()

would output:
```json
[
{"uri": "http://rdf.bonsai.uno/someUri1", "label": "Electricity production, coal"}: {
"Global Warming Potential 100a": [
{"impact": 0.102, "unit": "kg CO2-eq."}
],
"Acidification": [
{"impact": 1.2e-5, "unit": "kg SO2-eq."}
]
},
{"uri": "http://rdf.bonsai.uno/someUri2", "label": "Electricity production, nuclear"}: {
"Global Warming Potential 100a": [
{"impact": 0.02, "unit": "kg CO2-eq."}
],
"Acidification": [
{"impact": 1.2e-2, "unit": "kg SO2-eq."}
]
}
{
"label":"Manufacture of cement, lime and plaster",
"uri":"http://rdf.bonsai.uno/activitytype/exiobase3_3_17/A_CMNT",
"activityType":"",
"algorithm": "attributional",
"impacts": {
"amount":650.8,
"impact_name": "GWP100a",
"unit": "kg CO2-eq."
}
}
]
```

Expand All @@ -46,7 +41,7 @@ We foresee **bonsai_api** to work together with:
* **the BONSAI database**


![alt text](https://github.com/BONSAMURAIS/bonsai_api/blob/master/docs/bonsai_app_flow_diagram.png)
![alt text](https://github.com/BONSAMURAIS/bonsai_api/blob/master/bonsai_app_flow_diagram.png)


## Install
Expand Down Expand Up @@ -74,7 +69,42 @@ Or if you are using the master branch, install Flask from source before installi
pip install -e .

## Run
Linux/MacOS

### Docker

The docker image uses [gunicorn](https://gunicorn.org/) to serve the application.

Build the image with:

docker build . -t bonsai_api

The minimal command line to run the image would look like:

docker run -p 5000:5000 bonsai_api


Running on another port (say, 8080) on the host, and displaying DEBUG logs from gunicorn:

docker run -e GUNICORN_CMD_ARGS="--log-level DEBUG" -p 8080:5000 bonsai_api


Running the application as a docker container and naming the container `bonsai_api`:

docker run -d --name bonsai_api -e GUNICORN_CMD_ARGS="--log-level DEBUG" -p 8080:5000 bonsai_api

To see the output logs from this conatiner:

docker logs bonsai_api

To _follow_ the logs from the container (must do `CTL-C` to stop the logs from showing in the terminal, *but* the service will continue to run!)

docker logs -f bonsai_api

To stop the background service:

docker stop bonsai_api

### Linux/MacOS

Set the environment variables

Expand All @@ -85,7 +115,7 @@ Run local server

flask run

Or on Windows cmd
### Windows cmd

set FLASK_APP=bonsai_api
set FLASK_ENV=development
Expand Down
3 changes: 1 addition & 2 deletions bonsai_api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ info:
description: This is a simple API to serve queries to and from the BONSAI database as well as LCA results. You can find out more about bonsai_api on the [Github page](https://github.com/BONSAMURAIS/bonsai_api) and the main [BONSAI website](https://bonsai.uno/).
contact:
email: info@bonsai.uno
host: 'https://api.bonsai.uno'
host: 'api.bonsai.uno'
schemes:
- http
- https
basePath: "/v1"
consumes:
Expand Down

0 comments on commit 3a69b9f

Please sign in to comment.