Skip to main content

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)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.

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

oktsec-0.16.1.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

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

oktsec-0.16.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file oktsec-0.16.1.tar.gz.

File metadata

  • Download URL: oktsec-0.16.1.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for oktsec-0.16.1.tar.gz
Algorithm Hash digest
SHA256 62f11f79ffbfaa9c2ce44bd16631f5a47a64c7dbe1ffbe31b359aa64169fc3e1
MD5 a1641a6239ddc22d16c2c436f0f79aa0
BLAKE2b-256 564ae29c7ff562af3a5cfc2254b933b57a30e1b55085f9ccaac3ede0d77ab0f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for oktsec-0.16.1.tar.gz:

Publisher: pypi.yml on oktsec/oktsec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file oktsec-0.16.1-py3-none-any.whl.

File metadata

  • Download URL: oktsec-0.16.1-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for oktsec-0.16.1-py3-none-any.whl
Algorithm Hash digest
SHA256 669dc6b830f29723c67525da45eed5863d082b8d324039ac73e5da85f87df468
MD5 c357236dd3d57ebf177874579036e95f
BLAKE2b-256 e4c3d93221a0d12c6ba08c2d6c9be226a0ad3481ac09ad90371df82ab46cfce0

See more details on using hashes here.

Provenance

The following attestation bundles were made for oktsec-0.16.1-py3-none-any.whl:

Publisher: pypi.yml on oktsec/oktsec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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