AI Firewall Python SDK
Validate AI agent actions against policies before execution.
Installation
pip install ai-firewall
Or install from source:
cd sdk/python
pip install -e .
Quick Start
from ai_firewall import AIFirewall
# Initialize the client
fw = AIFirewall(
api_key="af_your_api_key",
project_id="your-project-id",
base_url="http://localhost:8000" # Your firewall server URL
)
# Validate an action before executing
result = fw.execute(
agent_name="invoice_agent",
action_type="pay_invoice",
params={
"vendor": "VendorA",
"amount": 5000,
"currency": "USD"
}
)
if result.allowed:
# Safe to proceed with the action
pay_invoice(result.action_id)
else:
# Action was blocked
print(f"Blocked: {result.reason}")
log_blocked_action(result.action_id, result.reason)
Strict Mode
Use strict mode to automatically raise an exception when actions are blocked:
fw = AIFirewall(
api_key="af_xxx",
project_id="my-project",
strict=True # Raises ActionBlockedError when blocked
)
try:
result = fw.execute("agent", "risky_action", {"amount": 1000000})
# This only runs if action is allowed
do_risky_action()
except ActionBlockedError as e:
print(f"Action {e.action_id} was blocked: {e.reason}")
Policy Management
# Get current policy
policy = fw.get_policy()
print(f"Policy version: {policy.version}")
print(f"Rules: {policy.rules}")
# Update policy
new_policy = fw.update_policy(
rules=[
{
"action_type": "pay_invoice",
"constraints": {
"params.amount": {"max": 10000}
}
}
],
version="2.0"
)
Audit Logs
# Get recent logs
logs = fw.get_logs(page=1, page_size=50)
for entry in logs.items:
status = "✓" if entry.allowed else "✗"
print(f"{status} {entry.agent_name}: {entry.action_type}")
# Filter blocked actions
blocked = fw.get_logs(allowed=False)
# Get statistics
stats = fw.get_stats()
print(f"Block rate: {stats['block_rate']}%")
Context Manager
with AIFirewall(api_key="...", project_id="...") as fw:
result = fw.execute("agent", "action", {})
# Connection automatically closed
Exceptions
from ai_firewall import (
AIFirewallError, # Base exception
AuthenticationError, # Invalid API key
ProjectNotFoundError, # Project doesn't exist
PolicyNotFoundError, # No active policy
ActionBlockedError, # Action blocked (strict mode)
NetworkError, # Connection failed
)
License
MIT
Metadata
Release files for ai-firewall 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ai_firewall-0.1.0.tar.gz | 6.2 kB | Without provenance | Details for ai_firewall-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ai_firewall-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for ai_firewall-0.1.0-py3-none-any.whl |
Total release size: 12.9 kB
Release files / ai_firewall-0.1.0.tar.gz
| Download URL | ai_firewall-0.1.0.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4c2cc31417fef4d556e4edab2ea648bd756c56934a588a66f57e31ab8410a813
|
|
BLAKE2b-256 checksum How to use checksums |
73cd0a1619728f74318ed270ff7e7ca9467a1c933962ddc4a424bdca634952a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / ai_firewall-0.1.0-py3-none-any.whl
| Download URL | ai_firewall-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9c44ff67154884e05b2cb351a80b1eb304ecdae261a00dd369329080167e1039
|
|
BLAKE2b-256 checksum How to use checksums |
a506ad83aa9c99489f40fa4cea1952a0794e3e9c36e20ac6f64e36a0740bddda
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for ai-firewall 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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.