# kortical.app
Why can't I just use kortical.api
?
You can, but consider the scenario where a deployed app needs to retrieve its config. This would be the normal way to do it:
import yaml
from kortical.api.project import Project
from kortical.api.environment import Environment
project = Project.get_selected_project()
environment = Environment.get_selected_environment(project)
app_instance = environment.get_component_instance('my_test_app')
app_config = yaml.safe_load(app_instance.get_app_config())
That was a lot of work! Instead, we can use a function from kortical.app
which is streamlined for better usage inside a Kortical app:
from kortical.app import get_app_config
app_config = get_app_config(format='yaml')
Examples like this can be found across the Kortical app templates.
#
# get_app_config
This function returns the app config for your app in two different ways:
- If the app is being run locally, the app config is read from the file
app_config.yml
in your app folder. - If the app is deployed, it will retrieve its config from Kortical; everytime you deploy an app, the contents of your config file will be saved to the platform as part of a new app version.
Inputs
format
(= None
) - Load the config, typically injson
oryaml
format. Ignore this argument to get the raw text.
Returns
config
- a dictionary (or text if theformat
argument is not used).
from kortical.app import get_app_config
# Kortical templates come provided with an app_config.yml, so use yaml format here.
app_config = get_app_config(format='yaml')
#
# get_version
This function returns the version for an app instance.
No Inputs
Returns
version
- the version of the app instance. If the code is not being run inside an app instance, returnsNone
; if the code is run inside an app instance but is not a published version, returnsvNone
.
from kortical.app import get_version
version = get_version()
>>> print(version)
'v4'
# kortical.app.requests
This library is a light wrapper for the Python requests
library, and is designed for communication between Kortical/non-Kortical APIs.
#
# get
component_name
- The name of a Kortical component you want to interact with.component_type
- Used to specify whether we are communicating with an app or model.url
- If talking to a Kortical app, this is the section of the URL after the app name.params
- Any additional parameters.project_id
(= None
) - The project in which the code is running; if local, uses the currently selected project.environment_id
(= None
) - The environment in which the code is running; if local, uses the currently selected environment.**kwargs
- Any keyword arguments.
#
# put
component_name
- The name of a Kortical component you want to interact with.component_type
- Used to specify whether we are communicating with an app or model.url
- If talking to a Kortical app, this is the section of the URL after the app name.data
- Data that needs to be passed into the request.project_id
(= None
) - The project in which the code is running; if local, uses the currently selected project.environment_id
(= None
) - The environment in which the code is running; if local, uses the currently selected environment.**kwargs
- Any keyword arguments.
#
# head
component_name
- The name of a Kortical component you want to interact with.component_type
- Used to specify whether we are communicating with an app or model.url
- If talking to a Kortical app, this is the section of the URL after the app name.project_id
(= None
) - The project in which the code is running; if local, uses the currently selected project.environment_id
(= None
) - The environment in which the code is running; if local, uses the currently selected environment.**kwargs
- Any keyword arguments.
#
# post
component_name
- The name of a Kortical component you want to interact with.component_type
- Used to specify whether we are communicating with an app or model.url
- If talking to a Kortical app, this is the section of the URL after the app name.data
- Data that needs to be passed into the request.json
- json that needs to be passed into the request.project_id
(= None
) - The project in which the code is running; if local, uses the currently selected project.environment_id
(= None
) - The environment in which the code is running; if local, uses the currently selected environment.**kwargs
- Any keyword arguments.
#
# patch
component_name
- The name of a Kortical component you want to interact with.component_type
- Used to specify whether we are communicating with an app or model.url
- If talking to a Kortical app, this is the section of the URL after the app name.data
- Data that needs to be passed into the request.project_id
(= None
) - The project in which the code is running; if local, uses the currently selected project.environment_id
(= None
) - The environment in which the code is running; if local, uses the currently selected environment.**kwargs
- Any keyword arguments.
#
# delete
component_name
- The name of a Kortical component you want to interact with.component_type
- Used to specify whether we are communicating with an app or model.url
- If talking to a Kortical app, this is the section of the URL after the app name.project_id
(= None
) - The project in which the code is running; if local, uses the currently selected project.environment_id
(= None
) - The environment in which the code is running; if local, uses the currently selected environment.**kwargs
- Any keyword arguments.
#
# predict
component_name
- The name of a Kortical component you want to interact with.df
- A Pandas dataframe for which you want predictions.explain_predictions
(= False
) - Set this to true if you want explanations.explain_profile
- fast, accurate or exhaustive.project_id
(= None
) - The project in which the code is running; if local, uses the currently selected project.environment_id
(= None
) - The environment in which the code is running; if local, uses the currently selected environment.**kwargs
- Any keyword arguments.
import pandas as pd
from kortical.app import requests
test_df = pd.read_csv('data/test_data.csv')
df_out = requests.predict('nlp_classifier', test_df)