cuOpt Thin Client API Example
import os
from cuopt_thin_client import CuOptServiceClient
# Load the credentials from the environment or some other way
cuopt_client_id = os.environ["CUOPT_CLIENT_ID"]
cuopt_client_secret = os.environ["CUOPT_CLIENT_SECRET"]
cuopt_service_client = CuOptServiceClient(
client_id=cuopt_client_id,
client_secret=cuopt_client_secret
)
optimized_routes = cuopt_service_client.get_optimized_routes("/path/to/cuopt/problem/data")
The problem data file should contain JSON data as shown in the request body for the Get Routes Open-API spec. The data may be written as a plain text file, and it may optionally be compressed with zlib. The data may also be written from Python using the pickle module.
Put your client id and secret in a credentials.json file as below:
{
"CUOPT_CLIENT_ID" : "PASTE_YOUR_CLIENT_ID_HERE",
"CUOPT_CLIENT_SECRET" : "PASTE_YOUR_CLIENT_SECRET_HERE"
}
Invoke the CLI
cuopt_cli cuopt_problem_data.json -c credentials.json
Alternatively, you may set CUOPT_CLIENT_ID and CUOPT_CLIENT_SECRET in your environment and omit the -c argument to cuopt_cli