Accessing the Zendir API requires an access token. Tokens are provided alongside a valid API license, which is tied to a user account through the Zendir website. A free trial can be created via the website for testing out the API using the Python client or another web-API application. If the account has an activated trial or paid account for the API, the user’s access token is available on the dashboard on the website.
NOTE
To enquire about purchasing an access token, please contact Zendir at support@zendir.io or visit the website for more information.
Adding the API Key
Once the example scripts have been downloaded, the credential_helper.py
script should be edited to include the access token for the API. This is done by adding the token to the GLOBAL_KEY
parameter in the module. By default, the value is left blank. Make sure to save the script as this key will not change between users or sessions.
The fetch_client
function will construct a valid Zendir Client with the API token that will enable a connection to the API, provided that the key is correct. If the key is invalid or mistyped, then no connection to the API will be made. The client is passed between all simulation objects behind the scenes to ensure that all objects instantiated are connected to the API.
Using the Client
In a Python script, to set up the client once the key has been added to the API_TOKEN
parameter, the following lines of code can be added. This ensures that the helper script provided with the example repository is calling the credentials with the user key.
import credential_helper
client = credential_helper.fetch_client()
Using the credential_helper.py
script is not a requirement. Instead, the Client
object can be created inside the script and the access token and URL end-point can be directly provided there instead. It simply makes it easier to run multiple scripts without having to change the key each time.
from zendir import Client
client = Client(token="API TOKEN")
Sessions
When a client object is created, the API will attempt to create a new API session in the cloud. An API session will spin up a dedicated instance to the API that is only accessible by the user who creates it. A standard user will only have access to one concurrent session and new sessions will not know about previous sessions or simulation data. Sessions last for as long as there are active API requests being performed. An idle session will timeout and be removed after 10 minutes of lack of API calls. New sessions will be created when API calls are resumed again. Any data outside of the session will be lost and a new session will be created if an API call is made outside of the duration time.
WARNING
Any data made in previous simulations will be lost if the session time is over. Make sure to download the simulation data if required before the timeout.
When a credential helper creates the client, information about the session will be logged to the screen. The session can take around 30 seconds to be created when the first API call is made. Provided the user is still in their session, there is no start-up time for a new session.
NOTE
During the start-up when a session is first created, messages may not appear on the screen and the Python console may appear to be frozen. For debugging options, see the Printing Logs document on how to enable the various debugging modes to see the status of the startup. Closing the application and starting again will not restart a session and will continue the progress of starting up in the background as it is running on the cloud.