Skip to content

Use the Python SDK

Your Python code asks the Gate before a tool runs, and gets back the decision, the result and the verdict.

Before you start

  • Python 3.10 to 3.14.
  • A running Deedglass server and an agent key. The Quickstart gives you both.

deedglass isn’t on PyPI yet. Until it is, install it from the repository:

Terminal window
pip install "deedglass @ git+https://github.com/deedglass/deedglass#subdirectory=sdk/python"

Each GitHub release also has the wheel. The client has one dependency, httpx. Extras: crypto for offline deed checks and signed intents, langchain and claude-agent-sdk for the adapters (deedglass[crypto] @ git+…).

Terminal
export DEEDGLASS_API_KEY="$(cat .deedglass/quickstart.key)"
export DEEDGLASS_SERVER=http://127.0.0.1:8080
agent.py
from deedglass import Deedglass, PolicyDeniedError
with Deedglass() as dg: # reads DEEDGLASS_API_KEY and DEEDGLASS_SERVER
try:
dg.act("postgres.execute", {"sql": "DROP TABLE public.orders"})
except PolicyDeniedError as e:
print("blocked:", e.message)
action = dg.act(
"postgres.execute",
{"sql": "UPDATE public.orders SET status = 'shipped' WHERE id = 42"},
wait_for_approval=120,
)
print(action)

The DROP raises PolicyDeniedError with the policy’s own sentence. The UPDATE waits up to 120 seconds for a person to approve it (under postgres-safe), runs, and prints a line like act_… · postgres.execute · executed · L2 · VERIFIED · deed_….

AsyncDeedglass has the same methods with await.

A MISMATCH is not an exception: the action ran and the Witness found a difference. Check it:

agent.py
from deedglass import Deedglass
dg = Deedglass()
action = dg.act("postgres.execute", {"sql": "UPDATE public.orders SET status = 'shipped' WHERE id = 42"})
if action.witness and action.witness.verdict == "MISMATCH":
print("Postgres changed something else:", action.witness.summary)
  • The SDK asks before your function runs and reports what happened. It doesn’t sandbox your function.
  • It doesn’t retry a 500: the server stores that answer under the request’s Idempotency-Key and would replay it.
  • The Python OpenAI Agents and CrewAI adapters aren’t built yet (0.2.1). Importing them raises ImportError saying so. The TypeScript SDK has an OpenAI Agents adapter.