
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
A Python SDK for the Reality Defender API to detect deepfakes and manipulated media.
# Using pip
pip install realitydefender
# Using poetry
poetry add realitydefender
First, you need to obtain an API key from the Reality Defender Platform.
This approach uses direct polling to wait for the analysis results.
import asyncio
from realitydefender import RealityDefender
async def main():
# Initialize the SDK with your API key
print("Initializing Reality Defender SDK...")
rd = RealityDefender(api_key="your-api-key")
# Upload a file for analysis
print("Uploading file for analysis...")
response = await rd.upload(file_path="/path/to/your/file.jpg")
request_id = response["request_id"]
print(f"File uploaded successfully. Request ID: {request_id}")
# Get results by polling until completion
print("Waiting for analysis results...")
result = await rd.get_result(request_id)
print("Analysis complete!")
# Process the results
print("\nResults:")
print(f"Status: {result['status']}")
print(f"Score: {result['score']}")
# List model results
print("\nModel details:")
for model in result["models"]:
print(f"{model['name']}: {model['status']} (Score: {model['score']})")
# Run the async function
asyncio.run(main())
This approach uses event handlers to process results when they become available.
import asyncio
from realitydefender import RealityDefender
async def main():
# Initialize the SDK
print("Initializing Reality Defender SDK...")
rd = RealityDefender(api_key="your-api-key")
# Set up event handlers
print("Setting up event handlers...")
rd.on("result", lambda result: print(f"Result received: {result['status']} (Score: {result['score']})"))
rd.on("error", lambda error: print(f"Error occurred: {error.message}"))
# Upload and start polling
print("Uploading file for analysis...")
response = await rd.upload(file_path="/path/to/your/file.jpg")
request_id = response["request_id"]
print(f"File uploaded successfully. Request ID: {request_id}")
print("Starting to poll for results...")
await rd.poll_for_results(response["request_id"])
print("Polling complete!")
# Run the async function
asyncio.run(main())
The SDK is designed with a modular architecture for better maintainability and testability:
The Reality Defender SDK uses asynchronous operations throughout.
rd = RealityDefender(
api_key="your-api-key", # Required: Your API key
)
# Must be called from within an async function
response = await rd.upload(file_path="/path/to/file.jpg") # Required: Path to the file to analyze
)
Returns: {"request_id": str, "media_id": str}
# Must be called from within an async function
# This will poll until the analysis is complete
result = await rd.get_result(request_id)
Returns a dictionary with detection results:
{
"status": str, # Overall status (e.g., "MANIPULATED", "AUTHENTIC")
"score": float, # Overall confidence score (0-1)
"models": [ # Array of model-specific results
{
"name": str, # Model name
"status": str, # Model-specific status
"score": float # Model-specific score (0-1)
}
]
}
# Set up event handlers before polling
rd.on("result", callback_function) # Called when results are available
rd.on("error", error_callback_function) # Called if an error occurs
# Start polling (must be called from within an async function)
await rd.poll_for_results(request_id)
# Clean up when done (must be called from within an async function)
await rd.cleanup()
The SDK raises exceptions for various error scenarios:
try:
result = rd.upload(file_path="/path/to/file.jpg")
except RealityDefenderError as error:
print(f"Error: {error.message} ({error.code})")
# Error codes: 'unauthorized', 'server_error', 'timeout',
# 'invalid_file', 'upload_failed', 'not_found', 'unknown_error'
See the examples
directory for more detailed usage examples.
To run the example code in this SDK, follow these steps:
# Navigate to the python directory
cd python
# Install the package in development mode
pip install -e .
# Set your API key
export REALITY_DEFENDER_API_KEY='<your-api-key>'
# Run the example
python examples/basic_usage.py
The example code demonstrates how to upload a sample image and process the detection results.
FAQs
SDK for the Reality Defender deepfake detection API
We found that realitydefender demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.