Setup
This section explains how to setup the dAIEdge-VLab Python API.
Login & API entry point
There are sevral ways to identify you to the dAIEdge-VLab :
- Provide a
setup.yaml
file to the Python API. - Login using the
login()
method. - Setup environement variables for your credentials.
It is recomended 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 dAIEdgeVLabAPI 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 allow you to difer the login phase to later. For instence, if you don’t know the credentials yet, this allows you to have the reference to the API before any login attempt :
from dAIEdgeVLabAPI import dAIEdgeVLabAPI
api = dAIEdgeVLabAPI(url="vlab.daiedge.eu", port=443)
api.login(username="your-email", password="your-password")
Envrionement variable
Start by simply set the $VLAB_USER
and $VLAB_PASSWORD
in the envrionement variables :
export VLAB_USER="your-email"
export VLAB_PASSWORD="your-password"
To avoid exporting these variable every time you open a new terminal, you can add the two previous line in your .bashrc
file. You can name these variables as you want.
With the setup.yaml
file :
The dAIEdgeVLabAPI
object will try to infer environement variable that are referenced in the setup.yaml
. For instance :
api:
url: "vlab.daiedge.eu"
port: "443"
user :
email: $VLAB_USER
password: $VLAB_PASSWORD
Directly in the Python script :
Simply refer the environement variables in your python scripts :
import os
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
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
)