Registry / ai-ml / clarifai

clarifai

JSON →
library12.5.0pypypi✓ verified 81d ago

The Clarifai Python SDK provides a client library for interacting with the Clarifai platform, enabling developers to build and deploy AI models for computer vision, natural language processing, and multimodal applications. The current version is 12.4.0, and it maintains a rapid release cadence with frequent updates.

pip install clarifai
INSTALL
IMPORT
SIG · CLARIFAI
C
clarifai
ai-mlpythonv12.5.0
Install
16.4s avg
Import
Disk
234MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v12.5.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 231.3MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 16.4s · import 0.000s · 226MB
234MB installed
● package 234MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ClarifaiClient
import clarifai
from clarifai import ClarifaiClient

This quickstart demonstrates how to initialize the Clarifai client, load a public image recognition model, and perform a prediction using an image URL. It emphasizes using environment variables for authentication and shows how to process the prediction results.

import os from clarifai.client import ClarifaiClient from clarifai.client.input import Input # Initialize the Clarifai client with your Personal Access Token (PAT). # It's highly recommended to set CLARIFAI_PAT as an environment variable. # Alternatively, you can pass it directly: ClarifaiClient(pat="YOUR_PAT_HERE") clarifai_pat = os.environ.get('CLARIFAI_PAT', 'YOUR_CLARIFAI_PAT_HERE') if clarifai_pat == 'YOUR_CLARIFAI_PAT_HERE': print("WARNING: CLARIFAI_PAT environment variable not set. Using placeholder.") print("Please replace 'YOUR_CLARIFAI_PAT_HERE' or set the environment variable.") client = ClarifaiClient(pat=clarifai_pat) # Example: Predict with a public image recognition model model_id = "general-image-recognition" # model_version_id = "aa7f35c01e0642fda5ff3a5a3bcce187" # Optional, uses default if not specified image_url = "https://samples.clarifai.com/wedding.jpg" # Create an input object for prediction input_obj = Input(url=image_url) print(f"Predicting with model '{model_id}' using image from {image_url}...") try: # Get the model and make a prediction model_prediction = client.get_model(model_id).predict(inputs=[input_obj]) # Access and print the prediction results if model_prediction.outputs: for concept in model_prediction.outputs[0].data.concepts: print(f" {concept.name}: {concept.value:.2f}") else: print("No outputs found in the prediction.") print(model_prediction) # Print full response for debugging if no outputs except Exception as e: print(f"An error occurred during prediction: {e}") if "Invalid authentication token" in str(e): print("Please check your CLARIFAI_PAT environment variable or provided PAT.") elif "Invalid request" in str(e): print("Please check your model ID, version ID, or input format.")
Debug
Known issues
breakingThe `clarifai.rest` module, including `ClarifaiApp`, was completely removed in version 12. The primary client is now `clarifai.client.ClarifaiClient`.
fix
Migrate all `from clarifai.rest import ClarifaiApp` imports and related usage to `from clarifai.client import ClarifaiClient`. Client initialization and method calls have significantly changed.
affects: >=12.0.0
gotchaAuthentication token types (PAT vs. API Key) and initialization methods have evolved. Incorrect or missing tokens are a frequent source of errors.
fix
Always use a Personal Access Token (PAT) for new applications. Set it as an environment variable (`CLARIFAI_PAT`) or pass it directly when initializing `ClarifaiClient(pat='YOUR_PAT')`. Ensure the PAT has the necessary scopes for your operations.
affects: All versions, especially >=12.0.0
gotchaInput handling for models requires creating `Input` objects. Directly passing URLs or byte streams to `predict` methods without wrapping them will fail.
fix
Before calling a model's `predict` method, construct an `Input` object (e.g., `Input(url='...')`, `Input(base64='...')`, `Input(file_bytes=...)`) and pass a list of these objects: `model.predict(inputs=[input_obj_1, input_obj_2])`.
affects: >=12.0.0
Upgrade
Version history
12.5.0latest on PyPI · released May 8, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
18
OpenAI (training)
1
Resources
clarifai — pip install clarifai · libregistry