Cortex Python Builders Reference¶
Builder Factory¶
-
class
cortex_builders.builder_factory.
BuilderFactory
(client)¶ Builds component builders.
-
action
(name: str, camel_version='1.0.0')¶ Creates an ActionBuilder with the given name.
- Parameters
name – name of the action builder. The name must provide at least one cortex namespace identifier and a resource name.
-
connection
(name: str, camel_version='1.0.0') → cortex_builders.connection_builder.ConnectionBuilder¶ Creates a connection with the given name.
- Parameters
name – name of the connection builder. The name must provide at least one cortex namespace identifier and a resource name.
-
dataset
(name: str, camel_version='1.0.0') → cortex_builders.dataset_builder.DatasetBuilder¶ Creates a DatasetBuilder with the given name.
Example
>>> builder = cortex.builder() >>> train_df = pd.read_csv(' <path to data as csv file>') >>> train_ds = builder.dataset('<cortex name space>/<dataset name>').from_df(train_df).build()
- Parameters
name – name of the dataset builder. The name must provide at least one cortex namespace identifier and a resource name.
-
pipeline
(name: str)¶ Creates a pipeline with the given name.
- Parameters
name – name of the pipeline
-
schema
(name: str, camel_version='1.0.0')¶ Creates a SchemaBuilder with the given name.
- Parameters
name – name of the schema builder
-
skill
(name: str, camel_version='1.0.0') → cortex_builders.skill_builder.SkillBuilder¶ Creates a SkillBuilder with the given name.
- Parameters
name – name of the skill builder. The name must provide at least one cortex namespace identifier and a resource name.
-
Builders¶
Connection Builder¶
-
class
cortex_builders.connection_builder.
ConnectionBuilder
(name: str, client: cortex.connection.ConnectionClient, camel='1.0.0')¶ A builder utility to aid in programmatic creation of Cortex Connections. Not meant to be directly instantiated by clients.
-
allow_write
(allow_write: bool = True)¶ Sets the allow_write property of the connection.
- Parameters
description – boolean value for the coonection to allow_write
- Returns
the builder instance
-
build
() → cortex.connection.Connection¶ Builds and saves a Connection using the properties configured on the builder
- Returns
the resulting Connection
-
connection_type
(connection_type: str)¶ Sets the connection_type property of a connection.
- Parameters
connection_type – Type of a connection
- Returns
the builder instance
-
description
(description: str)¶ Sets the description property of the Connection.
- Parameters
description – the human friendly long description of the Connection
- Returns
the builder instance
-
params
(name: str, value: str)¶ Adds a Connection parameter.
- Parameters
name – Parameter Name
value – Parameter Value
- Returns
Adds a Connection tags.
:param label:Parameter Label :param value :return:
-
title
(title: str)¶ Sets the title property of the Connection.
- Parameters
title – the human friendly name of the Connection
- Returns
the builder instance
-
Dataset Builder¶
-
class
cortex_builders.dataset_builder.
DatasetBuilder
(name: str, client: cortex.dataset.DatasetsClient, camel='1.0.0')¶ A builder utility to aid in programmatic creation of Cortex datasets; not meant to be directly instantiated by clients.
-
build
() → cortex.dataset.Dataset¶ Builds and saves a dataset using the properties configured on the builder.
- Returns
the resulting dataset
-
create_schema
(name: str, title: str = None, description: str = None)¶ Creates or replaces a schema (type) based on the message parameters set in the builder once the build is called. The Cortex dataset refers to this schema rather than embedding the parameters inline.
- Parameters
name – the resource name of the new schema
title – human-readable display name
description – human-readable long description
- Returns
the builder instance
-
description
(description: str)¶ Sets the description property of the dataset.
- Parameters
description – The human-readable long description of the dataset.
- Returns
The builder instance.
-
from_csv
(file_name, **kwargs)¶ Creates a dataset from a csv file.
- Parameters
file_name – name of the file
kwargs – optional key-value dictionary of parameters to pass to pandas on creation
-
from_dataset
(ds: cortex.dataset.Dataset)¶ Creates a dataset builder from a given dataset.
- Parameters
ds – dataset to use in creation of this builder
-
from_df
(df, format='json')¶ Sets the content of the dataset to the provided pandas dataframe. The datarrame is serialized and uploaded to the Cortex Managed Content service in the specified path.
- Parameters
df – the pandas dataframe to use
format – ‘json’ or ‘csv’
- Returns
the builder instance
-
from_json
(file_name, **kwargs)¶ Creates a dataset from a json file.
- Parameters
file_name – name of the file
kwargs – optional key-value dictionary of parameters to pass to pandas on creation
-
parameters
(parameters: list)¶ Sets the parameters property of the dataset.
- Parameters
parameters – The parameters to associate with the dataset.
- Returns
The builder instance.
-
title
(title: str)¶ Sets the title property of a dataset.
- Parameters
title – the human-readable name of the dataset.
- Returns
the builder instance.
-
to_camel
()¶ Creates a dataset with the builder’s CAMEL definitions.
-
Action Builder¶
-
class
cortex_builders.action_builder.
ActionBuilder
(name: str, client: cortex.action.ActionClient, camel='1.0.0')¶ Builds an action, the computional part of a skill.
-
build
(**kwargs) → Optional[cortex.action.Action]¶ Builds an action.
- Returns
An action, or none, if the dry-run flag is set
-
daemon
()¶ Sets the action to type: daemon.
-
from_image
(image: str)¶ Sets the Docker image name.
- Parameters
name – name of the docker image
-
from_model
(model, model_type='sklearn', x_pipeline=None, y_pipeline=None, target='y')¶ Associates a model with this ActionBuilder.
-
from_setup
(setup_script: str, action_module: str, function_name: str = 'main')¶ Builds an action from a source archive built using Python Setuptools; builds the source distribution using the Setuptools sandbox.
- Parameters
setup_script – path to setup.py script
action_module – full path to the Python module containing the action: function
function_name – name of the function to import and invoke, default is ‘main’
- Returns
the builder instance
-
from_source
(source_str: str, function_name: str = 'main')¶ Builds an action from source code. NOTE: The Python source code must contain a function with the specified name.
- Parameters
source_str – Python source code string
function_name – name of the function to invoke, default is ‘main’
- Returns
the builder instance
-
from_source_file
(file_path: str, function_name: str = 'main')¶ Builds an action from a source file. NOTE: The Python source code must contain a function with the specified name.
- Parameters
file_path – path to a file containing Python source code
function_name – name of the function to invoke, default is ‘main’
- Returns
the builder instance
-
image_prefix
(prefix)¶ Adds a path definition prefix to the Docker image name; ignored when the ‘registry’ property is set.
- Parameters
prefix – prefix to use with the Docker image
-
job
()¶ Sets the action to type: job.
-
kind
(kind: str)¶ Sets the kind of action, either “python:3” or “python:2”.
-
property
name
¶ Gets the name for the ActionBuilder
-
registry
(registry_uri: str)¶ Sets the Docker registry URI.
-
with_base_image
(base_image)¶ Sets the base image to use for the Action container.
- Parameters
base_image – a valid image name for an image that is accessible on the machine this builder is run.
-
with_conda_requirements
(requirements: list)¶ Sets conda requirements for this ActionBuilder to the given list.
- Parameters
requirements – a list of requirements
-
with_pip_freeze
()¶ Sets the requirements for this ActionBuilder with pip freeze.
-
with_requirements
(requirements: list)¶ Sets requirements for this ActionBuilder to the given list.
- Parameters
requirements – a list of requirements
-
Dataset Builder¶
-
class
cortex_builders.dataset_builder.
DatasetBuilder
(name: str, client: cortex.dataset.DatasetsClient, camel='1.0.0') A builder utility to aid in programmatic creation of Cortex datasets; not meant to be directly instantiated by clients.
-
build
() → cortex.dataset.Dataset Builds and saves a dataset using the properties configured on the builder.
- Returns
the resulting dataset
-
create_schema
(name: str, title: str = None, description: str = None) Creates or replaces a schema (type) based on the message parameters set in the builder once the build is called. The Cortex dataset refers to this schema rather than embedding the parameters inline.
- Parameters
name – the resource name of the new schema
title – human-readable display name
description – human-readable long description
- Returns
the builder instance
-
description
(description: str) Sets the description property of the dataset.
- Parameters
description – The human-readable long description of the dataset.
- Returns
The builder instance.
-
from_csv
(file_name, **kwargs) Creates a dataset from a csv file.
- Parameters
file_name – name of the file
kwargs – optional key-value dictionary of parameters to pass to pandas on creation
-
from_dataset
(ds: cortex.dataset.Dataset) Creates a dataset builder from a given dataset.
- Parameters
ds – dataset to use in creation of this builder
-
from_df
(df, format='json') Sets the content of the dataset to the provided pandas dataframe. The datarrame is serialized and uploaded to the Cortex Managed Content service in the specified path.
- Parameters
df – the pandas dataframe to use
format – ‘json’ or ‘csv’
- Returns
the builder instance
-
from_json
(file_name, **kwargs) Creates a dataset from a json file.
- Parameters
file_name – name of the file
kwargs – optional key-value dictionary of parameters to pass to pandas on creation
-
parameters
(parameters: list) Sets the parameters property of the dataset.
- Parameters
parameters – The parameters to associate with the dataset.
- Returns
The builder instance.
-
title
(title: str) Sets the title property of a dataset.
- Parameters
title – the human-readable name of the dataset.
- Returns
the builder instance.
-
to_camel
() Creates a dataset with the builder’s CAMEL definitions.
-