Govern any AI call in 2 lines. Drop-in governance SDK for OpenAI, Anthropic, Google, and any LLM — policy evaluation, evidence generation, and audit-ready compliance metadata on every request.
Project description
codex-govern
Govern any AI call in 2 lines. Drop-in governance SDK for OpenAI, Anthropic, Google, and any LLM — policy evaluation, evidence generation, and audit-ready compliance metadata on every request.
pip install codex-govern
Why codex-govern?
Every AI call your application makes should be governed — policy-checked, evidence-stamped, and audit-ready. codex-govern wraps your existing AI calls with zero refactoring:
- Policy enforcement — ALLOW / DENY / REQUIRE_APPROVAL on every request
- Evidence generation — SHA-256 checksum + evidence bundle per call
- Audit trail — every request logged with model, tokens, latency, decision
- Multi-provider — OpenAI, Anthropic, Google, and more through one interface
- Minimal dependency — only
requests(no heavy frameworks) - Python 3.9+ — works everywhere Python runs
Quick Start
from codex_govern import CodexGovern
govern = CodexGovern(
base_url="https://your-gateway.example.com",
token="your-jwt-token",
)
# Governed chat completion — same shape as OpenAI, plus governance metadata
result = govern.chat(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Summarize the quarterly report."}],
mission="DOCUMENT_ANALYSIS",
)
print(result["choices"][0]["message"]["content"]) # AI response
print(result["governance"]["live"]) # True = real model call
print(result["governance"]["policyDecision"]) # "ALLOW"
print(result["governance"]["checksumSha256"]) # SHA-256 evidence hash
How It Works
Your code
↓
codex-govern SDK
↓
CodexDominion Governance Gateway
↓
┌─────────────────────────────────────────────┐
│ 1. Policy evaluation (allow / deny / approve)│
│ 2. Model execution (live or simulated) │
│ 3. Evidence generation (SHA-256 checksum) │
│ 4. Audit logging (tokens, latency, decision) │
└─────────────────────────────────────────────┘
↓
Response + governance metadata
API Reference
Constructor
govern = CodexGovern(
base_url: str, # Gateway URL
token: str, # JWT auth token
default_model: str = "gpt-4o-mini", # Default model
default_mission: str = "CHAT_COMPLETION", # Default mission type
timeout: int = 30, # Request timeout in seconds
)
govern.chat(...) — Governed Chat Completion
Send a governed chat request. Routes through Policy Engine → Model Execution → Evidence Generation.
result = govern.chat(
messages=[{"role": "user", "content": "Hello"}],
model="gpt-4o-mini", # optional, uses default
mission="CHAT_COMPLETION", # optional, uses default
provider="openai", # optional, auto-detected
temperature=0.7, # optional
max_tokens=1000, # optional
metadata={"tag": "demo"}, # optional, attached to governance record
)
govern.ask(prompt, ...) — Quick One-Liner
Returns the assistant's response content directly as a string.
answer = govern.ask("What is governed AI?")
print(answer) # "Governed AI is..."
# With options
answer = govern.ask(
"Explain this code",
model="gpt-4o",
mission="CODE_REVIEW",
system_prompt="You are a senior engineer.",
)
govern.models() — Available Models
for m in govern.models():
status = "LIVE" if m["live"] else "SIMULATED"
print(f"{m['id']}: {status}")
govern.stats() — Gateway Statistics
stats = govern.stats()
print(f"{stats['totalRequests']} total, {stats['totalLive']} live")
print(f"Policy: {stats['policyBreakdown']['ALLOW']} allowed, {stats['policyBreakdown']['DENY']} denied")
govern.requests(limit=50) — Recent Requests
for r in govern.requests(limit=10):
print(f"{r['model']} → {r['policyDecision']} ({r['latencyMs']}ms)")
govern.login(email, password) — Authenticate
govern.login("user@example.com", "password")
# Token is stored automatically — all subsequent calls are authenticated
govern.set_token(token) — Set Token Directly
govern.set_token("your-new-jwt-token")
Response Shape
Every govern.chat() response includes standard AI fields plus governance metadata:
{
"id": "550e8400-...",
"model": "gpt-4o-mini",
"choices": [
{"message": {"role": "assistant", "content": "..."}}
],
"usage": {
"prompt_tokens": 18,
"completion_tokens": 31,
"total_tokens": 49
},
"governance": {
"governed": true,
"live": true,
"policyDecision": "ALLOW",
"evidenceId": "ev-...",
"checksumSha256": "sha256:51dbddd5...",
"totalLatencyMs": 1293
}
}
Error Handling
from codex_govern import CodexGovern, CodexGovernError
try:
result = govern.chat(messages=[{"role": "user", "content": "Hello"}])
except CodexGovernError as e:
print(f"Governance error {e.status}: {e}")
print(f"Body: {e.body}")
Architecture
┌──────────────────────────────────────────────────────┐
│ codex-govern SDK │
│ (Python 3.9+ · requests · Typed) │
└────────────────────────┬─────────────────────────────┘
│ HTTPS / JWT
┌────────────────────────▼─────────────────────────────┐
│ CodexDominion Governance Gateway │
│ │
│ ┌──────────┐ ┌──────────┐ ┌───────────────────┐ │
│ │ Policy │→│ Model │→│ Evidence │ │
│ │ Engine │ │ Execution│ │ Generation │ │
│ └──────────┘ └──────────┘ └───────────────────┘ │
│ │
│ Providers: OpenAI · Anthropic · Google · More │
└──────────────────────────────────────────────────────┘
Requirements
- Python 3.9+
requests(only runtime dependency)
Links
License
MIT — see LICENSE for details.
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 codex_govern-1.0.0.tar.gz.
File metadata
- Download URL: codex_govern-1.0.0.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd9ab26ba7a0610c8f82c34eaf26f86ed9bdbde26eb619189a158ef23643d299
|
|
| MD5 |
aa0c6bdcdb6e516e690662ae231914e1
|
|
| BLAKE2b-256 |
9af8994a47e43acb7437eee7a69f6a4edbb8230adda17bc709f029881d9d773b
|
File details
Details for the file codex_govern-1.0.0-py3-none-any.whl.
File metadata
- Download URL: codex_govern-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01e2743fb5be63ad2c401a5edc70d1d90478298ddb4fcfff3fa4f8432e143d2b
|
|
| MD5 |
ca2111d4406ec84f2f7e6737b4dfbe2c
|
|
| BLAKE2b-256 |
fd5bfa26c210a8a494714c9c109be336ffde956f51663f11aebfaf0799c546f5
|