Python SDK

The Python version of The Ops Platform SDK works in conjunction with our Docker base images. The SDK allows the development of automations with rich user interfaces, that run in both the local terminal and in our Slack App as Slack Ops. Other than The Ops Platform itself, this SDK depends on:

  • Python 3.6+
  • The requests library, version 2+

Python SDK Installation

The Python installer can be found on PyPi here: https://pypi.org/project/cto-ai

It can be installed with this command:

pip install cto-ai

sdk.get_host_os

sdk.get_host_os() -> str

Returns the Operating System the host is running on. For remote ops, will return "unknown" as no host is accessible in the remote environment.

Output:

Host's os is: darwin

sdk.home_dir

sdk.home_dir() -> str

Returns the home directory of the host machine.

Output:

Host's home directory is: /root

sdk.log

sdk.log(args)

Logs to the console in in a standardized way. Will not be relayed to
the user in a remote environment (use ux.print for that).

Output:

I am a log!
I am too!

sdk.get_state_path

sdk.get_state_path() -> str

Returns the path of the state directory. The contents of this directory are persistent through a workflow, including on remote.

Output:

The state path is: /root/.config/@cto.ai/ops/superman/test-op/00000000-1111-2222-3333-444444444444

sdk.config.get

sdk.config.get(key: str) -> str

Gets the value that is saved under the given key in the team configuration store, or None if the key is not set.

sdk.config.set

sdk.config.set(key: str, value: str)

Sets the given value in the team configuration store under the provided key.

sdk.config.get_all

sdk.config.get_all() -> dict

Gets all of the keys and values in the team configuration store.

sdk.get_secret

sdk.get_secret(key: str) -> str

Requests a secret from the secret store with the given key.

If the secret exists, it is returned, printing a notification to the user that it has been accessed.

Otherwise, the user is prompted to provide a replacement, either from the secret store or by direct entry through their interface.

Example

from cto_ai import sdk

secret = sdk.get_secret('SECRET')
# `ux.print` hides secret values but `sdk.log` does not.
sdk.log(f'my secret is {secret}')

Output

my secret is SUPER_SECRET_VALUE

sdk.set_secret

sdk.set_secret(key: str, value: str) -> str

Sets a particular value into the secret store.

If the secret already exists, the user is prompted on whether to overwrite it.

Returns the key that the secret is set to, or null if the user declines to overwrite the existing value.

Example

from cto_ai import sdk, ux

key = sdk.set_secret("secret1", "it's a secret to everybody")
ux.print(key)

Output

secret1

sdk.track

sdk.track(tags, metadata): Promise<any>

Send an workflow events to The Ops Platform.

  • tags: (String || String[]) Tags for the event you want to track
  • metaData: (Object) Data you want to be tracked

sdk.events

Note: This feature is coming soon.

sdk.events(team, filters): Promise<any>

Retrieve workflow events from The Ops Platform.

  • team: (String || String[]) The team you want to retrieve events for
  • filters: (Object) Filters for the events you want to retrieve