Python API Reference
Clarifai Python SDK API Reference
This is the API Reference documentation extracted from the source code.
App
class App(url=None, app_id=None, user_id=None, base_url="https://api.clarifai.com", pat=None, token=None, root_certificates_path=None, **kwargs)
App is a class that provides access to Clarifai API endpoints related to App information.
Parameters:
url(str) - The URL to initialize the app objectapp_id(str) - The App ID for the App to interact withuser_id(str) - The user ID of the ownerbase_url(str) - Base API url. Default "https://api.clarifai.com"pat(str) - A personal access token for authentication. Can be set as env var CLARIFAI_PATtoken(str) - A session token for authentication. Can be set as env var CLARIFAI_SESSION_TOKENroot_certificates_path(str) - Path to the SSL root certificates file**kwargs- Additional keyword arguments:name(str) - The name of the appdescription(str) - The description of the app
App.create_concepts
App.create_concepts(concept_ids, concepts=[])
Add concepts to the app.
Parameters:
concept_ids(List[str]) - List of concept IDs to addconcepts(List[str]) - Optional list of concept names
Example:
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
app.create_concepts(concept_ids=["concept_id_1", "concept_id_2"])
App.create_concept_relations
App.create_concept_relations(subject_concept_id, object_concept_ids, predicates)
Creates concept relations between concepts of the app.
Parameters:
subject_concept_id(str) - The concept ID of the subject conceptobject_concept_ids(List[str]) - List of concept IDs of object conceptspredicates(List[str]) - List of predicates corresponding to each relation
Example:
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
app.create_concept_relations(
subject_concept_id="subject_concept_id",
object_concept_ids=["object_concept_id_1", "object_concept_id_2"],
predicates=["hypernym", "synonym"]
)
App.create_dataset
App.create_dataset(dataset_id, **kwargs)
Creates a dataset for the app.
Parameters:
dataset_id(str) - The dataset ID for the dataset to create**kwargs- Additional keyword arguments passed to the Dataset
Returns: Dataset - A Dataset object for the specified dataset ID
Example:
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
dataset = app.create_dataset(dataset_id="dataset_id")
App.create_model
App.create_model(model_id, **kwargs)
Creates a model for the app.
Parameters:
model_id(str) - The model ID for the model to create**kwargs- Additional keyword arguments passed to the Model
Returns: Model - A Model object for the specified model ID
Example:
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
model = app.create_model(model_id="model_id")
App.create_workflow
App.create_workflow(config_filepath, generate_new_id=False, display=True)
Creates a workflow for the app from a YAML config file.
Parameters:
config_filepath(str) - The path to the yaml workflow config filegenerate_new_id(bool) - If True, generate a new workflow ID. Default Falsedisplay(bool) - If True, display the workflow nodes tree. Default True
Returns: Workflow - A Workflow object for the specified workflow config
Example:
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
workflow = app.create_workflow(config_filepath="config.yml")
App.dataset
App.dataset(dataset_id, dataset_version_id=None, **kwargs)
Returns a Dataset object for the existing dataset ID.
Parameters:
dataset_id(str) - The dataset ID for the dataset to interact withdataset_version_id(str) - The version ID for the dataset version to interact with
Returns: Dataset - A Dataset object for the existing dataset ID
Example:
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
dataset = app.dataset(dataset_id="dataset_id")
App.delete_concept_relations
App.delete_concept_relations(concept_id, concept_relation_ids=[])
Delete concept relations of a concept of the app.
Parameters:
concept_id(str) - The concept ID of the concept to delete relations forconcept_relation_ids(List[str]) - Optional list of concept relation IDs to delete
Example:
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
app.delete_concept_relations(concept_id="concept_id", concept_relation_ids=["id_1", "id_2"])
App.delete_dataset
App.delete_dataset(dataset_id)
Deletes a dataset for the user.
Parameters:
dataset_id(str) - The dataset ID for the app to delete
Example:
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
app.delete_dataset(dataset_id="dataset_id")
App.delete_model
App.delete_model(model_id)
Deletes a model for the user.
Parameters:
model_id(str) - The model ID for the app to delete
Example:
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
app.delete_model(model_id="model_id")
App.delete_workflow
App.delete_workflow(workflow_id)
Deletes a workflow for the user.
Parameters:
workflow_id(str) - The workflow ID for the app to delete
Example:
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
app.delete_workflow(workflow_id="workflow_id")
App.get_input_count
App.get_input_count()
Get count of all the inputs in the app.
Returns: int - Count of inputs in the app
Example:
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
input_count = app.get_input_count()
App.inputs
App.inputs()
Returns an Inputs object for the app.
Returns: Inputs - An Inputs object
App.list_concepts
App.list_concepts(page_no=None, per_page=None)
Lists all the concepts for the app.
Parameters:
page_no(int) - The page number to listper_page(int) - The number of items per page
Yields: Concept - Concept objects in the app
Example:
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
all_concepts = list(app.list_concepts())
Note: Defaults to 16 per page if page_no is specified and per_page is not. If both are None, lists all resources.
App.list_datasets
App.list_datasets(page_no=None, per_page=None)
Lists all the datasets for the app.
Parameters:
page_no(int) - The page number to listper_page(int) - The number of items per page
Yields: Dataset - Dataset objects for the datasets in the app
Example:
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
all_datasets = list(app.list_datasets())
Note: Defaults to 16 per page if page_no is specified and per_page is not. If both are None, lists all resources.
App.list_models
App.list_models(filter_by={}, only_in_app=True, page_no=None, per_page=None)
Lists all the available models for the user.
Parameters:
filter_by(dict) - A dictionary of filters to apply to the list of modelsonly_in_app(bool) - If True, only return models that are in the app. Default Truepage_no(int) - The page number to listper_page(int) - The number of items per page
Yields: Model - Model objects for the models in the app
Example:
from clarifai.client.user import User
app = User(user_id="user_id").app(app_id="app_id")
all_models = list(app.list_models())
Note: Defaults to 16 per page if page_no is specified and per_page is not. If both are None, lists all resources.
App.list_pipeline_steps
App.list_pipeline_steps(pipeline_id=None, filter_by={}, only_in_app=True, page_no=None, per_page=None)
Lists all the pipeline steps for the user.
Parameters:
pipeline_id(str) - If provided, only list pipeline steps from this pipelinefilter_by(dict) - A dictionary of filters to apply to the listonly_in_app(bool) - If True, only return pipeline steps that are in the app. Default Truepage_no(int) - The page number to listper_page(int) - The number of items per page
Yields: PipelineStep - PipelineStep objects
Example:
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
all_pipeline_steps = list(app.list_pipeline_steps())
App.list_pipelines
App.list_pipelines(filter_by={}, only_in_app=True, page_no=None, per_page=None)
Lists all the pipelines for the user.
Parameters:
filter_by(dict) - A dictionary of filters to apply to the list of pipelinesonly_in_app(bool) - If True, only return pipelines that are in the app. Default Truepage_no(int) - The page number to listper_page(int) - The number of items per page
Yields: Pipeline - Pipeline objects
Example:
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
all_pipelines = list(app.list_pipelines())
App.list_trainable_model_types
App.list_trainable_model_types()
Lists all the trainable model types.
Returns: List[str] - List of all trainable model types
Example:
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
print(app.list_trainable_model_types())
App.list_workflows
App.list_workflows(filter_by={}, only_in_app=True, page_no=None, per_page=None)
Lists all the available workflows for the user.
Parameters:
filter_by(dict) - A dictionary of filters to apply to the list of workflowsonly_in_app(bool) - If True, only return workflows that are in the app. Default Truepage_no(int) - The page number to listper_page(int) - The number of items per page
Yields: Workflow - Workflow objects for the workflows in the app
Example:
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
all_workflows = list(app.list_workflows())
Note: Defaults to 16 per page if page_no is specified and per_page is not. If both are None, lists all resources.
App.model
App.model(model_id, model_version={'id': ""}, **kwargs)
Returns a Model object for the existing model ID.
Parameters:
model_id(str) - The model ID for the model to interact withmodel_version(Dict) - The model version ID for the model version to interact with
Returns: Model - A Model object for the existing model ID
Example:
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
model_v1 = app.model(model_id="model_id", model_version={"id": "model_version_id"})
App.patch_dataset
App.patch_dataset(dataset_id, action='merge', **kwargs)
Patches a dataset for the app.
Parameters:
dataset_id(str) - The dataset ID for the dataset to patchaction(str) - The action to perform: merge/overwrite/remove. Default 'merge'**kwargs- Additional keyword arguments to patch the Dataset
Returns: Dataset - A Dataset object for the specified dataset ID
App.patch_model
App.patch_model(model_id, action='merge', **kwargs)
Patches a model of the app.
Parameters:
model_id(str) - The model ID of the model to patchaction(str) - The action to perform: merge/overwrite/remove. Default 'merge'**kwargs- Additional keyword arguments to patch the Model
Returns: Model - A Model object of the specified model ID
App.patch_workflow
App.patch_workflow(workflow_id, action='merge', config_filepath=None, **kwargs)
Patches a workflow of the app.
Parameters:
workflow_id(str) - The Workflow ID of the workflow to patchaction(str) - The action to perform: merge/overwrite/remove. Default 'merge'config_filepath(str) - The path to the yaml workflow config file**kwargs- Additional keyword arguments to patch the Workflow
Returns: Workflow - A Workflow object of the specified workflow ID
App.search
App.search(**kwargs)
Returns a Search object for the user and app ID.
Parameters:
**kwargs- Arguments passed to the Search class (see Search class)
Returns: Search - A Search object for the user and app ID
Example:
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
search_client = app.search(top_k=12, metric="euclidean")
App.search_concept_relations
App.search_concept_relations(concept_id=None, predicate=None, page_no=None, per_page=None, show_tree=False)
List all the concept relations of the app.
Parameters:
concept_id(str) - The concept ID to filter the concept relationspredicate(str) - Type of relation to filter: 'hypernym', 'hyponym', or 'synonym'page_no(int) - The page number to listper_page(int) - The number of items per pageshow_tree(bool) - If True, prints a rich tree representation of concept relations
Yields: ConceptRelation - ConceptRelation objects in the app
Example:
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
all_concept_relations = list(app.search_concept_relations())
App.workflow
App.workflow(workflow_id, **kwargs)
Returns a Workflow object for the existing workflow ID.
Parameters:
workflow_id(str) - The workflow ID for the workflow to interact with
Returns: Workflow - A Workflow object for the existing workflow ID
Example:
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
workflow = app.workflow(workflow_id="workflow_id")