aisquared.platform package

Submodules

aisquared.platform.AISquaredAPIException module

exception aisquared.platform.AISquaredAPIException.AISquaredAPIException[source]

Bases: Exception

aisquared.platform.AISquaredPlatformClient module

class aisquared.platform.AISquaredPlatformClient.AISquaredPlatformClient(use_port: bool = False)[source]

Bases: object

Client for interacting with the AI Squared platform programmatically

When using the client for the first time, it is important to run the client.login() method. When doing so, the client will ask for any required information interactively.

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> # If you have never logged in before, run the following code:
>>> client.login()
>>> # Test connection
>>> client.test_connection()
True
add_users_to_group(group_id: str, user_ids: list, port: int = 8086, use_port: bool | None = None) bool[source]

Add users to a group

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.add_users_to_group('group_id', ['user_id_1', 'user_id_2'])
True
Parameters:
  • group_id (str) – The group to add the users to

  • user_ids (list of str) – The IDs of the users to add

  • port (int (default 8086)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

success – Returns True if operation was successful

Return type:

bool

property base_url: str

The base URL associated with the client

create_group(display_name: str, role_id: str, port: int = 8086, use_port: bool | None = None) dict[source]

Create a group in the platform

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.create_group(
    'group display name',
    'role_id'
)
*dictionary containing group information*
Parameters:
  • display_name (str) – The display name of the group

  • role_id (str) – The role ID for the group

  • port (int (default 8086)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

group_info – Metadata about the created group

Return type:

dict

create_user(user_name: str, given_name: str, family_name: str, email: str, role_id: str, active: bool = True, middle_name: str | None = None, company_id: str | None = None, password: str | None = None, port: int = 8085, use_port: bool | None = None) dict[source]

Create a user within the platform

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.create_user(
    'user name',
    'given_name',
    'family_name',
    'user_email',
    'role_id'
)
*Dictionary with user information*
Parameters:
  • user_name (str) – The display name of the user

  • given_name (str) – The user’s first name

  • family_name (str) – The user’s last name

  • email (str) – The user’s email

  • role_id (str) – The ID of the role to be given to the user

  • active (bool (default True)) – Whether the user is active

  • middle_name (str or None (default None)) – The user’s middle name

  • company_id (str or None (default None)) – The user’s company ID

  • password (str or None (default None)) – The user’s password

  • port (int (default 8085)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

user_data – Metadata about the user

Return type:

dict

delete_group(group_id, port=8086, use_port: bool | None = None) bool[source]

Delete a group from the platform

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.delete_group('group_id')
True
Parameters:
  • group_id (str) – The ID of the group to delete

  • port (int (default 8086)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

result – Returns True if successful

Return type:

bool

delete_model(id: str, port: int = 8080, use_port: bool | None = None) bool[source]

Delete a model

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.delete_model('model_id')
True
Parameters:
  • id (str) – The ID for the model

  • port (int (default 8080)) – The API port for the model. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

success – Whether the action was successful

Return type:

bool

delete_user(user_id: str, port: int = 8085, use_port: bool | None = None) bool[source]

Delete a user from the system

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.delete_user('user_id')
True
Parameters:
  • user_id (str) – The user’s ID

  • port (int (default 8085)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

result – Returns True if the call is successful

Return type:

bool

get_group(group_id: str, port: int = 8086, use_port: bool | None = None) dict[source]

Retrieve information about a group

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.get_group('group_id')
*dictionary containing group data*
Parameters:
  • group_id (str) – The ID of the group requested

  • port (int (default 8086)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

group_info – The information about the group

Return type:

dict

get_group_id_by_name(group_name: str, port: int = 8083, use_port: bool | None = None) str[source]

Get the ID of a group by searching for its display name

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.get_group_id_by_name('Group Name')
*group_id*
Parameters:
  • group_name (str) – The display name of the group

  • port (int (default 8083)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

group_id – The ID of the group

Return type:

str

get_model(id: str, port: int = 8080, use_port: bool | None = None) dict[source]

Retrieve a model configuration

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.get_model('model_id')
*JSON Response including model data and metadata*
Parameters:
  • id (str) – The ID for the model

  • port (int (default 8080)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

model – Metadata about the model coupled with the model’s configuration information

Return type:

dictionary

get_model_id_by_name(model_name: str, port: int = 8080, use_port: bool | None = None) str[source]

Retrieve a model’s ID using the name of the model

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.get_model_id_by_name('my_awesome_model')
*model_id*
Parameters:
  • model_name (str) – The name of the model

  • port (int (default 8080)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

model_id – The model’s ID

Return type:

str

get_role_id_by_role_name(role_name: str, port: int = 8086, use_port: bool | None = None) str[source]

Get the ID of a role by searching for its display name

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.get_role_id_by_role_name('Role Name')
*role_id*
Parameters:
  • role_name (str) – The name of the role

  • port (int (default 8086)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

role_id – The ID of the role

Return type:

str

get_user(user_id: str, port: int = 8085, use_port: bool | None = None) dict[source]

Retrieve a user’s information from the platform

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.get_user('user_id')
*dictionary with results*
Parameters:
  • user_id (str) – The ID of the user

  • port (int (default 8085)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

user_info – The information about the user

Return type:

dict

get_user_id_by_name(name: str, port: int = 8080, use_port: bool | None = None) str[source]

Get a user’s ID from their display name

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.get_user_id_by_name('User Name')
*user_id*
Parameters:
  • name (str) – The display name of the user

  • port (int (default 8080)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

id – The ID of the user

Return type:

str

property headers

Headers used for authentication with the AI Squared Platform

list_group_users(group_id: str, as_df: bool = True, port: int = 8083, use_port: bool | None = None) DataFrame | dict[source]

List users in a group

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.list_group_users('group_id')
*DataFrame with results*
Parameters:
  • group_id (str) – The ID for the group

  • as_df (bool (default True)) – Whether to return the response as a pandas DataFrame

  • port (int (default 8083)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

users – The response from the API

Return type:

pandas DataFrame or dictionary

list_groups(max_count: int = 100, as_df: bool = True, port: int = 8083, use_port: bool | None = None) DataFrame | dict[source]

List all groups

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.list_groups()
*DataFrame with results*
Parameters:
  • max_count (int (default 100)) – The maximum number of groups to return

  • as_df (bool (default True)) – Whether to return the result as a pandas DataFrame

  • port (int (default 8083)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

groups – The response from the API

Return type:

pandas DataFrame or dictionary

list_model_feedback(model_id: str, limit: int = 10, as_df: bool = True, port: int = 8080, use_port: bool | None = None) dict | DataFrame[source]

List feedback on a model

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.list_model_feedback('model_id')
*DataFrame with Results*
Parameters:
  • model_id (str) – The ID of the model

  • limit (int (default 10)) – The maximum number of feedback items to return

  • port (int (default 8080)) – The API port to use. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

feedback – The feedback

Return type:

dict or pandas DataFrame

list_model_prediction_feedback(model_id: str, as_df: bool = True, port: int = 8080, use_port: bool | None = None) dict | DataFrame[source]

List all feedback for a model

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.list_model_prediction_feedback('model_id')
*DataFrame with Results*
Parameters:
  • model_id (str) – The ID of the model requested

  • as_df (bool (default True)) – Whether to return the results as a pandas DataFrame

  • port (int (default 8080)) – The API port to use. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

results – The results from the platform

Return type:

dict or pandas DataFrame

list_model_usage_metrics(model_id: str, period: str = 'hourly', as_df: bool = True, port: int = 8080, use_port: bool | None = None) dict | DataFrame[source]

Get usage metrics for a model

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.get_model_usage_metrics('model_id')
*DataFrame with results*
Parameters:
  • model_id (str) – The ID of the model

  • period (str (default 'hourly')) – The period to group metrics into

  • as_df (bool (default True)) – Whether to return results as a pandas DataFrame

  • port (int (default 8080)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

results – The results from the platform

Return type:

pandas DataFrame or dict

list_model_users(id: str, as_df: bool = True, port: int = 8080, use_port: bool | None = None) DataFrame | dict[source]

List users for a model

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.list_model_users('model_id')
*DataFrame with results*
Parameters:
  • id (str) – The ID for the model

  • as_df (bool (default True)) – Whether to return the response as a Pandas DataFrame

  • port (int (default 8080)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

model_users – The users for the model

Return type:

pandas DataFrame or dictionary

list_models(as_df: bool = True, port: int = 8080, use_port: bool | None = None) DataFrame | dict[source]

List models within the platform

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.list_models()
*DataFrame with results*
Parameters:
  • as_df (bool (default True)) – Whether to return the response as a pandas DataFrame

  • port (default None) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

models – The models

Return type:

pandas DataFrame or dictionary

list_prediction_feedback(prediction_id: str, as_df: bool = True, port: int = 8080, use_port: bool | None = None) DataFrame | dict[source]

List prediction feedback given a prediction ID

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.list_prediction_feedback('prediction_id')
*DataFrame with results*
Parameters:
  • prediction_id (str) – The prediction ID

  • as_df (bool (default True)) – Whether to return the results as a pandas DataFrame

  • port (int (default 8080)) – The API port to use. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

results – The results from the platform

Return type:

pandas DataFrame or dict

list_roles(as_df: bool = True, port: int = 8086, use_port: bool | None = None) DataFrame | dict[source]

List the roles available in the platform

Example usage:

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.list_roles()
*DataFrame with results*
Parameters:
  • as_df (bool (default True)) – Whether to return the results as a pandas DataFrame

  • port (int (default 8086)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

roles – The roles

Return type:

pandas DataFrame or dict

list_user_usage_metrics(user_id: str, period: str = 'hourly', as_df: bool = True, port: int = 8080, use_port: bool | None = None) dict | DataFrame[source]

Get usage metrics for a user

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.get_user_usage_metrics('user_id')
*DataFrame with results*
Parameters:
  • user_id (str) – The ID of the user

  • period (str (default 'hourly')) – The period to group metrics into

  • as_df (bool (default True)) – Whether to return results as a pandas DataFrame

  • port (int (default 8080)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

results – The results from the platform

Return type:

pandas DataFrame or dict

list_users(max_count: int = 100, as_df: bool = True, port: int = 8080, use_port: bool | None = None) DataFrame | dict[source]

List all users

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.list_users()
*DataFrame with results*
Parameters:
  • max_count (int (default 100)) – The maximum number of users to return

  • as_df (bool (default True)) – Whether to return the data as a Pandas DataFrame

  • port (int (default 8080)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

users – The response from the API

Return type:

pandas DataFrame or dictionary

login(url: str | None = None, port: int = 8080, username: str | None = None, password: str | None = None, use_port: bool | None = None) None[source]

Log in to the platform programmatically. If no url, username, or password are provided, logs in interactively

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.login()
Enter URL: https://platform.squared.ai
Enter Username: your.email@your_domain.com
Enter Password: <hidden>
Parameters:
  • url (str or None (default None)) – The URL for the platform API

  • port (int or None (default 8080)) – The API port for the call. This can be handled automatically by the platform ALB

  • username (str or None (default None)) – The username

  • password (str or None (default None)) – The password

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

property password: str

The password associated with the client

remove_users_from_group(group_id: str, user_ids: list, port: int = 8086, use_port: bool | None = None) bool[source]

Remove users from a group

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.remove_users_from_group('group_id', ['user_id_1', 'user_id_2'])
True
Parameters:
  • group_id (str) – The ID of the group

  • user_ids (list of str) – The IDs of the users to remove

  • port (int (default = 8086)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

success – Returns True if successful

Return type:

bool

share_model_with_group(model_id: str, group_id: str, port: int = 8080, use_port: bool | None = None) bool[source]

Share a model with a group

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.share_model_with_group('model_id', 'group_id')
True
Parameters:
  • model_id (str) – The ID for the model to be shared

  • group_id (str) – The ID for the group to be shared with. This can be handled automatically by the platform ALB

  • port (int (default 8080)) – The API port to use. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

success – Returns True if successful

Return type:

bool

share_model_with_user(model_id: str, user_id: str, port: int = 8080, use_port: bool | None = None) bool[source]

Share a model with a user

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.share_model_with_user('model_id', 'user_id')
True
Parameters:
  • model_id (str) – The ID for the model

  • user_id (str) – The ID for the user

  • port (int (default 8080)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

success – Whether the action was successful

Return type:

bool

test_connection(port: int = 8080, use_port: bool | None = None) bool[source]

Test whether there is a healthy connection to the platform

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.test_connection()
True
Parameters:
  • port (int (default 8080)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

success – True if connection was successful

Return type:

bool

property token: str

The token associated with the client

unshare_model_with_group(model_id: str, group_id: str, port: int = 8080, use_port: bool | None = None) bool[source]

Unshare a model with a group

>>> import aisquared
>>> client = aisquared.client.AISquaredPlatformClient()
>>> client.unshare_model_with_group('model_id', 'group_id')
True
Parameters:
  • model_id (str) – The ID of the model

  • group_id (str) – The ID of the group

  • port (int (default 8080)) – The API port to use. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

success – Returns True if successful

Return type:

bool

unshare_model_with_user(model_id: str, user_id: str, port: int = 8080, use_port: bool | None = None) bool[source]

Unshare a model with a user

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.unshare_model_with_user('model_id', 'user_id')
True
Parameters:
  • model_id (str) – The ID for the model

  • user_id (str) – The ID for the user

  • port (int (default 8080)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

success – Whether the action was successful

Return type:

bool

update_group(group_id: str, display_name: str, role_id: str, port: int = 8086, use_port: bool | None = None) bool[source]

Update information about a group

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.update_group(
    'group_id',
    'group display name',
    'role_id'
)
True
Parameters:
  • group_id (str) – The ID of the group to update

  • display_name (str) – The display name of the group

  • role_id (str) – The ID of the role for the group

  • port (int (default 8086)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

success – Returns True if successful

Return type:

bool

update_user(user_id: str, user_name: str, given_name: str, family_name: str, email: str, role_id: str, active: bool = True, middle_name: str | None = None, company_id: str | None = None, password: str | None = None, port: int = 8085, use_port: bool | None = None) bool[source]

Update information about a user

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.update_user(
    'user_id',
    'user name',
    'given_name',
    'family_name',
    'user_email',
    'role_id'
)
True
Parameters:
  • user_id (str) – The ID of the user to update

  • user_name (str) – The display name of the user

  • given_name (str) – The first name of the user

  • family_name (str) – The last name of the user

  • email (str) – The user’s email

  • role_id (str) – The ID of the user’s role

  • active (bool (default True)) – Whether the user is active

  • middle_name (str or None (default None)) – The user’s middle name

  • company_id (str or None (default None)) – The user’s company ID

  • password (str or None (default None)) – The user’s password

  • port (int (default 8085)) – The API port for the call. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

success – Returns True if update is successful

Return type:

bool

upload_model(model_file: str, port: int = 8081, use_port: bool | None = None) str[source]

Upload a model to the platform

>>> import aisquared
>>> client = aisquared.platform.AISquaredPlatformClient()
>>> client.upload_model('my_model_filename.air')
True
Parameters:
  • model_file (path or path-like) – The path to the model file

  • port (int (default 8081)) – The API port to use. This can be handled automatically by the platform ALB

  • use_port (bool or None (default None)) – Whether to use port in URL formatting. If None, defaults to class value

Returns:

successful – Whether the action was successful

Return type:

bool

property use_port
property username: str

The username associated with the client

aisquared.platform.DatabricksAPIException module

exception aisquared.platform.DatabricksAPIException.DatabricksAPIException[source]

Bases: Exception

aisquared.platform.DatabricksClient module

class aisquared.platform.DatabricksClient.DatabricksClient[source]

Bases: object

Client for working with a connected Databricks environment

When using the client for the first time, it is important to authenticate the client using the client.login() method. When doing so, the client will ask for any required information interactively.

>>> import aisquared
>>> client = aisquared.platform.DatabricksClient()
>>> # If you have never logged in before, run the following code:
>>> client.login()
>>> # Interactive session requesting required information
property base_url: str

The base URL for the workspace

create_compute(compute_name: str, spark_version: str, node_type_id: str) dict[source]

Create a compute resource

Parameters:
  • compute_name (str) – The name of the compute to create

  • spark_version (str) – The spark version to use for the compute resource

  • node_type_id (str) – The node type ID to use

Returns:

compute_info – The information about the created compute resource

Return type:

dict

create_job(job_name: str, tasks: list, libraries: list, compute_name: str, spark_version: str, node_type_id: str, cron_syntax: str | None = None, timezone: str | None = None) bool[source]

Create a job using notebooks and/or scripts in the workspace

Parameters:
  • job_name (str) – The name for the job

  • tasks (list of dict) – List of {task_name : task_script} dictionary pairs to run in the job

  • libraries (list of str) – The dependent libraries to install on all compute

  • compute_name (str) – The name of the compute to provision specifically for this job

  • spark_version (str) – The version of Spark to use on the compute instances

  • node_type_id (str) – The node type to use

  • cron_syntax (str or None (default None)) – If the job is to be set to a schedule, the cron syntax for that schedule

  • timezone (str or None (default None)) – The timezone to set the schedule to, if cron syntax is provided

Returns:

success – Whether the create job call was successful

Return type:

bool

create_served_model(model_name: str, model_version: str, workload_size: str, scale_to_zero_enabled: bool = True, workload_type: str = 'CPU') dict[source]

Create a model serving endpoint

Parameters:
  • model_name (str) – The name of the model to serve

  • model_version (str) – The version of the model to serve

  • workload_size (str) – The workload size of the serving endpoint

  • scale_to_zero_enabled (bool (default True)) – Whether to allow for scaling the endpoint to zero

  • type (workload) – The workload type - either ‘CPU’ or ‘GPU’

Returns:

configuration – Configuration information about the serving endpoint

Return type:

dict

delete_compute(compute_id: str) bool[source]

Delete a compute resource in the workspace

Parameters:

compute_id (str) – The ID for the compute to delete

Returns:

success – Whether the operation was successful

Return type:

bool

delete_from_workspace(filename: str) bool[source]

Delete a file from the workspace

Parameters:

filename (str) – The name of the file to delete

Returns:

success – Whether the operation is successful

Return type:

bool

delete_job(job_id: str) bool[source]

Delete a job from the workspace

Parameters:

job_id (str) – The ID of the job to delete

Returns:

success – Whether the delete operation was successful

Return type:

bool

delete_registered_model(model_name: str) bool[source]

Delete a registered model

Parameters:

model_name (str) – The name of the model to delete

Returns:

success – Whether the delete operation was successful

Return type:

bool

delete_served_model(model_name: str) bool[source]

Delete a served model in the workspace

Parameters:

model_name (str) – The name of the model to delete

Returns:

success – Whether the delete operation was successful

Return type:

bool

download_from_workspace(filename: str) str[source]

Download a file from the workspace

Parameters:

filename (str) – The filename of the file to download

Returns:

contents – The contents of the file

Return type:

str

property headers: dict

API headers for calls to the API

list_compute(as_df: bool = True) dict | DataFrame[source]

List compute in the workspace

Parameters:

as_df (bool (default True)) – Whether to return a pandas DataFrame

Returns:

compute – The compute resources in the workspace

Return type:

dict or pd.DataFrame

list_jobs(as_df: bool = True) dict | DataFrame[source]

List all jobs in the workspace

Parameters:

as_df (bool (default True)) – Whether to return a pandas DataFrame

Returns:

jobs – The jobs that exist in the workspace

Return type:

dict or pandas DataFrame

list_registered_models(as_df: bool = True) dict | DataFrame[source]

List registered models in the workspace

Parameters:

as_df (bool (default True)) – Whether to return a pandas DataFrame

Returns:

models – The models in the workspace

Return type:

dict or pandas DataFrame

list_served_models(as_df: bool = True) dict | DataFrame[source]

List served models in the workspace

Parameters:

as_df (bool (default True)) – Whether to return results as a pandas DataFrame

Returns:

models – The models served in the workspace

Return type:

dict or pandas DataFrame

list_workspace(as_df: bool = True) DataFrame | dict[source]

List files in the connected Databricks workspace

Parameters:

as_df (bool (default True)) – Whether to return the results as a pandas DataFrame

Returns:

results – The files in the workspace

Return type:

dict or pd.DataFrame

login(url: str | None = None, username: str | None = None, token: str | None = None, persist: bool = True) None[source]

Log in to the Databricks environment programmatically

>>> import aisquared
>>> client = aisquared.platform.DatabricksClient()
>>> client.login()
Enter URL: {Databricks_workspace_url}
Enter Username: your.email@your_domain.com
Enter Secret Token: <hidden>
Parameters:
  • url (str or None (default None)) – The URL of the Databricks workspace

  • username (str or None (default None)) – The username in the Databricks workspace

  • token (str or None (default None)) – The secret token for the Databricks workspace

  • persist (bool (default True)) – Whether to persist the login information, eliminating the need to run this command again in the future

run_job(job_id: str) int[source]

Run a job

Parameters:

job_id (str) – The ID of the job to run

Returns:

run_id – The ID of the specific run that was created

Return type:

int

start_compute(compute_id: str) bool[source]

Start a compute resource

Parameters:

compute_id (str) – The ID of the compute to start

Returns:

success – Whether the start operation was successful

Return type:

bool

stop_compute(compute_id: str) bool[source]

Stop a compute resource

Parameters:

compute_id (str) – The ID of the compute to start

Returns:

success – Whether the stop operation was successful

Return type:

bool

property token: str

The token to use for the workspace

update_job(job_id: int, job_name: str, tasks: list, libraries: list, compute_name: str, spark_version: str, node_type_id: str, cron_syntax: str | None = None, timezone: str | None = None) bool[source]

Update a job by Job ID using notebooks and/or scripts in the workspace

Parameters:
  • job_id (int) – The unique identifier of the job to update

  • job_name (str) – The new name for the job

  • tasks (list of dict) – List of {task_name : task_script} dictionary pairs to run in the updated job

  • libraries (list of str) – The dependent libraries to install on all compute for the new job

  • compute_name (str) – The name of the compute to provision specifically for the new job

  • spark_version (str) – The version of Spark to use on the compute instances

  • node_type_id (str) – The node type to use

  • cron_syntax (str or None (default None)) – If the new job is to be set to a schedule, the cron syntax for that schedule

  • timezone (str or None (default None)) – The timezone to set the schedule to, if cron syntax is provided

Returns:

success – Whether the update job call was successful

Return type:

bool

upload_to_workspace(filename: str, overwrite: bool = False) bool[source]

Upload a file to the workspace

Parameters:
  • filename (str) – The name of the file to upload

  • overwrite (bool (default False)) – Whether to overwrite the file if one of the same name already exists in the workspace

Returns:

success – Whether the upload was successful

Return type:

bool

property username: str

The user’s username

aisquared.platform.NoResultsFoundError module

exception aisquared.platform.NoResultsFoundError.NoResultsFoundError[source]

Bases: Exception

aisquared.platform.additional_utils module

aisquared.platform.crudl module

aisquared.platform.feedback module

aisquared.platform.metrics module

aisquared.platform.sharing module

aisquared.platform.user_group module

Module contents

Utilities for interacting with the AI Squared Platform.

The primary class within this subpackage is the AISquaredPlatformClient class, which has the capabilities to interact with much of the functionality in the AI Squared platform. For more information about this class, please see its documentation.