Official TruthScan Python client for AI image detection — presign, upload, detect, and poll for results.
Project description
TruthScan Image Detection — Python Client
Official Python client for the TruthScan AI Image Detection API. Detect whether images are AI-generated, real, digitally edited, or AI-edited.
Requirements
- Python 3.9+
- A TruthScan API key (get one here)
Installation
pip install truthscan-image-detector-client
Quick start
import os
from truthscan.image_detection import ImageDetectionClient
api_key = os.environ.get("TRUTHSCAN_API_KEY", "your_api_key_here")
client = ImageDetectionClient(api_key=api_key)
result = client.detect("path/to/image.jpg")
print(f"Status: {result['status']}")
print(f"Score: {result.get('result', 'N/A')}")
print(f"Final: {(result.get('result_details') or {}).get('final_result', '')}")
How it works
ImageDetectionClient.detect() runs the full workflow for you:
- Presign — request a presigned upload URL for the image filename
- Upload — upload the image bytes to storage
- Detect — submit the image for analysis and receive a detection ID
- Poll — call the query endpoint until status is
done(or timeout)
You only need one method call; polling interval and max attempts are configurable on detect().
Send a request and poll manually
For step-by-step control, use ImageDetectionService:
from truthscan.image_detection import ImageDetectionService
service = ImageDetectionService(
base_url="https://ai-image-detect.undetectable.ai",
api_key=api_key,
)
presign = service.get_presigned_url("photo.jpg")
service.upload(presign["presigned_url"], "path/to/photo.jpg")
file_url = ImageDetectionService.build_detect_file_url(
presign["file_path"], presign["presigned_url"]
)
detect = service.detect(file_url)
result = service.poll_for_result(detect["id"], max_attempts=60, sleep_seconds=0.5)
print(result["status"], result.get("result_details"))
Configuration
from truthscan.image_detection import ImageDetectionClient, DefaultConsoleLogger
client = ImageDetectionClient(
api_key="YOUR_API_KEY",
base_url=None,
timeout=60,
logger=DefaultConsoleLogger("info"),
)
API reference
ImageDetectionClient
| Method | Description |
|---|---|
detect(image, email?, generate_preview?, max_poll_attempts?, poll_interval_seconds?) |
Full workflow: presign, upload, detect, poll. Returns DetectionResult. |
check_user_credits() |
Returns credit balance for the API key. |
Supported file formats
JPG, JPEG, PNG, WebP, JFIF, HEIC, HEIF, AVIF, BMP, TIFF, TIF, GIF, SVG, PDF
File size limits: 1 KB – 10 MB
Note: Remove spaces from filenames before uploading.
Development
cd python
pip install -e .
python tests/test_client.py
License
MIT
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 truthscan_image_detector_client-20260526.0.0.tar.gz.
File metadata
- Download URL: truthscan_image_detector_client-20260526.0.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6cef8e949e364dedceda9e92d2e5e3d83542d230819a32b34cc042ab9da0125e
|
|
| MD5 |
e5aaa8bd96f7eca9df0349aebc0f540f
|
|
| BLAKE2b-256 |
f95fa294d8b53e489ffa2b19fedcce8cc02bd0d756ae15dbfd4188ddc05da7fb
|
File details
Details for the file truthscan_image_detector_client-20260526.0.0-py3-none-any.whl.
File metadata
- Download URL: truthscan_image_detector_client-20260526.0.0-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0a3a04326c9960324632b434e21c93eb45cc44682e50715eadaea47ccee183e
|
|
| MD5 |
fdf639dfa1bdfcfbdb24a9cdd7fb7d01
|
|
| BLAKE2b-256 |
4164961abb217ccb911e18697a083a881efc13b608f72415afb49a0424811ad7
|