Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openclassifier-0.1.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openclassifier-0.1.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

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

Hashes for openclassifier-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7dc1907ffbe2dcc549ed4841adee1701f1c3fe251de5bfd4ab65b62f33dcf8a6
MD5 82dda524122f48d81a62eb7876f1de8b
BLAKE2b-256 d0e0c07bbb1f568be295b6135885bfbf74fb73ed21343c5009a707605cb02c83

See more details on using hashes here.

Provenance

The following attestation bundles were made for openclassifier-0.1.0.tar.gz:

Publisher: publish.yml on openclassifier/openclassifier-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for openclassifier-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 65206088155db9cf19017dd8e78e5c13b186f794f9f12c91051c3feaf71991c3
MD5 b2bb833ab34a71160893c32a5aa8f071
BLAKE2b-256 3eff7660fea9c1c31e1a59f404453d6f1074f578011f5c6fcc4937c5de18c9c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for openclassifier-0.1.0-py3-none-any.whl:

Publisher: publish.yml on openclassifier/openclassifier-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page