Enforcer
The core enforcement engine that intercepts function calls and applies policies.
Decorators
@enforce
Decorates an async function to enforce policies before execution.
@enforce(policy: str | dict, mode: str = "strict")Parameters:
policy(str | dict): Path to a YAML policy file or a dictionary configuration.mode(str): Enforcement mode."strict"(default) raisesPolicyViolationError,"monitor"logs violations but allows execution.
Example:
from enforcecore import enforce
@enforce(policy="strict-search.yaml")
async def search_web(query: str):
...Classes
Enforcer
Manages policy loading, caching, and evaluation.
__init__(config: dict = None)
Initializes the Enforcer with optional global configuration.
evaluate(context: dict) -> bool
Evaluates the current context against loaded policies. Returns True if allowed, False otherwise.