Developer / Tutorials / Python

Interacting with Scifeon through Python

Last updated on 12-Mar-2021 by Jakob Jakobsen Boysen
Jakob Jakobsen Boysen

Platform Lead
boysen@scifeon.com
, tba

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 a Personal Access Token (PAT) needs to be generated to get access:

  1. Open your user profile: go to https://your-domain.scifeon.cloud/#/user/profile
  2. Click "New PAT" and copy the PAT generated and shown in the dialog (starts with PAT).
  3. Paste the PAT into the personal_access_token field in the script below.

    Example: Getting an experiment

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.