Developer / Tutorials / Python

Interacting with Scifeon through Python

Last updated on 21-Dec-2020 by Troels Bagge Angelo
Troels Bagge Angelo

Student Developer
angelo@scifeon.com
, Jakob Jakobsen Boysen
Jakob Jakobsen Boysen

Platform Lead
boysen@scifeon.com

This guide explains how to extract data from Scifeon via a Python script.

In all of the Python code examples below, remember to replace your-domain with your own Scifeon cloud domain.

Prerequisites

In order to interact with an API in python the requests library needs to be installed.

This is done by typing in the console:

pip install --upgrade requests

If you are using conda to run your python use:

conda install --upgrade requests

Now you can design your python script.

Authorize

First an accessToken needs to be generated to get access:

The string in username and password needs to be swapped with personal username and password.

Example: Getting an experiment

The access_token can now be used to extract needed data:

The output experiment will be a dictionary, which you can further manipulate in pandas or your favorite dataframe editor.

If you want to print the data in a JSON comparable format you can use the following function:

You can also request data using dataset-query. An example of this could be requesting all samples related to the fermentation named GDF1234:

The format of the queryResult can be found in datasetQuery documentation here

The queryResult will again be a dictionary, which can be manipulated into a dataframe through pandas.

Jupyter

There has been created a Jupyter notebook, with a tutorial for importing from scifeon. It can be downloaded here Download Jupyter notebook

Next steps

The HTTP API documentation lists all possibilities for querying and saving data.