Skip to main content

SDK and Command Line Interface

trainML provides an open-source library for programmatic access to trainML resources. It includes a Python module as well as a series of shell commands.


If you install the module in a virtual environment, the shell commands are only available when that virtual environment is activated.


Install the trainML PyPi package into a python virtual environment using Python 3.8 or above:

pip install trainml


In order to use the SDK, you must generate API keys for your trainML account and supply them to the SDK. To create new API keys, go to the account settings page and click the Create button in the API Keys section. This will automatically download a credentials.json file. This file can only be generated once per API key.


Treat this file as a password, as anyone with access to your API key will have the ability to create and control resources in your trainML account.

You can deactivate any API key by clicking the Remove button.

The easiest way to authenticate is to place the credentials file downloaded into the .trainml folder of your home directory and ensure only you have access to it. From the directory that the credentials.json file was downloaded, run the following command:

mkdir -p ~/.trainml
mv credentials.json ~/.trainml/credentials.json
chmod 600 ~/.trainml/credentials.json

For more ways to configure authentication, review the readme file on Github.



The trainML SDK utilizes the asyncio library to ease the concurrent execution of long running tasks. An example of how to create a dataset from an S3 bucket and immediately run a training job on that dataset is the following:

from trainml import TrainML
import asyncio

trainml = TrainML()

# Create the dataset
dataset =
name="Example Dataset",


# Watch the log output, attach will return when data transfer is complete

# Create the job
job =
name="Example Training Job",
gpu_type="GTX 1060",
"PYTHONPATH=$PYTHONPATH:$TRAINML_MODEL_PATH python -m --num_gpus=1 --data_dir=$TRAINML_DATA_PATH --model_dir=$TRAINML_OUTPUT_PATH --enable_checkpoint_and_export=True --train_epochs=10 --batch_size=1024",
datasets=[dict(, type="existing")],

# Watch the log output, attach will return when the training job stops

# Cleanup job and dataset

For more examples of how to use the SDK to create, monitor, and remove trainML resources, review the examples provided here.

Command Line Interface

The command line interface is rooted in the trainml command. To see the available options, run:

trainml --help

To list all jobs:

trainml job list

To list all datasets:

trainml dataset list

To connect to a job that requires the connection capability:

trainml job connect <job ID or name>

To watch the realtime job logs:

trainml job attach <job ID or name>

For more details of how to use the cli to create, monitor, and remove trainML resources, review the readme here.