Step 1: Using the OpenAPI Generator

In this step we will generate Python code that wraps around the REST API and makes it easier for you to interact with the platform.For this we will use the API specification that can be downloaded from the API documentation website.

You can find the API documentation by clicking on the question mark icon in the top right corner of the menu bar.

This will take you to the API documentation website.

At the top of the page, download the xyzt.ai OpenAPI specification by clicking on the Download button.

We will use this openapi.json file to generate Python API code that we will use to conveniently access the API.

For this you will need to have access to a shell with Node.js installed. The Python wrapper generating code is implemented to run with Node.js.

Start by creating a new folder in which you want to store your code:

mkdir rest-api-experiment
cd rest-api-experiment

and copy the downloaded openapi.json into that folder.

Next, install the OpenAPI Generator package with the Node Package Manager.

# Install the OpenAPI generator
npm install --save --save-exact @openapitools/openapi-generator-cli@2.5.1

Now, execute the following command to generate the Python wrapper library:

# Create a source folder with a gen subfolder
# This makes it easier to exclude the generate code from version control if you want
mkdir -p src/gen

# Use the openapi-generator-cli to generate Python code for the API schema
# and store the output in the src/gen folder
npx openapi-generator-cli generate \
  -g python \
  --global-property=skipFormModel=false \
  -o src/gen \
  -i openapi.json

This populates the src/gen folder with the following files and folders:

src/gen
 |_ README.md
 |_ ...
 |_ openapi_client
 |  |_ __init__.py
 |  |_ api
 |  |_ ...
 |_ ...

as well as some hidden files and folders (for example a .openapi-generator folder).

Congrats, you are now ready to start using the generated API access code.

We recommend using an IDE (Integrated Development Environment) such as PyCharm for using the generated code and creating your scripts. This has the benefit that automatic code-completion makes it easy to fill in the necessary parameters.

To make the newly generated Python code available (to all users on your computer), navigate to the src/gen folder and run:

sudo python setup.py install

The library is called openapi_client.

See also the generated README.md file in that folder for guidance.

Next part