Skip to main content

Create, Get, Update, Delete

Manage the data in your app


The API is built around a simple idea. You send inputs (such as images) to the service and it returns predictions. In addition to receiving predictions on inputs, you can also index inputs and their predictions to later search against. You can also index inputs with concepts to later train your own model.

When you add an input to your app, the base workflow of your app runs, computing the outputs from all the models in that workflow and indexing those outputs. Those indexed outputs are what incur the indexing fee monthly, and enable search and training on top of the outputs of the base workflow models.

info

The initialization code used in the following examples is outlined in detail on the client installation page.

Add Inputs

You can add inputs one by one or in bulk. If you send them in bulk, you are limited to sending 128 inputs at a time.

Note

Adding inputs is an asynchronous operation. That means it will process indexing of your inputs through your default workflow in the background, which can take some time. In order to check the status of each input you add, see the section on Get Inputs and look for status 30000 (INPUT_IMAGE_DOWNLOAD_SUCCESS) status code on each input to know when it has successfully been indexed.

Add Inputs via URL

Below is an example of how to add inputs via a publicly accessible URL.

##########################################################################
# In this section, we set the user authentication, app ID, and input URL.
# Change these strings to run your own example.
##########################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change this to whatever image input you want to add
IMAGE_URL = 'https://samples.clarifai.com/metro-north.jpg'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
user_app_id=userDataObject,
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
url=IMAGE_URL,
allow_duplicate_url=True
)
)
)
]
),
metadata=metadata
)

if post_inputs_response.status.code != status_code_pb2.SUCCESS:
print(post_inputs_response.status)
raise Exception("Post inputs failed, status: " + post_inputs_response.status.description)

Add Inputs via Bytes

Below is an example of how to add inputs via bytes.

Note

The data must be base64 encoded. When you add a base64 image to our servers, a copy will be stored and hosted on our servers. If you already have an image hosting service, we recommend using it and adding images via the url parameter.

##################################################################################
# In this section, we set the user authentication, app ID, and the location
# of the image we want as an input. Change these strings to run your own example.
##################################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change this to whatever image input you want to add
IMAGE_FILE_LOCATION = 'YOUR_IMAGE_FILE_LOCATION'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

with open(IMAGE_FILE_LOCATION, "rb") as f:
file_bytes = f.read()

post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
user_app_id=userDataObject,
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
base64=file_bytes
)
)
)
]
),
metadata=metadata
)

if post_inputs_response.status.code != status_code_pb2.SUCCESS:
print(post_inputs_response.status)
raise Exception("Post inputs failed, status: " + post_inputs_response.status.description)

Add Multiple Inputs With IDs

In cases where you have your own id and you only have one item per image, you are encouraged to send inputs with your own id. This will help you later match the input to your own database.

If you do not send an id, one will be created for you. If you have more than one item per image, it is recommended that you put the product id in the metadata.

##################################################################################
# In this section, we set the user authentication, app ID, and the URLs and IDs
# of the images we want as inputs. Change these strings to run your own example.
##################################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to whatever inputs you want to add
IMAGE_URL_1 = 'https://samples.clarifai.com/metro-north.jpg'
IMAGE_URL_2 = 'https://samples.clarifai.com/puppy.jpeg'
INPUT_ID_1 = 'mytrain'
INPUT_ID_2 = 'mypuppy'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
user_app_id=userDataObject,
inputs=[
resources_pb2.Input(
id=INPUT_ID_1,
data=resources_pb2.Data(
image=resources_pb2.Image(
url=IMAGE_URL_1,
allow_duplicate_url=True
)
)
),
resources_pb2.Input(
id=INPUT_ID_2,
data=resources_pb2.Data(
image=resources_pb2.Image(
url=IMAGE_URL_2,
allow_duplicate_url=True
)
)
),
]
),
metadata=metadata
)

if post_inputs_response.status.code != status_code_pb2.SUCCESS:
print("There was an error with your request!")
for input_object in post_inputs_response.inputs:
print("Input " + input_object.id + " status:")
print(input_object.status)
raise Exception("Post inputs failed, status: " + post_inputs_response.status.description)

Add Inputs With Concepts

If you would like to add an input with concepts, you can do so. Concepts play an important role in creating your own models.

You can learn more about creating your own models here.

Concepts also help you search for inputs. You can learn more about search here.

When you add a concept to an input, you need to indicate whether the concept is present in the image or not.

You can add inputs with concepts via URLs or bytes.

