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
- API: https://swiftapi.ai
- Documentation: https://getswiftapi.com/docs
Built by Rayan Pal. No AI action executes without verification.
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 swiftapi_python-1.0.3.tar.gz.
File metadata
- Download URL: swiftapi_python-1.0.3.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d75262b4210b45900c2d8586dfa5178cbcd2813eecb329bc2bf15d47a115534
|
|
| MD5 |
5ec40adcd38a51dfebb33ff81b1fba17
|
|
| BLAKE2b-256 |
d10796764830d847ac841678887e69682688766d7c57bb9a58bebb3f6bba138a
|
File details
Details for the file swiftapi_python-1.0.3-py3-none-any.whl.
File metadata
- Download URL: swiftapi_python-1.0.3-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7d70417820744e30c09689484553fcd430eafb0c10c9ca3f5e922b6e3a2d4e9
|
|
| MD5 |
93ffe223e08be22755e0e9739a8a5b11
|
|
| BLAKE2b-256 |
ac1c5b116cfef55d949d9505d3681614a8552b0f27346ce0c169a3318ef657d7
|