# kortical.api.app

This object represents an app on the platform. Within Kortical, an app is a program hosted on the platform designed to carry out a specific task (usually involving a predictive model).

The App class includes the following attributes:

  • id - The ID assigned to the app upon creation.
  • name - The name of the app.
  • default_version - The default version that will be used if you add the app to an environment by name (e.g v1, v2).
  • created_by - User that created the app.
  • created - Time of creation.

In the Kortical CLI, you can view this by running:

>>> kortical app version list

Apps deployed to Kortical:
+----+------------------+-----------------+----------------------------+---------------------+
| id |       name       | default_version |         created_by         |       created       |
+====+==================+=================+============================+=====================+
| 2  | web_app          | None            | owen.saldanha@kortical.com | 2023/06/05 10:23:08 |
+----+------------------+-----------------+----------------------------+---------------------+
| 3  | tax_chatbot      | None            | owen.saldanha@kortical.com | 2023/06/05 10:57:48 |
+----+------------------+-----------------+----------------------------+---------------------+
| 6  | test-app         | None            | owen.saldanha@kortical.com | 2023/06/05 14:24:43 |
+----+------------------+-----------------+----------------------------+---------------------+

# Apps

#

# list


This function returns a list of apps that have been deployed to Kortical.

No Inputs

Returns

  • [App, ...] - A list of App objects.
from kortical.api.app import App

apps = App.list()

#

# get_app


This function returns the specified app from Kortical.

Inputs

  • app_name_or_id - Name or ID of the app you want.

Returns

  • App - An App object, None if it does not exist.
from kortical.api.app import App

web_app = App.get_app('document_tagger')

#

# create_app


WARNING

This function does not create any versions or instances; we recommend you use App.deploy_app() instead.

This function creates a new app in Kortical.

Inputs

  • app_name - Name of the new app you want to create.

Returns

  • App - An App object.
from kortical.api.app import App

new_app = App.create_app('my_new_app')

#

# deploy_app


This function deploys a new app instance to your selected environment. Behind the scenes, the following steps happen:

  1. The app's Docker images are built and pushed to Kortical.
  2. A new version of the app is created.
  3. A new app instance is created in the selected environment.

Inputs

  • app_name - Name of the app you want to deploy; these are the names of the files in the k8s folder of your repository. You can also specify 'all' to deploy everything.

  • app_directory (= None) - If not currently in the root of your app folder, you can specify the path here.

  • environment (= None) - An Environment object, specifying where you want the app to be deployed; by default, this is your currently selected environment.

Returns

  • None
from kortical.api.environment import Environment
from kortical.api.app import App

app_directory = 'Users/darth-vader/git/apps/web_app'
current_environment = Environment.get_selected_environment()

# Deploy app
App.deploy_app('web_app', app_directory=app_directory, environment=current_environment)

#

# delete


This function deletes an app (and all of its versions) from Kortical. You will not be able to delete an app until all of its instances have been removed across all Kortical projects.

No Inputs

Returns

  • None
from kortical.api.app import App

# Get app, then delete
web_app = App.get_app('document_tagger')
web_app.delete()

# Creating an app folder

#

# list_templates


This function returns a list of app template names, which you can use to create a new codebase.

No Inputs

Returns

  • [template_name_1, ...] - A list of app template names.
from kortical.api.app import App

templates = App.list_templates()

>>> print(templates)
['web_app_template', 'openai_llm_template', etc...]

#

# create_app_folder_from_template


This function creates a new codebase; you should do this whenever you want to create a new Git repository.

Inputs

  • app_name - The name of your new codebase/app.
  • template_name - The name of the template from which you want to create your app; see list_templates above for a list of options.
  • target_directory (= None) - Location where you want to create your app; by default, this is the current working directory.

Returns

  • None
from kortical.api.app import App

App.create_app_from_template('new_app', template_name='openai_llm_template')

# App versions

TIP

See kortical.api.app_version for more information.

#

# list_versions


This function returns a list of versions for the specified app; an app version is created every time you deploy code to Kortical, version numbers are assigned automatically on a merge to master.

No Inputs

Returns

  • [AppVersion, ...] - A list of AppVersion objects.
from kortical.api.app import App

# Get app, then list versions
web_app = App.get_app('document_tagger')
model_versions = web_app.list_versions()

#

# get_version


This function gets the specified version of the app.

Inputs

  • version_name_or_id - The name or ID of the version to select; names (e.g v1, v2) only apply to app versions that have actually been assigned a number (see app.set_default_version below).

Returns

  • AppVersion - An AppVersion object.
from kortical.api.app import App

# Get app, then get version
web_app = App.get_app('document_tagger')
web_app_v2 = web_app.get_version('v2')

#

# create_version


WARNING

This function does not create any instances; we recommend you use App.deploy_app() instead.

This function creates a new app version.

Inputs

  • k8s_config - Kubernetes config (read from the file in your app's k8s folder).
  • app_config - App config (read from the file in your app's config folder).

Returns

  • AppVersion - An AppVersion object.
from kortical.api.app import App

# Inside the root oof an app folder...
with open('k8s/web_app.yml', 'r') as f:
    k8s_config = f.read()
with open('config/app_config.yml', 'r') as f:
    app_config = f.read()

web_app = App.get_app('document_tagger')
new_app_version = web_app.create_app_version('web_app', k8s_config, app_config)

#

# set_default_version


This function assigns a version number to an app version, and sets it as the default version; this means you can add the app to an environment without having to specify the version again.

Inputs

  • app_version - An AppVersion object.

Returns

  • AppVersion - A new AppVersion object; this will contain a version number if one didn't exist previously.
from kortical.api.app import App

# Get app, then get version
web_app = App.get_app('document_tagger')
web_app_latest_version = web_app.get_version(47)

# Set default version
web_app.set_default_version(web_app_latest_version)

#

# delete_version


This function deletes an app version from Kortical. You will not be able to delete an app version until all of its instances have been removed across all Kortical projects.

Inputs

  • app_version - An AppVersion object.

Returns

  • None
from kortical.api.app import App

# Get app, then get version
web_app = App.get_app('document_tagger')
web_app_v2 = web_app.get_version(25)

# Delete
web_app.delete_version(web_app_v2)