##################################################################################
# In this section, we set the user authentication, app ID, and the input to add
# with concept. Change these strings to run your own example.
##################################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to whatever input and concept you want to add
IMAGE_URL = 'https://samples.clarifai.com/puppy.jpeg'
CONCEPT_ID = 'charlie'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
user_app_id=userDataObject,
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
url=IMAGE_URL,
allow_duplicate_url=True
),
concepts=[resources_pb2.Concept(id=CONCEPT_ID, value=1.)]
)
)
]
),
metadata=metadata
)

if post_inputs_response.status.code != status_code_pb2.SUCCESS:
print(post_inputs_response.status)
raise Exception("Post inputs failed, status: " + post_inputs_response.status.description)

Add Inputs With Multiple Concepts

You can also add an input with multiple concepts in a single API call. You can provide the concepts in a list and iterate through it.

You can add the inputs via URLs or bytes.

##################################################################################
# In this section, we set the user authentication, app ID, and the input to add
# with concepts. Change these strings to run your own example.
##################################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to whatever input and concepts you want to add
IMAGE_URL = 'https://samples.clarifai.com/puppy.jpeg'
CONCEPT_IDS_LIST = ['one', 'two', 'three', 'four', 'five', 'six']

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
user_app_id=userDataObject,
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
url=IMAGE_URL,
allow_duplicate_url=True
),
# We use Python list comprehension to iterate through the list of concepts
concepts=[resources_pb2.Concept(id=str(i), value=1.) for i in CONCEPT_IDS_LIST]
)
)
]
),
metadata=metadata
)

if post_inputs_response.status.code != status_code_pb2.SUCCESS:
print(post_inputs_response.status)
raise Exception("Post inputs failed, status: " + post_inputs_response.status.description)

Add Inputs With Custom Metadata

In addition to adding an input with concepts, you can also add an input with custom metadata. This metadata will then be searchable. Metadata can be any arbitrary JSON.

If you have more than one item per image, it is recommended to put the id in the metadata like:

{
"product_id": "xyz"
}
####################################################################################
# In this section, we set the user authentication, app ID, and the custom metadata
# and input we want to add. Change these strings to run your own example.
####################################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to whatever input and custom metadata you want to add
CUSTOM_METADATA = {"id": "id001", "type": "animal", "size": 100}
IMAGE_URL = 'https://samples.clarifai.com/puppy.jpeg'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
from google.protobuf.struct_pb2 import Struct

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

input_metadata = Struct()

input_metadata.update(CUSTOM_METADATA)

post_inputs_response = stub.PostInputs(
service_pb2.PostInputsRequest(
user_app_id=userDataObject,
inputs=[
resources_pb2.Input(
data=resources_pb2.Data(
image=resources_pb2.Image(
url=IMAGE_URL,
allow_duplicate_url=True
),
metadata=input_metadata
)
)
]
),
metadata=metadata
)

if post_inputs_response.status.code != status_code_pb2.SUCCESS:
print(post_inputs_response.status)
raise Exception("Post inputs failed, status: " + post_inputs_response.status.description)

List Inputs

List all Inputs

You can list all the inputs (images) you previously added either for search or train. If you added inputs with concepts, they will be returned in the response as well.

This request is paginated.

###############################################################
# In this section, we set the user authentication and app ID.
# Change these strings to run your own example.
###############################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

list_inputs_response = stub.ListInputs(
service_pb2.ListInputsRequest(
user_app_id=userDataObject,
page=1,
per_page=10
),
metadata=metadata
)

if list_inputs_response.status.code != status_code_pb2.SUCCESS:
print(list_inputs_response.status)
raise Exception("List inputs failed, status: " + list_inputs_response.status.description)

for input_object in list_inputs_response.inputs:
print(input_object)

List Inputs (Streaming)

This is another method for listing inputs, which was built to scalably list an app's inputs in an iterative / streaming fashion. StreamInputs will return per_page number of inputs from a certain input onward, controlled by the optional last_id parameter (defaults to the first input).

By default, the stream will return inputs from oldest to newest. Set the descending field to true to reverse that order.

###############################################################
# In this section, we set the user authentication and app ID.
# Change these strings to run your own example.
###############################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

# To start from beginning, do not provide the last_id parameter.
stream_inputs_response = stub.StreamInputs(
service_pb2.StreamInputsRequest(
user_app_id=userDataObject,
per_page=5,
# descending = True # Set to reverse order
),
metadata=metadata
)

if stream_inputs_response.status.code != status_code_pb2.SUCCESS:
print(stream_inputs_response.status)
raise Exception("Stream inputs failed, status: " + stream_inputs_response.status.description)

