Python SDK for OpenClassifier - Ultra fast classification API
Project description
OpenClassifier Python SDK
Python SDK for the OpenClassifier API - ultra fast classification for text, images, and PDFs.
Installation
pip install openclassifier
Quick Start
from openclassifier import OpenClassifier
client = OpenClassifier(api_key="sk_live_...")
result = client.classify.text(
"Hello, how can I help you today?",
["greeting", "question", "complaint"]
)
print(result["results"]["label"]) # "greeting"
print(result["results"]["confidence"]) # 0.95
Usage
Text Classification
# Single label (default)
result = client.classify.text(
content="I need help with my order",
labels=["support", "sales", "billing"]
)
# Multi-label classification
result = client.classify.text(
content="Great product but shipping was slow",
labels=["positive", "negative", "shipping", "product"],
multi_label=True
)
Image Classification
# From URL
result = client.classify.image(
inputs=["https://example.com/photo.jpg"],
labels=["cat", "dog", "bird"]
)
# From base64
result = client.classify.image(
inputs=[{"base64": "...", "media_type": "image/jpeg"}],
labels=["cat", "dog", "bird"],
detail="high" # "low", "high", or "auto"
)
# Multiple images
result = client.classify.image(
inputs=[
"https://example.com/photo1.jpg",
"https://example.com/photo2.jpg"
],
labels=["landscape", "portrait", "abstract"]
)
PDF Classification
# From URL
result = client.classify.pdf(
input="https://example.com/document.pdf",
labels=["invoice", "receipt", "contract"]
)
# With options
result = client.classify.pdf(
input="https://example.com/document.pdf",
labels=["invoice", "receipt", "contract"],
aggregation="both", # "per_page", "document", or "both"
page_range={"start": 1, "end": 10}
)
print(result["document_label"]["label"]) # Overall classification
print(result["results"]) # Per-page results
Configuration
client = OpenClassifier(
api_key="sk_live_...", # Or set OPENCLASSIFIER_API_KEY env var
base_url="https://api.openclassifier.com", # Optional
timeout=60.0 # Request timeout in seconds
)
Error Handling
from openclassifier import (
OpenClassifier,
AuthenticationError,
InvalidRequestError,
RateLimitError,
InsufficientBalanceError,
ClassificationError,
)
try:
result = client.classify.text("Hello", ["a", "b"])
except AuthenticationError:
print("Invalid API key")
except InvalidRequestError as e:
print(f"Bad request: {e.message}")
except RateLimitError:
print("Rate limit exceeded, retry later")
except InsufficientBalanceError:
print("Add credits to your account")
except ClassificationError:
print("Classification failed")
License
Apache 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openclassifier-0.1.0.tar.gz.
File metadata
- Download URL: openclassifier-0.1.0.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7dc1907ffbe2dcc549ed4841adee1701f1c3fe251de5bfd4ab65b62f33dcf8a6
|
|
| MD5 |
82dda524122f48d81a62eb7876f1de8b
|
|
| BLAKE2b-256 |
d0e0c07bbb1f568be295b6135885bfbf74fb73ed21343c5009a707605cb02c83
|
Provenance
The following attestation bundles were made for openclassifier-0.1.0.tar.gz:
Publisher:
publish.yml on openclassifier/openclassifier-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openclassifier-0.1.0.tar.gz -
Subject digest:
7dc1907ffbe2dcc549ed4841adee1701f1c3fe251de5bfd4ab65b62f33dcf8a6 - Sigstore transparency entry: 813448844
- Sigstore integration time:
-
Permalink:
openclassifier/openclassifier-python@34a51afe1810c603723411daf8a5da52b47e32ed -
Branch / Tag:
refs/tags/V0.1.0 - Owner: https://github.com/openclassifier
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@34a51afe1810c603723411daf8a5da52b47e32ed -
Trigger Event:
release
-
Statement type:
File details
Details for the file openclassifier-0.1.0-py3-none-any.whl.
File metadata
- Download URL: openclassifier-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65206088155db9cf19017dd8e78e5c13b186f794f9f12c91051c3feaf71991c3
|
|
| MD5 |
b2bb833ab34a71160893c32a5aa8f071
|
|
| BLAKE2b-256 |
3eff7660fea9c1c31e1a59f404453d6f1074f578011f5c6fcc4937c5de18c9c3
|
Provenance
The following attestation bundles were made for openclassifier-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on openclassifier/openclassifier-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openclassifier-0.1.0-py3-none-any.whl -
Subject digest:
65206088155db9cf19017dd8e78e5c13b186f794f9f12c91051c3feaf71991c3 - Sigstore transparency entry: 813448847
- Sigstore integration time:
-
Permalink:
openclassifier/openclassifier-python@34a51afe1810c603723411daf8a5da52b47e32ed -
Branch / Tag:
refs/tags/V0.1.0 - Owner: https://github.com/openclassifier
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@34a51afe1810c603723411daf8a5da52b47e32ed -
Trigger Event:
release
-
Statement type: