Python SDK

Python client for Teradata AnalyticOps allows users to integrate with AnalyticOps from anywhere they can execute python such as notebooks, IDEs etc. It can also be used for devops to automate additional parts of the process and integreate into the wider organization.

Installation

The cli is available from pypi here

pip install aoa

Create Client

By default, creating an instance of the AoaClient() will use the users aoa configuration stored in ~/.aoa/config.yaml. You can override these values by passing the relevant constructor arguments or even with env variables.

1 from aoa import AoaClient
2
3 client = AoaClient(project_id="23e1df4b-b630-47a1-ab80-7ad5385fcd8d")

Read Entities

We provide an extensive sdk implementation to interact with the APIs. You can find, create, update, archive, etc any entity that supports it via the SDK. In addition, most if not all search endpoints are also implemented in the sdk. Here are some examples

 1 from aoa import AoaClient, DatasetApi, JobApi
 2 import pprint
 3
 4 client = AoaClient(project_id="23e1df4b-b630-47a1-ab80-7ad5385fcd8d")
 5
 6 dataset_api = DatasetApi(aoa_client=client)
 7
 8 datasets = dataset_api.find_all()
 9 pprint.pprint(datasets)
10
11 dataset = dataset_api.find_by_id("11e1df4b-b630-47a1-ab80-7ad5385fcd8c")
12 pprint.pprint(dataset)
13
14 job_api = JobApi(aoa_client=client)
15 jobs = job_api.find_by_id("21e1df4b-b630-47a1-ab80-7ad5385fcd1c")
16 pprint.pprint(jobs)

Deploy Model Version

Let’s assume we have a model version 4131df4b-b630-47a1-ab80-7ad5385fcd15 which we want to deploy In-Vantage and schedule it to execute once a month at midnight of the first day of the month using dataset connection 11e1df4b-b630-47a1-ab80-7ad5385fcd8c and dataset template d8a35d98-21ce-47d0-b9f2-00d355777de1. We can use the SDK as follows to perform this.

 1 from aoa import AoaClient, TrainedModelApi, JobApi
 2
 3 client = AoaClient(project_id="23e1df4b-b630-47a1-ab80-7ad5385fcd8d")
 4 trained_model_api = TrainedModelApi(aoa_client=client)
 5 job_api = JobApi(aoa_client=client)
 6
 7 trained_model_id = "4131df4b-b630-47a1-ab80-7ad5385fcd15"
 8 deploy_request = {
 9   "type": "IN_VANTAGE",
10   "datasetConnectionId": "11e1df4b-b630-47a1-ab80-7ad5385fcd8c",
11   "datasetTemplateId": "d8a35d98-21ce-47d0-b9f2-00d355777de1",
12   "args": {
13      "CRON": "0 0 1 * *"
14   }
15 }
16
17 job = trained_model_api.deploy(trained_model_id, deploy_request)
18
19 # wait until the job completes (if the job fails it will raise an exception)
20 job_api.wait(job['id'])

Import Model Version

Let’s assume we have a PMML model which we have trained in another data science platfrom. We want to import the artefacts for this version (model.pmml and data_stats.json) against a BYOM model f937b5d8-02c6-5150-80c7-1e4ff07fea31.

 1from aoa import AoaClient, TrainedModelApi, TrainedModelArtefactsApi, JobApi
 2import uuid
 3
 4client = AoaClient(project_id="23e1df4b-b630-47a1-ab80-7ad5385fcd8d")
 5trained_model_api = TrainedModelApi(aoa_client=client)
 6trained_model_artefacts_api = TrainedModelArtefactsApi(aoa_client=client)
 7job_api = JobApi(aoa_client=client)
 8
 9artefacts_import_id = uuid.uuid4()
10artefacts = ["model.pmml", "data_stats.json"]
11
12# first, upload the artefacts which we want to associate with the BYOM model version
13trained_model_artefacts_api.upload_artefacts(artefacts_import_id, artefacts)
14
15import_request = {
16    # tell the import job how to find the already uploaded artefacts so it can link them
17    "artefactImportId": str(artefacts_import_id),
18    "externalId": "my-byom-version-id"
19}
20
21job = model_api.import_byom(model["id"], import_request)
22
23# wait until the job completes (if the job fails it will raise an exception)
24job_api.wait(job["id"])
25
26# now you can list the artefacts which were uploaded and linked to the model version
27trained_model_id = job["metadata"]["trainedModel"]["id"]
28artefacts = trained_model_artefacts_api.list_artefacts(trained_model_id)