How to query the API ?
With cURL
The REST API is queryable in command line by using cURL
Command :
$ curl --url 'https://metabocloud.mesocentre.uca.fr/index/compounds/HVYWMOMLDIMFJA-DPAQBDIFSA-N.png?community=chebi&size=medium&outputType=resource' \
--output <path/to/output/file>
Output :
The PNG image is saved according to the path defined in the --output
option.
Command :
$ curl -i --url 'https://metabocloud.mesocentre.uca.fr/index/compounds/HVYWMOMLDIMFJA-DPAQBDIFSA-N.mol?community=chebi&outputType=resource'
Output :
HTTP/2 200
accept-ranges: bytes
access-control-allow-headers: X-Metadata-Chebi-Id,X-Metadata-Creation-Date,X-Metadata-Data-License,X-Metadata-Data-Source
access-control-allow-origin: *
access-control-expose-headers: *
content-disposition: inline;filename=f.txt
content-type: text/plain
date: Fri, 20 Sep 2024 07:49:50 GMT
vary: Origin
vary: Access-Control-Request-Method
vary: Access-Control-Request-Headers
x-metadata-chebi-id: CHEBI:16113
x-metadata-creation-date: 2024-08-12
x-metadata-data-license: Creative Commons License (CC BY 4.0)
x-metadata-data-source: Chemical Entities of Biological Interest (ChEBI) Database
content-length: 3175
2024-08-12 CHEBI:16113
Chemical Entities of Biological Interest (ChEBI) Database
Creative Commons License (CC BY 4.0)
32 35 0 1 0 999 V2000
-2.6376 -0.5038 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-3.5146 -0.9853 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-3.5146 -2.0037 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-2.6376 -2.5039 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.7885 -2.0037 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.9208 -2.5039 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.7885 -0.9853 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.9208 0.4770 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.0339 0.9867 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.8154 0.4770 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.8154 -0.5038 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.7677 -0.8155 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.3337 -0.0228 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.7677 0.7881 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.8154 1.5055 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.7885 -0.0040 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.8154 -1.5134 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0
2.6954 0.6279 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0
-4.4046 -2.5266 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
-0.9208 -0.5038 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.9208 -1.5056 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0
0.9007 2.3172 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.0339 -0.9853 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.0339 0.0162 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0
-0.0339 -2.0037 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
3.5020 1.8166 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
4.3691 2.3172 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
5.2363 1.8166 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
5.2363 0.8154 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.6349 2.3172 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.7677 1.8166 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
6.1035 2.3172 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
11 10 1 0 0 0
14 10 1 0 0 0
9 10 1 0 0 0
10 15 1 1 0 0
23 11 1 0 0 0
12 11 1 0 0 0
11 17 1 6 0 0
8 20 1 0 0 0
7 20 1 0 0 0
23 20 1 0 0 0
25 23 1 0 0 0
5 7 1 0 0 0
7 16 1 1 0 0
1 7 1 0 0 0
13 14 1 0 0 0
31 14 1 0 0 0
14 18 1 6 0 0
8 9 1 0 0 0
13 12 1 0 0 0
6 25 1 0 0 0
4 5 1 0 0 0
6 5 2 0 0 0
2 1 1 0 0 0
3 4 1 0 0 0
3 2 1 0 0 0
3 19 1 1 0 0
20 21 1 6 0 0
31 22 1 6 0 0
23 24 1 1 0 0
30 26 1 0 0 0
27 26 1 0 0 0
28 27 1 0 0 0
29 28 1 0 0 0
32 28 1 0 0 0
30 31 1 0 0 0
M END
Command :
$ curl -i --url 'https://metabocloud.mesocentre.uca.fr/index/compounds/HVYWMOMLDIMFJA-DPAQBDIFSA-N.png?community=chebi&size=medium&outputType=url'
Output :
HTTP/2 200
accept-ranges: bytes
access-control-allow-headers: X-Metadata-Image-Size,X-Metadata-Chebi-Id,X-Metadata-Creation-Date,X-Metadata-Data-License,X-Metadata-Data-Source
access-control-allow-origin: *
access-control-expose-headers: *
content-type: text/plain
date: Fri, 20 Sep 2024 08:48:01 GMT
vary: Origin
vary: Access-Control-Request-Method
vary: Access-Control-Request-Headers
x-metadata-chebi-id: 16113
x-metadata-creation-date: 2024-08-26
x-metadata-data-license: Creative Commons License (CC BY 4.0)
x-metadata-data-source: Chemical Entities of Biological Interest (ChEBI) Database
x-metadata-image-size: 350 x 350 px
content-length: 107
https://unh-metabocloud-resources.s3.mesocentre.uca.fr/png/chebi/medium/HVYWMOMLDIMFJA-DPAQBDIFSA-N_350.png
Command :
$ curl -i --url 'https://metabocloud.mesocentre.uca.fr/index/compounds/HVYWMOMLDIMFJA-DPAQBDIFSA-N.mol?community=chebi&outputType=url'
Output :
HTTP/2 200
accept-ranges: bytes
access-control-allow-headers: X-Metadata-Chebi-Id,X-Metadata-Creation-Date,X-Metadata-Data-License,X-Metadata-Data-Source
access-control-allow-origin: *
access-control-expose-headers: *
content-disposition: inline;filename=f.txt
content-type: text/plain
date: Fri, 20 Sep 2024 08:53:14 GMT
vary: Origin
vary: Access-Control-Request-Method
vary: Access-Control-Request-Headers
x-metadata-chebi-id: CHEBI:16113
x-metadata-creation-date: 2024-08-12
x-metadata-data-license: Creative Commons License (CC BY 4.0)
x-metadata-data-source: Chemical Entities of Biological Interest (ChEBI) Database
content-length: 96
https://unh-metabocloud-resources.s3.mesocentre.uca.fr/mol/chebi/HVYWMOMLDIMFJA-DPAQBDIFSA-N.mol
Command :
$ curl --head --url 'https://metabocloud.mesocentre.uca.fr/index/compounds/HVYWMOMLDIMFJA-DPAQBDIFSA-N.png?community=chebi&size=small&outputType=url'
Output :
HTTP/2 200
accept-ranges: bytes
access-control-allow-headers: X-Metadata-Image-Size,X-Metadata-Chebi-Id,X-Metadata-Creation-Date,X-Metadata-Data-License,X-Metadata-Data-Source
access-control-allow-origin: *
access-control-expose-headers: *
content-type: text/plain
date: Fri, 20 Sep 2024 08:10:28 GMT
vary: Origin
vary: Access-Control-Request-Method
vary: Access-Control-Request-Headers
x-metadata-chebi-id: 16113
x-metadata-creation-date: 2024-08-26
x-metadata-data-license: Creative Commons License (CC BY 4.0)
x-metadata-data-source: Chemical Entities of Biological Interest (ChEBI) Database
x-metadata-image-size: 50 x 50 px
content-length: 105
Command :
$ curl --head --url 'https://metabocloud.mesocentre.uca.fr/index/compounds/HVYWMOMLDIMFJA-DPAQBDIFSA-N.mol?community=chebi&outputType=url'
Output :
HTTP/2 200
accept-ranges: bytes
access-control-allow-headers: X-Metadata-Chebi-Id,X-Metadata-Creation-Date,X-Metadata-Data-License,X-Metadata-Data-Source
access-control-allow-origin: *
access-control-expose-headers: *
content-disposition: inline;filename=f.txt
content-type: text/plain
date: Fri, 20 Sep 2024 08:13:02 GMT
vary: Origin
vary: Access-Control-Request-Method
vary: Access-Control-Request-Headers
x-metadata-chebi-id: CHEBI:16113
x-metadata-creation-date: 2024-08-12
x-metadata-data-license: Creative Commons License (CC BY 4.0)
x-metadata-data-source: Chemical Entities of Biological Interest (ChEBI) Database
content-length: 96
With Python
One of the ways to query a REST-API with Python is to use the requests library.
After installing the requests
library, you can query the REST API :
import requests
# Variables
file_format = "png"
output_type = "resource"
inchi_key = "Compound's InChI Key"
community = "Community from which the file must be retrieved"
size = "Image size wanted ('small', 'medium' or 'large')"
# Request
result = requests.get(f"https://metabocloud.mesocentre.uca.fr/index/compounds/{inchi_key}.{file_format}?community={community}&size={size}&outputType={output_type}")
# Metadata
headers = result.headers
metadata = dict(filter(lambda x: x[0].startswith("X-Metadata"), headers.items()))
# Output
with open("image.png", "wb") as file:
file.write(result.content)
print("Metadata : ", metadata)
Output :
The PNG image is saved and the metadata are displayed.
Metadata : {'X-Metadata-Chebi-Id': '16113', 'X-Metadata-Creation-Date': '2024-08-26', 'X-Metadata-Data-License': 'Creative Commons License (CC BY 4.0)', 'X-Metadata-Data-Source': 'Chemical Entities of Biological Interest (ChEBI) Database', 'X-Metadata-Image-Size': '350 x 350 px'}
import requests
# Variables
file_format = "mol"
output_type = "resource"
inchi_key = "Compound's InChI Key"
community = "Community from which the file must be retrieved"
# Request
result = requests.get(f"https://metabocloud.mesocentre.uca.fr/index/compounds/{inchi_key}.{file_format}?community={community}&outputType={output_type}")
# Metadata
headers = result.headers
metadata = dict(filter(lambda x: x[0].startswith("X-Metadata"), headers.items()))
# Output
output = result.text
print("Metadata : ", metadata)
print("Resource :\n", output)
Output :
Metadata : {'X-Metadata-Chebi-Id': 'CHEBI:16113', 'X-Metadata-Creation-Date': '2024-08-12', 'X-Metadata-Data-License': 'Creative Commons License (CC BY 4.0)', 'X-Metadata-Data-Source': 'Chemical Entities of Biological Interest (ChEBI) Database'}
Resource :
2024-08-12 CHEBI:16113
Chemical Entities of Biological Interest (ChEBI) Database
Creative Commons License (CC BY 4.0)
32 35 0 1 0 999 V2000
-2.6376 -0.5038 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-3.5146 -0.9853 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-3.5146 -2.0037 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-2.6376 -2.5039 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.7885 -2.0037 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.9208 -2.5039 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.7885 -0.9853 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.9208 0.4770 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.0339 0.9867 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.8154 0.4770 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.8154 -0.5038 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.7677 -0.8155 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.3337 -0.0228 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.7677 0.7881 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.8154 1.5055 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.7885 -0.0040 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.8154 -1.5134 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0
2.6954 0.6279 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0
-4.4046 -2.5266 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
-0.9208 -0.5038 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.9208 -1.5056 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0
0.9007 2.3172 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.0339 -0.9853 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.0339 0.0162 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0
-0.0339 -2.0037 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
3.5020 1.8166 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
4.3691 2.3172 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
5.2363 1.8166 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
5.2363 0.8154 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.6349 2.3172 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.7677 1.8166 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
6.1035 2.3172 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
11 10 1 0 0 0
14 10 1 0 0 0
9 10 1 0 0 0
10 15 1 1 0 0
23 11 1 0 0 0
12 11 1 0 0 0
11 17 1 6 0 0
8 20 1 0 0 0
7 20 1 0 0 0
23 20 1 0 0 0
25 23 1 0 0 0
5 7 1 0 0 0
7 16 1 1 0 0
1 7 1 0 0 0
13 14 1 0 0 0
31 14 1 0 0 0
14 18 1 6 0 0
8 9 1 0 0 0
13 12 1 0 0 0
6 25 1 0 0 0
4 5 1 0 0 0
6 5 2 0 0 0
2 1 1 0 0 0
3 4 1 0 0 0
3 2 1 0 0 0
3 19 1 1 0 0
20 21 1 6 0 0
31 22 1 6 0 0
23 24 1 1 0 0
30 26 1 0 0 0
27 26 1 0 0 0
28 27 1 0 0 0
29 28 1 0 0 0
32 28 1 0 0 0
30 31 1 0 0 0
M END
import requests
# Variables
file_format = "png"
output_type = "url"
inchi_key = "Compound's InChI Key"
community = "Community from which the file must be retrieved"
size = "Image size wanted ('small', 'medium' or 'large')"
# Request
result = requests.get(f"https://metabocloud.mesocentre.uca.fr/index/compounds/{inchi_key}.{file_format}?community={community}&size={size}&outputType={output_type}")
# Metadata
headers = result.headers
metadata = dict(filter(lambda x: x[0].startswith("X-Metadata"), headers.items()))
# Output
output = result.text
print("Metadata : ", metadata)
print("URL : ", output)
Output :
Metadata : {'X-Metadata-Chebi-Id': '16113', 'X-Metadata-Creation-Date': '2024-08-26', 'X-Metadata-Data-License': 'Creative Commons License (CC BY 4.0)', 'X-Metadata-Data-Source': 'Chemical Entities of Biological Interest (ChEBI) Database', 'X-Metadata-Image-Size': '350 x 350 px'}
Output : https://unh-metabocloud-resources.s3.mesocentre.uca.fr/png/chebi/medium/HVYWMOMLDIMFJA-DPAQBDIFSA-N_350.png
import requests
# Variables
file_format = "mol"
output_type = "url"
inchi_key = "Compound's InChI Key"
community = "Community from which the file must be retrieved"
# Request
result = requests.get(f"https://metabocloud.mesocentre.uca.fr/index/compounds/{inchi_key}.{file_format}?community={community}&outputType={output_type}")
# Metadata
headers = result.headers
metadata = dict(filter(lambda x: x[0].startswith("X-Metadata"), headers.items()))
# Output
output = result.text
print("Metadata : ", metadata)
print("URL : ", output)
Output :
Metadata : {'X-Metadata-Chebi-Id': '16113', 'X-Metadata-Creation-Date': '2024-08-26', 'X-Metadata-Data-License': 'Creative Commons License (CC BY 4.0)', 'X-Metadata-Data-Source': 'Chemical Entities of Biological Interest (ChEBI) Database'}
Output : https://unh-metabocloud-resources.s3.mesocentre.uca.fr/mol/chebi/HVYWMOMLDIMFJA-DPAQBDIFSA-N.mol
import requests
# Variables
file_format = "png"
output_type = "resource"
inchi_key = "Compound's InChI Key"
community = "Community from which the file must be retrieved"
size = "Image size wanted ('small', 'medium' or 'large')"
# Request
result = requests.head(f"https://metabocloud.mesocentre.uca.fr/index/compounds/{inchi_key}.{file_format}?community={community}&size={size}&outputType={output_type}")
# Metadata
headers = result.headers
metadata = dict(filter(lambda x: x[0].startswith("X-Metadata"), headers.items()))
print("Metadata : ", metadata)
Output :
Metadata : {'X-Metadata-Chebi-Id': '16113', 'X-Metadata-Creation-Date': '2024-08-26', 'X-Metadata-Data-License': 'Creative Commons License (CC BY 4.0)', 'X-Metadata-Data-Source': 'Chemical Entities of Biological Interest (ChEBI) Database', 'X-Metadata-Image-Size': '350 x 350 px'}
import requests
# Variables
file_format = "mol"
output_type = "resource"
inchi_key = "Compound's InChI Key"
community = "Community from which the file must be retrieved"
# Request
result = requests.head(f"https://metabocloud.mesocentre.uca.fr/index/compounds/{inchi_key}.{file_format}?community={community}&outputType={output_type}")
# Metadata
headers = result.headers
metadata = dict(filter(lambda x: x[0].startswith("X-Metadata"), headers.items()))
print("Metadata : ", metadata)
Output :
Metadata : {'X-Metadata-Chebi-Id': '16113', 'X-Metadata-Creation-Date': '2024-08-26', 'X-Metadata-Data-License': 'Creative Commons License (CC BY 4.0)', 'X-Metadata-Data-Source': 'Chemical Entities of Biological Interest (ChEBI) Database'}
Note
If you ran the application locally on your machine from a virtual environment or via Docker, you need to change the URL you send the
request to. This means that https://metabocloud.mesocentre.uca.fr/index/compounds/
will become http://localhost:8084/compounds/
if you launched the application with the default parameters.
If you choose another port to run the application then you need to change the URL accordingly.
With a client generated by Swagger
From the OpenAPI specification file describing this REST API, you can auto-generated a client in the language you want thanks to Swagger
using the option Generate Client
in the menu.
The OpenAPI specification file is downloadable here : https://metabocloud.mesocentre.uca.fr/index/metabocloud-index.yaml