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.
Terminal window
pip install deedglass

The client has one dependency, httpx. Extras: deedglass[crypto] for offline deed checks and signed intents, deedglass[langchain] and deedglass[claude-agent-sdk] for the adapters.

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 OpenAI Agents and CrewAI adapters come in the next release. Importing them today raises ImportError saying so.