Python bindings for the Dogwood
policy frontend: a PyO3 shell over
dogwood-ops, the host-neutral
operations the dogwood CLI and @aws/dogwood-wasm share (reports, errors,
the live authorizer, input limits, fail-closed rules). This package only
converts Python values and maps OpError to dogwood.DogwoodError.
pip install dogwood-awsWheels are published for Linux (glibc and musl; x86_64 and aarch64), macOS (x86_64 and arm64) and Windows (x64 and arm64). One abi3 wheel per platform covers CPython >= 3.9. Elsewhere pip builds from the sdist, which needs a Rust toolchain.
import dogwood as dw
schema = dw.mcp_to_cedar_schema(tools) # str or list of tool dicts
report = dw.validate(policy, schema) # dict, see the .pyi stubs
auth = dw.DogwoodAuthorizer(policy, schema)
d = auth.is_authorized({"action": "Drupe::Action::SendEmail", "timestamp": 20,
"principal": {"type": "Drupe::User", "id": "agent"},
"context": {"input": {...}}, "logged": {"input": {...}}})
if not d["allowed"]: ...Same surface and semantics as @aws/dogwood-wasm, in snake_case. Differences:
- Errors raise
dogwood.DogwoodError;.diagnosticis the same dict as the JS error's.diagnostic. decimal.Decimalmaps to a Cedar decimal (exact text);tupleworks as a list;boolnever becomes aLong; anintoutside i64 raises.last_timestampis anint(nof64widening needed in Python).- Every call releases the GIL;
DogwoodAuthorizeris thread-safe (an internal mutex — the engine isSendbut notSync) and the module declares free-threaded support (gil_used = false). - One abi3 wheel covers CPython >= 3.9.
Built against dogwood-language 1.2, which checks events against the
schemas at run time:
- a request's context must match the action's context type (the MCP template
now requires
context.system.now, a Cedardatetime, given as{"__extn": {"fn": "datetime", "arg": "2026-01-01T00:00:00Z"}}); - a history event (e.g. a
response) whose logged record does not conform to its signature is not recorded:is_authorizedraisesDogwoodError("event rejected, not recorded in the history") and leaves the history untouched, andreplaylists it inrejected; - a
.logtrace must logcallerResourceas well ascallerPrincipal.
python3 -m venv .venv && .venv/bin/pip install maturin pytest
VIRTUAL_ENV=$PWD/.venv .venv/bin/maturin develop
.venv/bin/python -m pytest crates/dogwood-python/tests
.venv/bin/python crates/dogwood-python/examples/demo.pypyproject.toml is at the repository root so the package can carry
LICENSE, NOTICE and THIRD-PARTY-NOTICES. Generate the last with
scripts/third-party-notices.sh (needs cargo-about) before building a
distribution; a release fails without it.
.github/workflows/ci.yml runs on every PR and push to main, and daily:
build-test:cargo build --locked, generatesTHIRD-PARTY-NOTICES, builds the abi3 wheel with maturin, runspytestagainst the installed wheel on CPython 3.13 and runsexamples/demo.pyon CPython 3.9 (the oldest supported version) in a digest-pinnedpython:3.9-slimcontainer;cargo-deny: RustSec advisories, licenses, bans and sources (deny.toml);pip-audit: audits the hash-pinned tools inci/requirements.txtandci/test-requirements.txt;secret-scan: scans the full git history for committed credentials with gitleaks (pinned by version and SHA-256 inci.yml).
To change those tools, edit the .in file next to them and recompile with
the command at its top.
DESIGN.md describes how the bindings work. Releases are
published to PyPI by .github/workflows/release.yml when a
v* tag is pushed; see RELEASING.md.
See CONTRIBUTING.md and SECURITY.md.