Python API Reference
Clarifai Python SDK API Reference
This is the API Reference documentation extracted from the source code.
User
class User(user_id= '',base_url= "https://api.clarifai.com",pat= '',token= '',**kwargs)
User is a class that provides access to Clarifai API endpoints related to user information.
User._init_()
__init__(user_id='',base_url: str = "https://api.clarifai.com",pat='',token= '',**kwargs)
Initializes a User object.
Parameters
- user_id (str) – The user ID for the user to interact with.
- base_url (str) - Base API url. Default "https://api.clarifai.com"
- pat (str) - A personal access token for authentication.
- token (str) - A session token for authentication. Accepts either a session token or a pat. Can be set as env var CLARIFAI_SESSION_TOKEN.
- root_certificates_path (str) - Path to the SSL root certificates file, used to establish secure gRPC connections.
- **kwargs – Additional keyword arguments to be passed to the ClarifaiAuthHelper.
User.app()
app(app_id, **kwargs)
Returns an App object for the specified app ID.
Parameters
- app_id (str) – The app ID for the app to interact with.
- **kwargs – Additional keyword arguments to be passed to the App.
Returns
An App object for the specified app ID.
Return type
App
Example
from clarifai.client.user import User
app = User("user_id").app("app_id")
User.create_app()
create_app(app_id, base_workflow='Language-Understanding', **kwargs)
Creates an app for the user.
Parameters
- app_id (str) – The app ID for the app to create.
- base_workflow (str) – The base workflow to use for the app.(Examples: ‘Universal’, ‘Empty’, ‘General’)
- **kwargs – Additional keyword arguments to be passed to the App.
Returns
An App object for the specified app ID.
Return type
App
Example
from clarifai.client.user import User
client = User(user_id="user_id")
app = client.create_app(app_id="app_id",base_workflow="Universal")
User.create_runner()
create_runner(runner_id, labels, description='')
Creates a runner
Parameters
- runner_id (str) – The Id of runner to create.
- labels (List[str]) – Labels to match runner.
- description (str) – Description of Runner.
Returns
A runner object for the specified Runner ID.
Return type
Runner
Example
from clarifai.client.user import User
client = User(user_id="user_id")
runner = client.create_runner(runner_id="runner_id", labels=["label to link runner"], description="laptop runner")
User.delete_app()
delete_app(app_id)
Deletes an app for the user.
Parameters
- app_id (str) – The app ID for the app to delete.
Return type
None
Example
from clarifai.client.user import User
user = User("user_id").delete_app("app_id")
User.delete_runner()
delete_runner(runner_id)
Deletes all specified runner ids.
Parameters
- runner_ids (str) – List of runners to delete.
Example
from clarifai.client.user import User
client = User(user_id="user_id")
client.delete_runner(runner_id="runner_id")
User.list_apps()
list_apps(filter_by= {}, page_no, per_page)
Lists all the apps for the user.
Parameters
- filter_by (dict): A dictionary of filters to be applied to the list of apps.
- page_no (int): The page number to list.
- per_page (int): The number of items per page.
Returns
A list of App objects for the user.
Return type
List of App
Example
from clarifai.client.user import User
apps = User("user_id").list_apps()
User.list_runners()
list_runners(filter_by={}, page_no, per_page)
List all runners for the user.
Parameters
- filter_by (dict): A dictionary of filters to be applied to the list of apps.
- page_no (int): The page number to list.
- per_page (int): The number of items per page.
Returns
A list of Runner objects for the runners.
Return type
List[Runner]
Example
from clarifai.client.user import User
client = User(user_id="user_id")
all_runners= client.list_runners()
User.runner()
runner(runner_id)
Returns a Runner object if exists.
Parameters
- runner_id (str) – The runner ID to interact with.
Returns
A Runner object for the existing runner ID.
Return type
Runner
Example
from clarifai.client.user import User
client = User(user_id="user_id")
runner = client.runner(runner_id="runner_id")
App
class App(url='', app_id='',base_url= "https://api.clarifai.com",pat='',token='',**kwargs)
App is a class that provides access to Clarifai API endpoints related to App information.
App._init_()
__init__(url='', app_id='',base_url= "https://api.clarifai.com",pat='',token='',**kwargs)
Initializes an App object.
Parameters
- url (str) - The URL to initialize the app object.
- app_id (str) - The App ID for the App to interact with.
- base_url (str) - Base API url. Default "https://api.clarifai.com"
- pat (str) - A personal access token for authentication.
- token (str) - A session token for authentication. Accepts either a session token or a pat. Can be set as env var CLARIFAI_SESSION_TOKEN
- root_certificates_path (str) - Path to the SSL root certificates file, used to establish secure gRPC connections.
- **kwargs – Additional keyword arguments to be passed to the ClarifaiAuthHelper:
- name (str): The name of the app.
- description (str): The description of the app.
App.create_dataset()
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 to be passed to the Dataset.
Returns
A Dataset object for the specified dataset ID.
Return type
Dataset
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()
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 to be passed to the Model.
Returns
A Model object for the specified model ID.
Return type
Model
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_module()
create_module(module_id, description, **kwargs)
Creates a module for the app.
Parameters
- module_id (str) – The module ID for the module to create.
- description (str) – The description of the module to create.
- **kwargs – Additional keyword arguments to be passed to the module.
Returns
A Module object for the specified module ID.
Return type
Module
Example
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
module = app.create_module(module_id="module_id")
App.create_workflow()
create_workflow(config_filepath, generate_new_id, display)
Creates a workflow for the app.
Parameters
- config_filepath (str) – The path to the yaml workflow config file.
- generate_new_id (bool) – If True, generate a new workflow ID.
- display (bool) – If True, display the workflow nodes tree.
Returns
A Workflow object for the specified workflow config.
Return type
Workflow
Example
from clarifai.client.app import App
app = App(user_id="user_id", app_id="app_id")
workflow = app.create_workflow(config_filepath="config.yml")
App.dataset()
dataset(dataset_id, **kwargs)
Returns a Dataset object for the existing dataset ID.
Parameters
- dataset_id (str) – The dataset ID for the dataset to interact with.
Returns
A Dataset object for the existing dataset ID.
Return type
Dataset
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_dataset()
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()
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_module()
delete_module(module_id)
Deletes a module for the user.
Parameters
- module_id (str) – The module 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_module(module_id="module_id")
App.delete_workflow()
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.inputs()
inputs()
Returns an Input object.
Returns
An input object.
Return type
Inputs
App.list_concepts()
list_concepts(page_no,per_page)
Lists all the concepts for the app.
Parameters
- page_no (int) - The page number to list.
- per_page (int) - The number of items per page.
App.list_datasets()
list_datasets(page_no,per_page)
Lists all the datasets for the app.
Parameters
- page_no (int) - The page number to list.
- per_page (int) - The number of items per page.
Returns
A list of Dataset objects for the datasets in the app.
Return type
List[Dataset]
Example
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
all_datasets = app.list_datasets()
App.list_installed_module_versions()
list_installed_module_versions(filter_by={},page_no,per_page)
Lists all installed module versions in the app.
Parameters
- filter_by (dict) – A dictionary of filters to apply to the list of installed module versions.
- page_no (int) - The page number to list.
- per_page (int) - The number of items per page.
Returns
A list of Module objects for the installed module versions in the app.
Return type
List[Module]
Example
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
all_installed_module_versions = app.list_installed_module_versions()
App.list_models()
list_models(filter_by={}, only_in_app=True,page_no,per_page)
Lists all the available models for the user.
Parameters
- filter_by (dict) – A dictionary of filters to apply to the list of models.
- only_in_app (bool) – If True, only return models that are in the app.
- page_no (int) - The page number to list.
- per_page (int) - The number of items per page.
Returns
A list of Model objects for the models in the app.
Return type
List[Model]
Example
from clarifai.client.user import User
app = User(user_id="user_id").app(app_id="app_id")
all_models = app.list_models()
App.list_modules()
list_modules(filter_by={}, only_in_app=True,page_no,per_page)
Lists all the available modules for the user.
Parameters
- filter_by (dict) – A dictionary of filters to apply to the list of modules.
- only_in_app (bool) – If True, only return modules that are in the app.
- page_no (int) - The page number to list.
- per_page (int) - The number of items per page.
Returns
A list of Module objects for the modules in the app.
Return type
List[Module]
Example
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
all_modules = app.list_modules()
App.list_workflows()
list_workflows(filter_by={}, only_in_app=True, page_no,per_page)
Lists all the available workflows for the user.
Parameters
- filter_by (dict) – A dictionary of filters to apply to the list of workflows.
- only_in_app (bool) – If True, only return workflows that are in the app.
- page_no (int) - The page number to list.
- per_page (int) - The number of items per page.
Returns
A list of Workflow objects for the workflows in the app.
Return type
List Workflow
Example
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
all_workflows = app.list_workflows()
App.list_trainable_model_types()
list_trainable_model_types()
Lists all the trainable model types.
Example
from clarifai.client.app import App
print(app.list_trainable_model_types())
App.search()
search(**kwargs)
Returns a Search object for the user and app ID.
Parameters
- **kwargs - See the Search class.
Returns
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.model()
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 with.
- model_version (dict) – The Model Version to interact with.
Returns
A Model object for the existing model ID.
Return type
Model
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': ""})
App.module()
module(module_id, module_version_id='', **kwargs)
Returns a Module object for the existing module ID.
Parameters
- module_id (str) – The module ID for the module to interact with.
- module_version_id (str) – The module version ID for the module version to interact with.
Returns
A Module object for the existing module ID.
Return type
Module
Example
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
module = app.module(module_id="module_id", module_version_id="module_version_id")
App.workflow()
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
A Workflow object for the existing workflow ID.
Return type
Workflow
Example
from clarifai.client.app import App
app = App(app_id="app_id", user_id="user_id")
workflow = app.workflow(workflow_id="workflow_id")
Dataset
class Dataset(url='',dataset_id='',base_url= "https://api.clarifai.com",pat= '',token='',**kwargs)
Dataset._init_()
Dataset is a class that provides access to Clarifai API endpoints related to Dataset information.
__init__(url='',dataset_id='',base_url= "https://api.clarifai.com",pat= '',token='',**kwargs)
Initializes a Dataset object.
Parameters
- url (str) - The URL to initialize the dataset object.
- dataset_id (str) - The Dataset ID within the App to interact with.
- base_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_PAT
- token (str) - A session token for authentication. Accepts either a session token or a pat. Can be set as env var CLARIFAI_SESSION_TOKEN.
- root_certificates_path (str) - Path to the SSL root certificates file, used to establish secure gRPC connections.
- **kwargs – Additional keyword arguments to be passed to the Dataset
Dataset.export()
export(save_path='',archive_url=''local_archive_path='',split='',num_workers)
Exports the Clarifai protobuf dataset to a local archive.
Parameters
- save_path (str) – The path to save the archive to.
- archive_url (str) – The URL to the Clarifai protobuf archive.
- local_archive_path (str) – The path to the local Clarifai protobuf archive.
- split (str) – Export dataset inputs in the directory format
{split}/{input_type}
. Default is all. - num_workers (int) - Number of workers to use for downloading the archive. Default is 4.
Example
from clarifai.client.dataset import Dataset
Dataset().export(save_path='output.zip', local_archive_path='clarifai-data-protobuf.zip')
Note: Currently only supports export of dataset inputs.
Dataset.upload_dataset()
upload_dataset(dataloader,batch_size,get_upload_status,log_warnings)
Uploads a dataset to the app.
Parameters
- dataloader (Type[ClarifaiDataLoader]) - ClarifaiDataLoader object
- batch_size (int) - batch size for concurrent upload of inputs and annotations (max: 128)
- get_upload_status (bool) - True if you want to get the upload status of the dataset
- log_warnings (bool) - True if you want to save log warnings in a file
Dataset.upload_from_csv()
upload_from_csv(csv_path='',input_type='text',csv_type='',labels='',batch_size)
Uploads dataset from a CSV file.
Parameters
- csv_path (str) – path to the csv file
- input_type (str) – type of the dataset(text, image)
- csv_type (str) – type of the csv file(raw, url, file_path)
- labels (bool) – True if csv file has labels column
- batch_size (int) - batch size for concurrent upload of inputs and annotations
Example
from clarifai.client.dataset import Dataset
dataset = Dataset(user_id = 'user_id', app_id = 'demo_app', dataset_id = 'demo_dataset')
dataset.upload_from_csv(csv_path='csv_path', input_type='text', csv_type='raw', labels=True)
Note: csv file should have either one(input) or two columns(input, labels).
Dataset.upload_from_folder()
upload_from_folder(folder_path='',input_type='',labels,batch_size)
Upload dataset from folder.
Parameters
- folder_path (str) – Path to the folder containing images.
- input_type (str) – type of the dataset(text, image)
- labels (bool) – True if folder name is the label for the inputs
- batch_size (int) - batch size for concurrent upload of inputs and annotations
Example
from clarifai.client.dataset import Dataset
dataset = Dataset(user_id = 'user_id', app_id = 'demo_app', dataset_id = 'demo_dataset')
dataset.upload_from_folder(folder_path='folder_path', input_type='text', labels=True)
Note: The filename is used as the input_id.
Dataset.get_upload_status()
get_upload_status(dataloader,delete_version,timeout,pre_upload_stats,pre_upload)
Creates a new dataset version and displays the upload status of the dataset.
Parameters
- dataloader (Type[ClarifaiDataLoader]) - ClarifaiDataLoader object
- delete_version (bool) - True if you want to delete the version after getting the upload status
- timeout (int) - Timeout in seconds for getting the upload status. Default is 600 seconds.
- pre_upload_stats (Tuple[Dict[str, int], Dict[str, int]]) - The pre upload stats for the dataset.
- pre_upload (bool) - True if you want to get the pre upload stats for the dataset.
Example
from clarifai.client.dataset import Dataset
dataset = Dataset(dataset_id='dataset_id', user_id='user_id', app_id='app_id')
dataset.get_upload_status(dataloader)
Note: This is a beta feature and is subject to change.
Dataset.list_versions()
list_versions(page_no,per_page)
Lists all the versions for the dataset.
Parameters
- page_no (int) - The page number to list.
- per_page (int) - The number of items per page.
Example
from clarifai.client.dataset import Dataset
dataset = Dataset(dataset_id='dataset_id', user_id='user_id', app_id='app_id')
all_dataset_versions = list(dataset.list_versions())
Note: Defaults to 16 per page if page_no is specified and per_page is not specified.If both page_no and per_page are None, then lists all the resources.
Dataset.create_version()
create_version(**kwargs)
Creates a dataset version for the Dataset.
Parameters
- **kwargs - Additional keyword arguments to be passed to Dataset Version.
- description (str) - The description of the dataset version.
- metadata (dict) - The metadata of the dataset version.*
Example
from clarifai.client.dataset import Dataset
dataset = Dataset(dataset_id='dataset_id', user_id='user_id', app_id='app_id')
dataset_version = dataset.create_version(description='dataset_version_description')
Dataset.delete_version()
delete_version(version_id='')
Deletes a dataset version for the Dataset.
Parameters
- version_id (str) - The version ID to delete.
Example
from clarifai.client.dataset import Dataset
dataset = Dataset(dataset_id='dataset_id', user_id='user_id', dataset.delete_version(version_id='version_id')
Input
class Inputs(user_id='',app_id='',logger_level="INFO",base_url="https://api.clarifai.com",pat='',token='',**kwargs)
Inputs is a class that provides access to Clarifai API endpoints related to Input information.