SDKs overview
Clarifai offers a suite of Software Development Kits (SDKs) designed to simplify interaction with its computer vision and AI platform. These SDKs provide programmatic access to functionalities such as custom model training and deployment, data labeling, image and video analysis, and workflow management. The aim is to enable developers to integrate Clarifai's AI capabilities into their applications without needing to construct raw HTTP requests for every API endpoint. By abstracting the underlying REST API, the SDKs streamline development, accelerate integration, and allow developers to focus on application logic rather than API communication protocols. Clarifai maintains official SDKs for several popular programming languages, alongside support for cURL for direct API interaction and a dedicated SDK for their Spacetime platform.
The SDKs are structured to support various aspects of the Clarifai platform, including:
- Data Management: Uploading, tagging, and organizing inputs (images, videos, text) for model training and inference.
- Model Interaction: Sending inputs to pre-built or custom-trained models to receive predictions.
- Model Training: Programmatically initiating and managing the training of custom computer vision models.
- Workflow Management: Defining and executing complex AI pipelines that combine multiple models and operations.
- Spacetime SDK: A specialized SDK for interacting with Clarifai's Spacetime platform, which focuses on large-scale, geospatial, and temporal data processing.
Detailed documentation for all SDKs, including API references and example usage, is available on the Clarifai API guide.
Official SDKs by language
Clarifai provides official SDKs for a range of programming languages, ensuring broad compatibility with different development environments. These SDKs are actively maintained by Clarifai and are recommended for developers building applications that integrate with the platform.
| Language | Package/Repository | Installation Command (Example) | Maturity |
|---|---|---|---|
| Python | clarifai-python |
pip install clarifai |
Stable, Actively Maintained |
| Java | clarifai-java (Maven/Gradle) |
Add to pom.xml or build.gradle |
Stable, Actively Maintained |
| Node.js | clarifai-nodejs-grpc |
npm install clarifai-nodejs-grpc |
Stable, Actively Maintained |
| Go | clarifai-go |
go get github.com/Clarifai/clarifai-go/clarifai |
Stable, Actively Maintained |
| cURL | N/A (Direct HTTP) | N/A (command-line utility) | Core API Access |
| PHP | clarifai/clarifai-php (Composer) |
composer require clarifai/clarifai-php |
Stable, Actively Maintained |
| C# | Clarifai.gRPC (NuGet) |
dotnet add package Clarifai.gRPC |
Stable, Actively Maintained |
Each SDK is designed to align with the idioms and best practices of its respective language, providing a natural development experience. For comprehensive details on each SDK, including advanced usage and specific API methods, developers should consult the Clarifai API documentation.
Installation
Installation procedures vary by programming language and package manager. The following examples demonstrate typical installation methods for Clarifai's official SDKs:
Python
The Python SDK is typically installed via pip, the standard package installer for Python.
pip install clarifai
Java
For Java projects, the Clarifai SDK can be included as a dependency using Maven or Gradle. Below is an example for Maven:
<dependency>
<groupId>com.clarifai.grpc</groupId>
<artifactId>clarifai-grpc</artifactId>
<version>9.7.0</version> <!-- Check Clarifai docs for latest version -->
</dependency>
Node.js
The Node.js SDK is available via npm, the default package manager for JavaScript runtime Node.js.
npm install clarifai-nodejs-grpc
Go
Go modules are used to manage the Go SDK dependencies.
go get github.com/Clarifai/clarifai-go/clarifai
PHP
The PHP SDK is installed using Composer, the dependency manager for PHP.
composer require clarifai/clarifai-php
C#
The C# SDK is distributed as a NuGet package, installed via the .NET CLI or Visual Studio.
dotnet add package Clarifai.gRPC
Always refer to the Clarifai SDK documentation for the most current installation instructions and version compatibility information.
Quickstart example
The following Python example demonstrates how to authenticate with the Clarifai API and make a prediction using a pre-trained general image recognition model. This quickstart assumes you have installed the Python SDK and have a Clarifai API key.
First, set up your environment by importing the necessary libraries and your API key:
import os
from clarifai_grpc.channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_pb2
# Your Clarifai API Key
# It's recommended to store your API key in an environment variable
# Example: CLARIFAI_API_KEY = "YOUR_API_KEY"
PAT = os.environ.get("CLARIFAI_API_KEY", "YOUR_CLARIFAI_PAT")
# The Clarifai application ID
USER_ID = 'clarifai'
APP_ID = 'main'
MODEL_ID = 'general-image-recognition'
MODEL_VERSION_ID = 'aa7f35c01e0642fda5ff3a5a3f12dc59' # Optional, use to specify a model version
# Initialize gRPC channel
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
data = resources_pb2.Data(image=resources_pb2.Image(url="https://samples.clarifai.com/goldfish.jpg"))
Next, send a prediction request to the general image recognition model:
post_model_outputs_response = stub.PostModelOutputs(
service_pb2.PostModelOutputsRequest(
user_app_id=resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID),
model_id=MODEL_ID,
version_id=MODEL_VERSION_ID, # This is optional. Defaults to the latest model version
inputs=[resources_pb2.Input(data=data)]
),
metadata=metadata
)
if post_model_outputs_response.status.code != status_pb2.SUCCESS:
print(post_model_outputs_response.status)
raise Exception(f"Post model outputs failed, status: {post_model_outputs_response.status.description}")
# Print the prediction results
print("Prediction results:")
for concept in post_model_outputs_response.outputs[0].data.concepts:
print(f" {concept.name}: {concept.value:.2f}")
This example demonstrates how to provide an image URL as input and retrieve a list of predicted concepts with their respective confidence scores. For more advanced use cases, such as custom model training or managing large datasets, refer to the Clarifai developer documentation.
Community libraries
While Clarifai provides official SDKs for core functionality, the open-source community may develop and maintain additional libraries, tools, or wrappers that extend Clarifai's capabilities or offer integrations with other platforms. These community-contributed projects can sometimes provide specialized functionalities, alternative language bindings, or utilities tailored for specific use cases not covered by the official SDKs. Developers often share such projects on platforms like GitHub or package repositories.
Before using any community-maintained library, it is advisable to assess its:
- Active Maintenance: Check the project's commit history and issue tracker to determine if it is actively supported.
- Documentation: Ensure that the library has clear and sufficient documentation for usage.
- Licensing: Verify the license to confirm it is suitable for your project's requirements.
- Security: Review the codebase or community feedback for any potential security concerns.
For official support and guarantees, Clarifai recommends using their officially supported SDKs. Information regarding community-contributed libraries is typically found through community forums, developer blogs, or GitHub searches. An example of a common practice for open-source project discovery is searching on GitHub for relevant repositories.