print("First response (starting from the first input):")
for input_object in stream_inputs_response.inputs:
print("\t" + input_object.id)

last_id = stream_inputs_response.inputs[-1].id

# Set last_id to get the next set of inputs. The returned inputs will not include the last_id input.
stream_inputs_response = stub.StreamInputs(
service_pb2.StreamInputsRequest(
user_app_id=userDataObject,
per_page=5,
last_id=last_id
),
metadata=metadata
)

print(f"Second response (first input is the one following input ID {last_id}):")
for input_object in stream_inputs_response.inputs:
print("\t" + input_object.id)

Get Inputs

Get Input by ID

If you'd like to get the details of a specific input by its id, you can do that as well.

###############################################################################
# In this section, we set the user authentication, app ID, and the input's ID
# Change these strings to run your own example.
###############################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change this ID to whatever input you want its details
INPUT_ID = 'eec128fd81974543bafff48702edca4d'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

get_input_response = stub.GetInput(
service_pb2.GetInputRequest(
user_app_id=userDataObject,
input_id=INPUT_ID
),
metadata=metadata
)

if get_input_response.status.code != status_code_pb2.SUCCESS:
print(get_input_response.status)
raise Exception("Get input failed, status: " + get_input_response.status.description)

input_object = get_input_response.input
print(input_object)

Get Inputs' Status

If you add inputs in bulk, they will be procesed in the background. You can get the status of all your inputs (processed, to_process, and errors) like this:

##################################################################
# In this section, we set the user authentication and the app ID.
# Change these strings to run your own example.
##################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

get_input_count_response = stub.GetInputCount(
service_pb2.GetInputCountRequest(
user_app_id=userDataObject
),
metadata=metadata
)

if get_input_count_response.status.code != status_code_pb2.SUCCESS:
print(get_input_count_response.status)
raise Exception("Get input count failed, status: " + get_input_count_response.status.description)

counts = get_input_count_response.counts
print(counts)

Update Inputs

Update Input With Concepts

To update an input with a new concept, or to change a concept value from true/false, you can do the following:

##############################################################################
# In this section, we set the user authentication, app ID, and the input and
# concept ID we want to update. Change these strings to run your own example.
##############################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the update you want to make
INPUT_ID = 'eec128fd81974543bafff48702edca4d'
CONCEPT_ID_1 = 'tree'
CONCEPT_ID_2 = 'water'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

patch_inputs_response = stub.PatchInputs(
service_pb2.PatchInputsRequest(
user_app_id=userDataObject,
action="merge", # Supported actions: overwrite, merge, remove
inputs=[
resources_pb2.Input(
id=INPUT_ID,
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_1, value=1.), # 1 means true, this concept is present.
resources_pb2.Concept(id=CONCEPT_ID_2, value=0.) # 0 means false, this concept is not present.
]
)
)
]
),
metadata=metadata
)

if patch_inputs_response.status.code != status_code_pb2.SUCCESS:
print(patch_inputs_response.status)
raise Exception("Patch inputs failed, status: " + patch_inputs_response.status.description)

Bulk Update Inputs With Concepts

You can update existing inputs using their ids. This is useful if you'd like to add concepts to inputs after they have already been added.

Below is an example of how to update multiple inputs with concepts at once.

################################################################################
# In this section, we set the user authentication, app ID, and the inputs and
# concepts IDs we want to update. Change these strings to run your own example.
################################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the updates you want to make
INPUT_ID_1 = '2e9c4a86555d40ffb47c7b045d7e3048'
INPUT_ID_2 = '52b467c2005946cbbbe7a5eec76e29cf'
CONCEPT_ID_1 = 'tree'
CONCEPT_ID_2 = 'water'
CONCEPT_ID_3 = 'animal'
CONCEPT_ID_4 = 'fruit'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

patch_inputs_response = stub.PatchInputs(
service_pb2.PatchInputsRequest(
user_app_id=userDataObject,
action="merge", # Supported actions: overwrite, merge, remove.
inputs=[
resources_pb2.Input(
id=INPUT_ID_1,
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_1, value=1.), # 1 means true, this concept is present.
resources_pb2.Concept(id=CONCEPT_ID_2, value=0.) # 0 means false, this concept is not present.
]
)
),
resources_pb2.Input(
id=INPUT_ID_2,
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_3, value=1.),
resources_pb2.Concept(id=CONCEPT_ID_4, value=0.)
]
)
),
]
),
metadata=metadata
)

