Setup
This section explains how to setup the dAIEdge-VLab Python API.
Login & API entry point
There are several ways to identify you to the dAIEdge-VLab :
- Provide a
setup.yamlfile to the Python API. - Login using the
login()method. - Setup environment variables for your credentials.
It is recommended to use the last method. This avoids pushing your credentials to a git repository by accident.
Setup file
The setup.yaml file is used to store the API entry point and your credentials. You should never push this file in any git repository. Don’t forget to add the setup.yaml in your .gitignore file.
Create the following file and fill in your credentials :
api:
url: "vlab.daiedge.eu"
port: "443"
user :
email: "your-email"
password: "your-password"
Simply give the path to the setup.yaml file in the dAIEdgeVLabAPI constructor :
from daiedge_vlab import dAIEdgeVLabAPI
api = dAIEdgeVLabAPI(setup_file="./path/to/setup.yaml")As soon as the object api is created, it will try to identify itself to the dAIEdge-VLab. If it fails, an error will be thrown.
Login Method
This method allows you to defer the login phase to later. For instance, if you don’t know the credentials yet, this allows you to have the reference to the API before any login attempt :
from daiedge_vlab import dAIEdgeVLabAPI
api = dAIEdgeVLabAPI(url="vlab.daiedge.eu", port=443)
api.login(username="your-email", password="your-password")Environment variable
Start by simply setting the $VLAB_USER and $VLAB_PASSWORD in the environment variables :
export VLAB_USER="your-email"
export VLAB_PASSWORD="your-password"To avoid exporting these variables every time you open a new terminal, you can add the two previous lines in your .bashrc file. You can name these variables as you want.
With the setup.yaml file :
The dAIEdgeVLabAPI object will try to infer environment variables that are referenced in the setup.yaml. For instance :
api:
url: "vlab.daiedge.eu"
port: "443"
user :
email: $VLAB_USER
password: $VLAB_PASSWORDDirectly in the Python script :
Simply refer to the environment variables in your python scripts :
import os
from daiedge_vlab import dAIEdgeVLabAPI
api = dAIEdgeVLabAPI(url="vlab.daiedge.eu", port=443)
api.login(username=os.environ['VLAB_USER'], password=os.environ['VLAB_PASSWORD'])Login validity
Once logged in, by default, the dAIEdgeVLabAPI object can access the dAIEdge-VLab for 15 minutes. After that, you must call the method refresh to get a new valid token. You can do that up to 14 days after the login. You can enable an automatic refresh mechanism by setting to True the auto_refresh parameter in the login method or in the constructor. This will automatically call the refresh method on your behalf every 10 minutes. The following code snippets showcase these use cases :
import dAIEdgeVLabAPI
api = dAIEdgeVLabAPI(setup_file="./path/to/setup.yaml", auto_refresh=True)import os
from daiedge_vlab import dAIEdgeVLabAPI
api = dAIEdgeVLabAPI(url="vlab.daiedge.eu", port=443)
api.login(
username=os.environ['VLAB_USER'],
password=os.environ['VLAB_PASSWORD'],
auto_refresh=True
)