Login with API Key
To authenticate with Modelbit from outside of a notebook you can use API keys stored in environment variables.
First, create an API key in Modelbit. Then set two environment variables:
MB_API_KEY
= Your Modelbit API KeyMB_WORKSPACE_NAME
= The name of your Modelbit workspace
Your Modelbit workspace name
Your Modelbit workspace name comes from your Modelbit URL. When logged into Modelbit, your URL looks like:
https://app.modelbit.com/w/<WORKSPACE_NAME>/...
For example, if your URL is https://app.modelbit.com/w/science-inc/...
your workspace name is science-inc
.
Examples
In Python
Set your API key in Python using os.environ
:
import os
os.environ['MB_API_KEY'] = "<KEY>"
os.environ['MB_WORKSPACE_NAME'] = "<WORKSPACE_NAME>"
For example:
os.environ['MB_API_KEY'] = "mizAO2tWpi:mszPoa5k..."
os.environ['MB_WORKSPACE_NAME'] = "science-inc"
In Hex
Store your Modelbit API key as a secret value in Hex and use its name. You'll also need to set MB_WORKSPACE_NAME
:
import os
os.environ['MB_API_KEY'] = MODELBIT_API_KEY # Hex will paste in the MODELBIT_API_KEY secret value
os.environ['MB_WORKSPACE_NAME'] = <WORKSPACE_NAME> # for example, "science-inc"
In your bash terminal
In bash, you can set your environment variables with:
export MB_API_KEY=<KEY> MB_WORKSPACE_NAME=<WORKSPACE_NAME>
# for example
export MB_API_KEY="mizAO2tWpi:mszPoa5k..." MB_WORKSPACE_NAME="science-inc"
Logging in
Then, when you call mb.login()
your session will authenticate with the API Key:
import modelbit
mb = modelbit.login()