Python SDK for Cyberette Deepfake Detection
Project description
cyberette-sdk-python
Python SDK for Cyberette Deepfake Detection
An async-first Python SDK for detecting deepfakes in images, videos, and audio files using the Cyberette API.
Installation
pip install cyberette
Requirements: Python 3.8+, aiohttp, pydantic
Quick Start
from cyberette_sdk import Cyberette
import asyncio
async def main():
async with Cyberette(api_key="YOUR_API_KEY") as client:
result = await client.upload("image.jpg")
print(result)
asyncio.run(main())
Initialization
client = Cyberette(
api_key="YOUR_API_KEY", # Required
timeout_seconds=300.0, # Default: 300s
verdict_thresholds=(0.5, 0.7), # (modified_threshold, generated_threshold)
verdict_labels=("Real", "AI Modified", "AI Generated"),
)
Verdict Thresholds
The SDK reclassifies the API score into a verdict using two thresholds:
| Score range | Verdict |
|---|---|
< modified_threshold |
"Real" (label[0]) |
>= modified_threshold and < generated_threshold |
"AI Modified" (label[1]) |
>= generated_threshold |
"AI Generated" (label[2]) |
Defaults: (0.5, 0.7) thresholds, ("Real", "AI Modified", "AI Generated") labels.
Uploading Files
Single upload
result = await client.upload("photo.jpg")
result = await client.upload("audio.mp3")
result = await client.upload("video.mp4")
Retries automatically on transient errors (3 retries, exponential backoff).
Batch upload
files = ["image1.jpg", "image2.jpg", "video.mp4", "audio.mp3"]
results = await client.batch_upload(files, concurrency=5)
for item in results:
print(item["file"], item["result"], item["error"])
Each item in the returned list: {"file": str, "result": dict | None, "error": Exception | None}
Folder upload
results = await client.upload_folder("path/to/folder", concurrency=5)
Uploads all files in the folder (non-recursive).
Event System
Register sync or async handlers for upload lifecycle events.
# Decorator style
@client.on("upload_started")
async def on_start(file_path):
print(f"Starting: {file_path}")
# Direct style
client.on("upload_success", lambda file_path, response: print(f"Done: {file_path}"))
Available events
| Event | Keyword args |
|---|---|
upload_started |
file_path |
upload_sent |
file_path, url |
upload_success |
file_path, response |
upload_error |
file_path, error |
batch_started |
files |
batch_file_success |
file, result |
batch_file_error |
file, error |
batch_finished |
results |
ResponseParser
Helper for extracting fields from response dicts.
from cyberette_sdk import ResponseParser
verdict = ResponseParser.get_detection_verdict(result)
confidence = ResponseParser.get_detection_percentage(result)
model = ResponseParser.get_model_name(result)
version = ResponseParser.get_model_version(result)
segments = ResponseParser.get_segments(result)
summary = ResponseParser.format_detection(result)
# "Model: <name> v<version>, Verdict: <verdict> (<confidence>%)"
seg_lines = ResponseParser.format_segments(result)
# ["Segment: 0.0 -> 2.5, Verdict: Real (0.12%)", ...]
For multimodal video responses, pass media="audio" or media="video":
audio_verdict = ResponseParser.get_detection_verdict(result, media="audio")
video_verdict = ResponseParser.get_detection_verdict(result, media="video")
Batch summary
summaries = ResponseParser.summarize_batch(results)
# [{"file": ..., "verdict": ..., "percentage": ..., "error": ...}, ...]
Pydantic Models
Type-safe wrappers for API responses.
from cyberette_sdk import ImageResponse, AudioResponse, VideoResponse, MultimodalVideoResponse
image = ImageResponse(**result)
print(image.deepfake.detection.verdict)
print(image.deepfake.detection.score)
audio = AudioResponse(**result)
print(audio.deepfake.detection.segments)
video = VideoResponse(**result)
multi = MultimodalVideoResponse(**result)
print(multi.audio.deepfake.detection.verdict)
print(multi.video.deepfake.detection.verdict)
All models: Segment, Detection, DeepfakeAnalysis, ImageResponse, AudioResponse, VideoResponse, MultimodalVideoResponse, BatchResultItem, BatchResult, ErrorResponse
Error Handling
async with Cyberette(api_key="YOUR_API_KEY") as client:
try:
result = await client.upload("image.jpg")
except FileNotFoundError:
print("File not found")
except Exception as e:
print(f"Error: {e}")
Examples
See the examples/ folder:
basic.py— Single file uploadbatch_usage.py— Batch uploadupload_folder.py— Folder uploadevents_direct.py— Event listeners (direct style)events_decorator.py— Event listeners (decorator style)events_batch.py— Batch events
Testing
pytest tests/ -v
pytest tests/ --cov=cyberette_sdk --cov-report=html
License
Apache License 2.0. See LICENSE for details.
Changelog
v0.1.3
- Added
upload_folder()method - Retry logic with exponential backoff on transient errors
- Configurable verdict thresholds and labels
v0.1.2
- Initial release
- Async upload via API gateway
- Batch processing with concurrency control
- Event system
- ResponseParser helpers
- Pydantic response models
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 cyberette-0.1.3.tar.gz.
File metadata
- Download URL: cyberette-0.1.3.tar.gz
- Upload date:
- Size: 20.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b191bddffaac3f7b9b6f5d5ec498371a016d007a6b88842553d5353073d47074
|
|
| MD5 |
2c68609879164c7c5bc849a8d42d9f99
|
|
| BLAKE2b-256 |
80c5480dc8cfc77ad7c07d62e2bdcecdc2df50bd69d9b2b9f83bc3eb23ee4691
|
File details
Details for the file cyberette-0.1.3-py3-none-any.whl.
File metadata
- Download URL: cyberette-0.1.3-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
996ab6a8fb3a7c98bd3e881cf0b0a6d7a80b9755644387757da2b5f494587030
|
|
| MD5 |
a3edfc425a4605b064ccf01b23814b8b
|
|
| BLAKE2b-256 |
eac8868ad35eef7e6ff75899a99a3123df0a4cf5bb4d1c52a93d38be484b3c17
|