Python Client: Install and Authenticate

Python Client: Install and Authenticate

To install the OpenLab python client, ensure you have python >= 3.6, which comes packaged with the python package installer (pip). To check the version, open a command prompt and type your python environmental variable (in my case, it was customized to py), followed by -V for Version.

Once you have verified your python version, simply run pip install openlab in the command prompt.

This will fetch the OpenLab package, and download all necessary python dependencies if they aren't installed yet.


Note: If you get a PermissionError, try adding --user t0 the previous command to install the package without administrative rights.


Setup your OpenLab credentials

There are 3 ways to validate your OpenLab Credentials (in increasing priority):

  1. Using the keyring library (Default)
  2. Storing  your credentials in openlab/account.py
  3. Passing keyword arguments into the http_client() initialization

All 3 of the above options require 2 mandatory and 1 optional parameter(s):

  • API Key
  • Username/E-mail
  • License ID (optional for multi-license holders)

Note: The optional license guuid is only relevant if running a simulation using python, as it is used for checking allotted simulation limits. If it is omitted, OpenLab will take a "best guess" approach as to which license to use.

To generate these parameters: 1.) Go to your User settings in the top right corner of https://live.openlab.app.  2.) Select which license you want to generate for (if multiple licenses)  3.) Click Generate Python login script.

A new API key will be generated, and a form should appear which will overwrite your old API key (if you had one). Copy this key and paste it in the correct place for the upcoming options.

Authentication

Option 1 - Keyring

Either create a new python script, or open a python shell (following method). The first time you initialize and run openlab.http_client(), you will be prompted to enter your credentials:

After you have entered this, the python client will securely store it in your system's password keychain, and you will not need to input these afterwards (unless your  api key expires or you generate a new one from the webpage).

Note: If you need to switch users or change api key, enter and run openlab.login.switch_user(new_username, new_api_key) from a python script/shell.

Option 2 - Store in file

You can paste the credentials taken earlier into a specific file in the same file directory as your OpenLab python library. This file is acount.py. You will see that the default values are all None. As long as these values are not None, they will take priority over the stored keyring credentials.

Option 3 - Pass in as arguments

Additionally, you can pass the values as keyword arguments when initializing the http client. Make sure to replace the break lines/return lines with commas. For example:

import openlab
session=openlab.http_client(username="openlab.test.user@gmail.com",apikey="66385C24228E02EE0ACBB82894C3F4B1E7CA12F32E3C1C08606682E1135B7111",licenseguid="d66f7084-e59c-4443-bd23-3d43a926fa6e")

This option takes first priority over the previous two options.


If you have any questions or problems authenticating the OpenLab python client, please don't hesitate to contact us!

Who is using OpenLab:

  • University of Stavanger
  • NTNU
  • Aker BP
  • Maersk Drilling
  • Equinor
  • University of Calgary