Skip to main content

SwiftAPI Python SDK - AI Action Verification Gateway

Project description

SwiftAPI Python SDK

No AI action executes without verification.

SwiftAPI is the ignition key for AI agents. This SDK provides Python bindings for the SwiftAPI execution governance protocol.

Installation

pip install swiftapi-python

Quick Start

from swiftapi import SwiftAPI, Enforcement

# Initialize client with your API key
api = SwiftAPI(key="swiftapi_live_...")

# Create an enforcement point
guard = Enforcement(api)

# THE LINE THAT SAVES THE COMPANY
guard.run(
    lambda: os.system("rm -rf /tmp/data"),
    action="file_delete",
    intent="Cleanup temporary files"
)

If the action is denied by policy, a PolicyViolation exception is raised and nothing executes.

Features

  • Cryptographic Enforcement: Ed25519 signed attestations prove authorization
  • Offline Verification: Verify attestation signatures without network calls
  • Policy Enforcement: Actions blocked if they violate configured policies
  • Rate Limiting: Built-in handling for API rate limits
  • Beautiful Output: Color-coded terminal output for approvals/denials

Usage Patterns

1. Direct Execution

from swiftapi import SwiftAPI, Enforcement

api = SwiftAPI(key="swiftapi_live_...")
guard = Enforcement(api)

# Execute with verification
result = guard.run(
    lambda: dangerous_operation(),
    action="database_write",
    intent="Update user preferences"
)

2. Decorator

@guard.protect(action="api_call", intent="Send notification")
def send_notification(user_id: str, message: str):
    # This only runs if SwiftAPI approves
    notification_service.send(user_id, message)

# Usage - automatically enforced
send_notification("user123", "Hello!")

3. Context Manager

with guard.guard(action="file_write", intent="Save configuration"):
    # This block only executes if approved
    with open("/etc/myapp/config.json", "w") as f:
        json.dump(config, f)

4. One-off Enforcement

from swiftapi import SwiftAPI, enforce

api = SwiftAPI(key="swiftapi_live_...")
enforce(api, lambda: risky_operation(), action="admin", intent="Reset system")

Paranoid Mode

For maximum security, enable paranoid mode to check revocation status online:

guard = Enforcement(api, paranoid=True)

This adds an extra network call but ensures revoked attestations are caught in real-time.

Offline Verification

You can verify attestation signatures without any network calls:

from swiftapi import verify_signature, is_valid

# Verify signature (raises exception if invalid)
verify_signature(attestation)

# Check validity without exceptions
if is_valid(attestation):
    print("Attestation is valid")

Error Handling

from swiftapi import (
    SwiftAPI,
    Enforcement,
    PolicyViolation,
    SignatureVerificationError,
    AttestationRevokedError,
)

api = SwiftAPI(key="swiftapi_live_...")
guard = Enforcement(api)

try:
    guard.run(lambda: delete_everything(), action="nuke", intent="YOLO")
except PolicyViolation as e:
    print(f"Action denied: {e.denial_reason}")
except SignatureVerificationError:
    print("CRITICAL: Attestation signature is invalid!")
except AttestationRevokedError as e:
    print(f"Attestation {e.jti} was revoked")

API Client

The SDK also provides direct API access:

from swiftapi import SwiftAPI

api = SwiftAPI(key="swiftapi_live_...")

# Get API info
info = api.get_info()

# Verify an action
result = api.verify(
    action_type="file_write",
    intent="Save user data",
    params={"path": "/data/users.json"}
)

# Check attestation revocation
is_revoked = api.check_revocation(jti="attestation-id")

# List authority keys (admin only)
keys = api.list_keys()

# Create new key (admin only)
new_key = api.create_key(name="agent-1", scopes=["verify"])

Configuration

api = SwiftAPI(
    key="swiftapi_live_...",
    base_url="https://swiftapi.ai",  # Default
    timeout=30,  # Request timeout in seconds
)

guard = Enforcement(
    client=api,
    paranoid=False,  # Enable online revocation checks
    verbose=True,    # Print status messages
)

The Golden Loop

Every protected action goes through this verification chain:

┌─────────────────────────────────────────────────────────┐
│                    THE GOLDEN LOOP                       │
├─────────────────────────────────────────────────────────┤
│                                                          │
│  1. API CALL                                            │
│     client.verify() ──────────────────────────────┐     │
│                                                    │     │
│  2. CRYPTO CHECK (Offline Truth)                  │     │
│     verifier.verify_signature() ◄─────────────────┤     │
│                                                    │     │
│  3. ONLINE CHECK (Optional/Paranoid)              │     │
│     client.check_revocation() ◄───────────────────┤     │
│                                                    │     │
│  4. EXECUTE                                        │     │
│     func() ◄──────────────────────────────────────┘     │
│                                                          │
│  If ANY step fails → PolicyViolation raised             │
│  The action NEVER executes without full verification    │
│                                                          │
└─────────────────────────────────────────────────────────┘

License

MIT License - See LICENSE file for details.

Links


Built by Rayan Pal. No AI action executes without verification.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swiftapi_python-1.2.0.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

swiftapi_python-1.2.0-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file swiftapi_python-1.2.0.tar.gz.

File metadata

  • Download URL: swiftapi_python-1.2.0.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for swiftapi_python-1.2.0.tar.gz
Algorithm Hash digest
SHA256 5923dbcf35347aa2f929e199e8099172c7b6113777dc1ac59e3940499a387006
MD5 d8de40bbd08bdcf4f2f5869b49bcd40f
BLAKE2b-256 c23daa9ede01ef43d95daada138afb03471d647282eee3433d97e8799ae87344

See more details on using hashes here.

File details

Details for the file swiftapi_python-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for swiftapi_python-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 125ba96c83729a7ba1bc772259d412c9f38f41dde480f2126b7db3fe069c5533
MD5 6de0cf1e6f59101eeccbf3b91e5f09fe
BLAKE2b-256 c4d81f9c056061fa5d8fe118b86b2a1f4d23ce59e3ff46a5040304f86d985c16

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page