Skip to main content

Adversaria Python SDK

Python SDK for Adversaria - Adversarial Testing Harness for LLMs.

Installation

pip install adversaria

Note: This SDK requires the Adversaria CLI to be installed:

cargo install adversaria

Quick Start

from adversaria import Adversaria

# Create client
client = Adversaria()

# Run tests
result = client.run(
    provider="openai",
    model="gpt-4",
    api_key="sk-..."  # Optional, uses OPENAI_API_KEY env var
)

# Check results
print(f"Risk Score: {result.risk_score}/100")
print(f"Successful Attacks: {result.successful_attacks}/{result.total_attacks}")

# Save report
report_path = result.save_report("./reports")
print(f"Report saved: {report_path}")

API Reference

Adversaria

Main client class for running security tests.

client = Adversaria(config_path=None)

Methods:

run(provider, model, suites=None, api_key=None)

Run security tests against an LLM.

Arguments:

  • provider (str): Provider name ('openai', 'anthropic', 'ollama')
  • model (str): Model name
  • suites (list, optional): List of suite IDs to run
  • api_key (str, optional): API key (uses env var if not provided)

Returns: TestResult

list_suites()

List available attack suites.

Returns: List[Suite]

list_reports(directory="./reports")

List available reports.

Returns: List[str] - List of report file paths

load_report(filepath)

Load a report from file.

Returns: TestResult

TestResult

Test execution results.

Attributes:

  • id (str): Unique test run ID
  • model (str): Model tested
  • provider (str): Provider used
  • timestamp (str): Test timestamp
  • risk_score (int): Overall risk score (0-100)
  • total_attacks (int): Total attacks executed
  • successful_attacks (int): Number of successful attacks
  • failed_attacks (int): Number of failed attacks
  • duration_ms (int): Execution time in milliseconds
  • raw_data (dict): Full report data

Methods:

save_report(directory="./reports")

Save report to directory.

Returns: str - Path to saved report

Examples

Basic Testing

import os
from adversaria import Adversaria

# Set API key
os.environ["OPENAI_API_KEY"] = "sk-..."

# Run test
client = Adversaria()
result = client.run(provider="openai", model="gpt-4")

if result.risk_score > 50:
    print("⚠️ High risk detected!")

Specific Suites

result = client.run(
    provider="openai",
    model="gpt-4",
    suites=["prompt_injection", "jailbreak"]
)

Multiple Providers

providers = [
    ("openai", "gpt-4"),
    ("anthropic", "claude-3-opus-20240229"),
]

for provider, model in providers:
    result = client.run(provider=provider, model=model)
    print(f"{provider}/{model}: {result.risk_score}/100")

Load Previous Report

client = Adversaria()

# List all reports
reports = client.list_reports()

# Load latest report
if reports:
    result = client.load_report(reports[0])
    print(f"Risk Score: {result.risk_score}/100")

Requirements

  • Python 3.8+
  • Adversaria CLI (cargo install adversaria)
  • PyYAML

License

MIT

Metadata

Release files for adversaria 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for adversaria 0.1.0
File Size Uploaded Provenance
adversaria-0.1.0.tar.gz 4.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for adversaria 0.1.0
File Interpreter ABI Platform
adversaria-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.1 kB

Release files / adversaria-0.1.0.tar.gz

Download URL adversaria-0.1.0.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8a6d68976e4b3c25a81c22153c77064bfed520c913ad94c05e966f1079953fa5
BLAKE2b-256 checksum
How to use checksums
aa16a8125379b21e00ce77929ed2ecc2b0270d6122d7bd0fe717af645e85e629
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

Release files / adversaria-0.1.0-py3-none-any.whl

Download URL adversaria-0.1.0-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d5f3d635ed9356279bc9652e6e1de9bc8c02fe1e40f0ec71fb9e1d9ce7a1d5ae
BLAKE2b-256 checksum
How to use checksums
17dbb785d463e3ebfb9beb60702556a9097b91e4708c295d6822f9c79ef251ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

Security for adversaria 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page