Python SDK for the oktsec security proxy — identity, policy, and content scanning for AI agent communication
Project description
oktsec Python SDK
Python client for the oktsec security proxy — identity verification, policy enforcement, and content scanning for AI agent communication.
Install
pip install oktsec
Quick start
from oktsec import Client
with Client("http://localhost:8080", "my-agent") as c:
resp = c.send_message("recipient", "hello from Python")
print(resp.status, resp.message_id)
With Ed25519 signing
from oktsec import Client, load_keypair
kp = load_keypair("./keys", "my-agent")
with Client("http://localhost:8080", "my-agent", keypair=kp) as c:
resp = c.send_message("recipient", "signed message")
print(resp.verified_sender) # True
Async support
import asyncio
from oktsec import AsyncClient
async def main():
async with AsyncClient("http://localhost:8080", "my-agent") as c:
resp = await c.send_message("recipient", "async hello")
print(resp.status)
asyncio.run(main())
Error handling
from oktsec import Client, PolicyError
with Client("http://localhost:8080", "my-agent") as c:
try:
resp = c.send_message("target", "suspicious content")
except PolicyError as e:
print(f"Rejected: {e.response.policy_decision}")
print(f"HTTP {e.status_code}")
for rule in e.response.rules_triggered:
print(f" - {rule.rule_id}: {rule.name} ({rule.severity})")
Generate keypairs
from oktsec import generate_keypair
kp = generate_keypair("new-agent")
kp.save("./keys")
API
Client(base_url, agent_name, keypair=None, timeout=30.0)
send_message(to, content, metadata=None)→MessageResponsehealth()→HealthResponseget_quarantine(quarantine_id)→dict
AsyncClient(base_url, agent_name, keypair=None, timeout=30.0)
Same methods, all async.
load_keypair(directory, name) → Keypair
Loads Ed25519 keys from PEM files. Compatible with oktsec keygen output.
generate_keypair(name) → Keypair
Generates a new Ed25519 keypair.
License
Apache 2.0 — same as oktsec.
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 oktsec-0.15.2.tar.gz.
File metadata
- Download URL: oktsec-0.15.2.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db3e9f53a83d73aa4011232c246aa6f52b3051fe0000556c7f633ee2f0a7751a
|
|
| MD5 |
09fc6e95d82bec0d24c39252e1f70210
|
|
| BLAKE2b-256 |
c86391d1b64e95dbb5ce814b2e3cae841102f4e7f8e48edceddfe73500fb181b
|
File details
Details for the file oktsec-0.15.2-py3-none-any.whl.
File metadata
- Download URL: oktsec-0.15.2-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c1e0685ba25179c12477ccd602ee6b4ce4e2a38dfb601f0bb78443a4539cc59
|
|
| MD5 |
8cc2a662090a509bd00bd2733a5c0165
|
|
| BLAKE2b-256 |
a7ad6f91b556a63ebe9f82a50bef819df1a628a2a472a90986f75d40762fa235
|