Typed Python SDK client for ITS-AI API (sync + async).
Project description
ITS-AI Python SDK
Typed, ergonomic Python client for the ITS-AI API with sync and async interfaces, robust error mapping, attempts, and helpful docs.
- Sync and async clients:
ItsAIClient(requests) andAsyncItsAIClient(httpx) - Strongly-typed results via dataclasses
- Attempts on 429/5xx with exponential backoff and
Retry-Aftersupport - Rich, typed error hierarchy mapped from API
typeand HTTP status - Safe logging with masked API keys
Installation
pip install its-ai
Quick start
Single text analysis
from its_ai import ItsAIClient, AnalyzeTextResult
client = ItsAIClient(api_key="api_key")
try:
result: AnalyzeTextResult = client.analyze_text("Your English text here.")
print(result.answer)
finally:
client.close()
With deep scan:
with ItsAIClient(api_key="api_key") as client:
result = client.analyze_text("Your English text here.", deep_scan=True)
print(result.answer, result.segmentation_tokens)
Batch analysis
from its_ai import ItsAIClient, AnalyzeBatchItemResult
texts = [
"Short text", # might trigger LowWords
"A sufficiently long English text ...",
]
with ItsAIClient(api_key="sk_live_your_key") as client:
items: list[AnalyzeBatchItemResult] = client.analyze_batch(texts, deep_scan=False)
for item in items:
print(item.text, item.answer)
Chunking large batches automatically:
with ItsAIClient(api_key="sk_live_your_key") as client:
results = client.analyze_batch(texts, max_batch_size=50)
Async usage
import asyncio
from its_ai import AsyncItsAIClient
async def main():
async with AsyncItsAIClient(api_key="sk_live_your_key") as client:
res = await client.analyze_text("hello world", deep_scan=True)
print(res)
asyncio.run(main())
Errors and attempts
The client raises typed exceptions derived from ItsAIError based on the API error type and HTTP status. Common ones include:
ValidationError,AuthenticationFailed,PermissionDenied,NotFound,NotAcceptable- Domain errors:
LowWords,ManyWords,OnlyEnglish,RateLimitExceeded, etc.
Idempotent POSTs are retried up to 3 times on 429/5xx with exponential backoff and Retry-After respected. Other 4xx are not retried.
from its_ai import ItsAIClient, LowWords, ManyWords, OnlyEnglish, AuthenticationFailed
try:
with ItsAIClient() as client: # reads ITS_AI_API_KEY from env by default
client.analyze_text("too short")
except LowWords as e:
print("Text too short:", e.message)
except ManyWords:
print("Text too long")
except OnlyEnglish:
print("Only English is supported")
except AuthenticationFailed:
print("Invalid/absent API key")
Configuration
api_key: string, required (defaults fromITS_AI_API_KEY)base_url: defaults tohttps://api.its-ai.org(trailing slashes trimmed)timeout: default 10s (override per-call viatimeout=)max_attempts: default 3 (for 429/5xx)max_batch_size(batch-only): optional chunking of input texts
Headers are set automatically: User-Agent: its-ai-python-sdk/<version>, Accept: application/json, Content-Type: application/json.
Logging
The package uses Python's logging under the logger name its_ai. Enable DEBUG to see request URLs, status codes, and trimmed payloads. The api_key is masked.
import logging
logging.basicConfig(level=logging.DEBUG)
Environment
ITS_AI_API_KEY– used by default ifapi_keyis not passed.ITS_AI_E2E=1– enable smoke tests to hit the real API in CI (optional).
Testing
Run unit tests:
python -m pytest -q
Run smoke (real API) tests when you have a valid key:
export ITS_AI_API_KEY="sk_live_your_key"
export ITS_AI_E2E=1
python -m pytest -q
API Reference (brief)
ItsAIClient.analyze_text(text: str, deep_scan: bool = False, *, timeout: float | None = None) -> AnalyzeTextResultItsAIClient.analyze_batch(texts: list[str], deep_scan: bool = False, *, timeout: float | None = None, max_batch_size: int | None = None) -> list[AnalyzeBatchItemResult]- Async variants with the same signatures on
AsyncItsAIClient.
License
MIT
For API details and the hosted endpoint see https://api.its-ai.org.
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 its_ai-0.1.2.tar.gz.
File metadata
- Download URL: its_ai-0.1.2.tar.gz
- Upload date:
- Size: 19.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67fa88aebd4c84b29e616482397f6ca44983b78a6d7f3c016d39e760a67d9754
|
|
| MD5 |
91ef363c79ccbf40e1354b1dc44893ea
|
|
| BLAKE2b-256 |
08c984e2f0fcf131fc2a3e970423a83853e59c43ee3fa3ecef511f1e40c45b93
|
File details
Details for the file its_ai-0.1.2-py3-none-any.whl.
File metadata
- Download URL: its_ai-0.1.2-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26bab004a7c83191c7e4c563c20a1c883abd83f11dcea7a1add39d1a4ef96c0a
|
|
| MD5 |
e8ba358aa49556399211497d51774141
|
|
| BLAKE2b-256 |
08b593c0da99679b4e38a90a77208c4f023e5ed47d7450ed0b1ee655021423d5
|