if patch_inputs_response.status.code != status_code_pb2.SUCCESS:
print(patch_inputs_response.status)
raise Exception("Patch inputs failed, status: " + patch_inputs_response.status.description)

Delete Inputs

Delete Concepts From an Input

To remove concepts that were already added to an input, you can do this:

##############################################################################
# In this section, we set the user authentication, app ID, and the input and
# concept ID. Change these strings to run your own example.
##############################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the concept you want to remove
INPUT_ID = '2e9c4a86555d40ffb47c7b045d7e3048'
CONCEPT_ID = 'water'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

patch_inputs_response = stub.PatchInputs(
service_pb2.PatchInputsRequest(
user_app_id=userDataObject,
action="remove", # Supported actions: overwrite, merge, remove.
inputs=[
resources_pb2.Input(
id=INPUT_ID,
data=resources_pb2.Data(
concepts=[
# We're removing the concept, so there's no need to specify
# the concept value.
resources_pb2.Concept(id=CONCEPT_ID),
]
)
)
]
),
metadata=metadata
)

if patch_inputs_response.status.code != status_code_pb2.SUCCESS:
print(patch_inputs_response.status)
raise Exception("Patch inputs failed, status: " + patch_inputs_response.status.description)

Bulk Delete Concepts From a List of Inputs

Below is an example of how to bulk delete multiple concepts from a list of inputs.

##############################################################################
# In this section, we set the user authentication, app ID, and the inputs and
# concepts IDs. Change these strings to run your own example.
##############################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the concepts you want to remove
INPUT_ID_1 = '2e9c4a86555d40ffb47c7b045d7e3048'
INPUT_ID_2 = '52b467c2005946cbbbe7a5eec76e29cf'
CONCEPT_ID_1 = 'tree'
CONCEPT_ID_2 = 'water'
CONCEPT_ID_3 = 'animal'
CONCEPT_ID_4 = 'fruit'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

patch_inputs_response = stub.PatchInputs(
service_pb2.PatchInputsRequest(
user_app_id=userDataObject,
action="remove", # Supported actions: overwrite, merge, remove.
inputs=[
resources_pb2.Input(
id=INPUT_ID_1,
data=resources_pb2.Data(
concepts=[
# We're removing the concepts, so there's no need to specify
# the concept value.
resources_pb2.Concept(id=CONCEPT_ID_1),
resources_pb2.Concept(id=CONCEPT_ID_2),
]
)
),
resources_pb2.Input(
id=INPUT_ID_2,
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_3),
resources_pb2.Concept(id=CONCEPT_ID_4),
]
)
),
]
),
metadata=metadata
)

if patch_inputs_response.status.code != status_code_pb2.SUCCESS:
print(patch_inputs_response.status)
raise Exception("Patch inputs failed, status: " + patch_inputs_response.status.description)

Delete Input by ID

Below is an example of how to delete a single input by its id.

##############################################################################
# In this section, we set the user authentication, app ID, and the ID of the
# input we want to delete. Change these strings to run your own example.
##############################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change this based on the input you want to delete
INPUT_ID = '2e9c4a86555d40ffb47c7b045d7e3048'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

delete_input_response = stub.DeleteInput(
service_pb2.DeleteInputRequest(
user_app_id=userDataObject,
input_id=INPUT_ID
),
metadata=metadata
)

if delete_input_response.status.code != status_code_pb2.SUCCESS:
print(delete_input_response.status)
raise Exception("Delete input failed, status: " + delete_input_response.status.description)

Delete a List of Inputs

You can also delete multiple inputs in one API call. This will happen asynchronously.

info

We currently support a batch size of 128 inputs per request. So, you can provide a list of 128 input IDs and delete them in one API call.

##############################################################################
# In this section, we set the user authentication, app ID, and the IDs of the
# inputs we want to delete. Change these strings to run your own example.
##############################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the inputs you want to delete
INPUT_ID_1 = '97eb76d22e964c7cbbf06a51532c6fbe'
INPUT_ID_2 = '86b1272feabb45d4bcd2de51eedd729b'

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

delete_inputs_response = stub.DeleteInputs(
service_pb2.DeleteInputsRequest(
user_app_id=userDataObject,
ids=[INPUT_ID_1, INPUT_ID_2]
),
metadata=metadata
)

if delete_inputs_response.status.code != status_code_pb2.SUCCESS:
print(delete_inputs_response.status)
raise Exception("Delete input failed, status: " + delete_inputs_response.status.description)