Skip to main content

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) → MessageResponse
  • health() → HealthResponse
  • get_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.

Metadata

Release files for oktsec 0.16.1

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

Source distribution (sdist)

Source distribution for oktsec 0.16.1
File Size Uploaded
oktsec-0.16.1.tar.gz 7.7 kB Details

Built distribution (wheel)

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

Total release size: 14.4 kB

Release files / oktsec-0.16.1.tar.gz

Download URL oktsec-0.16.1.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
62f11f79ffbfaa9c2ce44bd16631f5a47a64c7dbe1ffbe31b359aa64169fc3e1
BLAKE2b-256 checksum
How to use checksums
564ae29c7ff562af3a5cfc2254b933b57a30e1b55085f9ccaac3ede0d77ab0f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 13, 2026.

Transparency log

Release files / oktsec-0.16.1-py3-none-any.whl

Download URL oktsec-0.16.1-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
669dc6b830f29723c67525da45eed5863d082b8d324039ac73e5da85f87df468
BLAKE2b-256 checksum
How to use checksums
e4c3d93221a0d12c6ba08c2d6c9be226a0ad3481ac09ad90371df82ab46cfce0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.16.1 This release

2 release files

0.16.0

2 release files

0.15.2

2 release files

0.13.2

2 release files

0.13.1

2 release files

0.13.0

2 release files

0.12.1

2 release files

0.12.0

2 release files

0.1.0

2 release files

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