Cedar Python
Python bindings for Cedar, the open-source policy language for access control. This library lets you define, validate, and evaluate authorization policies directly from Python.
Installation
pip install cedar-python
Quick Start
from cedar import Authorizer, EntityUid, Policy, PolicySet, Request
# Create policies
policies = PolicySet('''
permit(principal == User::"alice", action == Action::"read", resource);
forbid(principal, action == Action::"delete", resource);
''')
# Create and evaluate a request
request = Request(
EntityUid("User", "alice"),
EntityUid("Action", "read"),
EntityUid("Document", "doc1"),
)
authorizer = Authorizer()
response = authorizer.is_authorized(request, policies)
print(response.allowed) # True
Core API
Entities
from cedar import Entity, EntityUid, Context
# Entity identifiers
uid = EntityUid("User", "alice")
uid.entity_type() # "User"
uid.id() # "alice"
# Entities with attributes and hierarchy
user = Entity(
uid=EntityUid("User", "alice"),
attrs={"email": "alice@example.com", "role": "admin"},
parents=[EntityUid("Group", "admins")]
)
# Context for requests
context = Context({"ip_address": "10.0.0.1", "authenticated": True})
Authorization
from cedar import Authorizer, Request, Response
# Authorizer with entity hierarchy
authorizer = Authorizer(entities=[user, group])
# Full request with context
request = Request(
principal=EntityUid("User", "alice"),
action=EntityUid("Action", "read"),
resource=EntityUid("Document", "doc1"),
context=Context({"time": "2024-01-01T00:00:00Z"})
)
response = authorizer.is_authorized(request, policies)
response.allowed # bool
response.decision # "Allow" or "Deny"
response.reason # Policy IDs that contributed to decision
response.errors # Any evaluation errors
Schema Validation
Validate entities, requests, and context against a schema:
from cedar import Authorizer, Context, EntityUid, Request, Schema
schema = Schema.from_json('''...''')
action = EntityUid("Action", "read")
# Validate context against schema (requires action to determine expected shape)
context = Context({"ip_address": "10.0.0.1"}, schema=schema, action=action)
# Validate request components against schema
request = Request(
principal=EntityUid("User", "alice"),
action=action,
resource=EntityUid("Document", "doc1"),
context=context,
schema=schema
)
# Validate entities when creating the authorizer
authorizer = Authorizer(entities=[user, doc], schema=schema)
# Validate request components using stored schema
authorizer.validate_request(principal, action, resource, context)
Dynamic Entity Management
Add, update, or remove entities in an existing authorizer:
from cedar import Authorizer, Entity, EntityUid
authorizer = Authorizer()
# Add a new entity (fails if entity already exists)
alice = Entity(EntityUid("User", "alice"), {"role": "admin"})
authorizer.add_entity(alice)
# Upsert an entity (adds or replaces existing)
alice_updated = Entity(EntityUid("User", "alice"), {"role": "user"})
authorizer.upsert_entity(alice_updated)
# Remove an entity by UID
authorizer.remove_entity(EntityUid("User", "alice"))
# With schema validation
schema = Schema.from_json('''...''')
authorizer = Authorizer(schema=schema)
doc = Entity(EntityUid("Document", "doc1"), {"owner": "alice"})
authorizer.add_entity(doc) # Validates against schema
Policies
from cedar import Policy, PolicySet
# Single policy
policy = Policy('permit(principal, action, resource);', id="policy1")
policy.id() # "policy1"
policy.effect() # "Permit"
policy.annotations() # {"id": "policy1"}
policy.to_cedar() # Formatted Cedar syntax
policy.to_json() # JSON representation
# Policy sets
policy_set = PolicySet('''
@id("read-access")
permit(principal, action == Action::"read", resource);
''')
policy_set.policies() # List of Policy objects
policy_set.policy("read-access") # Get by ID
len(policy_set) # Number of policies
Schemas
from cedar import Schema
# From JSON
schema = Schema.from_json('''{
"": {
"entityTypes": {"User": {}, "Document": {}},
"actions": {
"read": {"appliesTo": {"principalTypes": ["User"], "resourceTypes": ["Document"]}}
}
}
}''')
# From Cedar schema syntax
schema = Schema.from_cedarschema('''
entity User;
entity Document;
action read appliesTo { principal: User, resource: Document };
''')
schema.entity_types() # ["User", "Document"]
schema.actions() # ["read"]
schema.principals() # Entity types that can be principals
schema.resources() # Entity types that can be resources
Validation
Validate policies against a schema for type checking and error detection:
from cedar import PolicySet, Schema
# Create schema and policies
schema = Schema.from_cedarschema('''
entity User;
entity Document;
action read appliesTo { principal: User, resource: Document };
''')
policies = PolicySet('''
permit(principal == User::"alice", action == Action::"read", resource);
''')
# Validate policies against schema
result = schema.validate_policyset(policies)
result.valid # True if validation passed
result.errors # List of ValidationError objects
result.warnings # List of ValidationWarning objects
# ValidationError/ValidationWarning have policy_id and message attributes
for error in result.errors:
print(f"{error.policy_id}: {error.message}")
Schema Module
Pydantic models for building schemas programmatically:
from cedar.schema import CedarSchema, NamespaceDefinition, EntityType, Action, AppliesTo
schema = CedarSchema(root={
"": NamespaceDefinition(
entityTypes={"User": EntityType()},
actions={"read": Action(appliesTo=AppliesTo(principalTypes=["User"]))}
)
})
Lean Module (Formal Verification)
Symbolic policy analysis using cedar-lean-cli:
from cedar.lean import (
check_equivalent,
check_implies,
check_disjoint,
compare_policysets,
analyze_policies,
)
# Check if two policies are equivalent
result = check_equivalent(policy1, policy2, schema)
result.satisfied # True if equivalent
result.counterexample # Example where they differ (if not equivalent)
# Compare policy sets
comparison = compare_policysets(old_policies, new_policies, schema)
comparison.is_equivalent # True if all request signatures are equivalent
comparison.more_permissive # Request envs where source allows more
comparison.less_permissive # Request envs where source allows less
CLI
# Validate a policy against a schema
cedar schema validate policy.cedar schema.json
# Run the MCP server
cedar mcp
MCP Server
For AI coding assistants, Cedar provides an MCP server with policy tools:
pip install cedar-python[mcp]
cedar mcp
Available tools: validate_policy, validate_policy_set, validate_schema, format_policy
License
Metadata
Release files for cedar-python 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cedar_python-0.1.4.tar.gz | 126.8 kB | Details |
Built distributions (wheels)
Total release size: 60.4 MB
Release files / cedar_python-0.1.4.tar.gz
| Download URL | cedar_python-0.1.4.tar.gz |
|---|---|
| Size | 126.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6006a0db7fc314bb0d157e6d6d259acb380bb02a2735c919554581145a648043
|
|
BLAKE2b-256 checksum How to use checksums |
b8bceaeeb3683fb8d9a262187d42255197549458cfa5c6bf49c5ff36e0d22355
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / cedar_python-0.1.4-cp314-cp314-win_amd64.whl
| Download URL | cedar_python-0.1.4-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
a8781f5a01ab770e0cda1cd3e2cc6d90114091353f896c7774b371f06195f992
|
|
BLAKE2b-256 checksum How to use checksums |
61298bccab1c1fe1c03ca4b36022c04d58961a475c82ef986ce14136a8f4bc86
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / cedar_python-0.1.4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | cedar_python-0.1.4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 4.3 MB |
| Tags | CPython 3.14 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
f9526b582aaa7027f601b3ab3d929768db436ff2fac5924468fd9f3db7cc91e4
|
|
BLAKE2b-256 checksum How to use checksums |
68354a3bed56fcb5e1df31e7582ed8591a2c5bc62c15bd0fabf37b9032a2d4ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / cedar_python-0.1.4-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | cedar_python-0.1.4-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 4.2 MB |
| Tags | CPython 3.14 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
d9c4f6169b1d44d7e4fe419b46159459c669626a525c49ef5697853ee1da4457
|
|
BLAKE2b-256 checksum How to use checksums |
591260dff22827d64f6f768e748d5bac39f11fdbf2f6017a02425522a87c22dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / cedar_python-0.1.4-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | cedar_python-0.1.4-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 3.8 MB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
b41b5b447affd68ca2bce5567d1e4b65bce222ed5d5102bdd9c8f159802a6f68
|
|
BLAKE2b-256 checksum How to use checksums |
f727c67c024fbf6e678c1a4cff379e290fc505fdace4b727a51065802af471b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / cedar_python-0.1.4-cp314-cp314-macosx_10_12_x86_64.whl
| Download URL | cedar_python-0.1.4-cp314-cp314-macosx_10_12_x86_64.whl |
|---|---|
| Size | 4.0 MB |
| Tags | CPython 3.14 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
282bdde7236645a08ba63aaf2cfc920c2d7ff391aabf1a1528e81155f64e4daa
|
|
BLAKE2b-256 checksum How to use checksums |
6bbfae630a82bb8c75bd8969cf457275fd6d47350e0ab2b74f030603195e6e00
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / cedar_python-0.1.4-cp313-cp313-win_amd64.whl
| Download URL | cedar_python-0.1.4-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
b38e0c7c9acad95f1e84e561b88e178a49c54d56e51c33a40c0d6b80d07385b9
|
|
BLAKE2b-256 checksum How to use checksums |
034f50ffdfa7fff50aef0ad81cffe1ce4883c79819a55ac6b46cba69ec09cfb9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / cedar_python-0.1.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | cedar_python-0.1.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 4.3 MB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
e6dcd098df1e00b66f3398a1b166f70248a4c01e2a1dd8d5437b5956e6ddab5d
|
|
BLAKE2b-256 checksum How to use checksums |
4678d4dcc53d9967ce443ec3d47f0e74a917852a40cfa0e1682a66e738c592a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / cedar_python-0.1.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | cedar_python-0.1.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 4.2 MB |
| Tags | CPython 3.13 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
3343dfa00f63c8cdfa285bb516136697c23ad015f71f2212ddc18f4a3d1e8287
|
|
BLAKE2b-256 checksum How to use checksums |
71c3d521b6f937814b0b3880f89eb0ced64284633e730ed9dd18c636e97a6bc3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / cedar_python-0.1.4-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | cedar_python-0.1.4-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 3.8 MB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
b6f08055fa92536791eb69d141ab3baf8ba93c5553c1c2b0893e282dbca27b49
|
|
BLAKE2b-256 checksum How to use checksums |
1996dfeead1ed7cd00870cff8f7cbc482ac6c5f8d5e9f8eb94ce297a9517adca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / cedar_python-0.1.4-cp313-cp313-macosx_10_12_x86_64.whl
| Download URL | cedar_python-0.1.4-cp313-cp313-macosx_10_12_x86_64.whl |
|---|---|
| Size | 4.0 MB |
| Tags | CPython 3.13 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
9f697cef012c95e96a40354922e461aa2b7c952fdf0d4cb3af365ee17f513b74
|
|
BLAKE2b-256 checksum How to use checksums |
c343c51a75d9677c2cbdc2938900b8aef30381c1bf1bb2830d00fbba2aea8ca5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / cedar_python-0.1.4-cp312-cp312-win_amd64.whl
| Download URL | cedar_python-0.1.4-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
532f7fdff3a55aad8443f5ac3183fa0937effc5162098aaf5efe1ff627da6387
|
|
BLAKE2b-256 checksum How to use checksums |
6ae543bc79c0289871e6195c24df06cecf13bb9012ec4a8d5ae669238d6ddbf4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / cedar_python-0.1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | cedar_python-0.1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 4.3 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
6eca6ab21cca34c79a8770ca540c18b78006e0a8f4db4308e2697b00101c8f34
|
|
BLAKE2b-256 checksum How to use checksums |
00cdcb798acc873f3b1a844278c412b59df76c81dc3c2827041de08d7b691c7e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / cedar_python-0.1.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | cedar_python-0.1.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 4.2 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
6091f3a82efbdf6979eaacec92cd410903e727fddf39021811de95a031cc5d90
|
|
BLAKE2b-256 checksum How to use checksums |
d4e14f68a70034759b061d2aa0a8b21e2c92edae7c654e52e93146e7bc89b969
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / cedar_python-0.1.4-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | cedar_python-0.1.4-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 3.8 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
350139ace8f9baa983538a1601128b2f8a77639ceed10de50e86f030b5405233
|
|
BLAKE2b-256 checksum How to use checksums |
4423f8f3254579695b6916297e35e566edee3b5999ca20bfd1e2a90f102dd099
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / cedar_python-0.1.4-cp312-cp312-macosx_10_12_x86_64.whl
| Download URL | cedar_python-0.1.4-cp312-cp312-macosx_10_12_x86_64.whl |
|---|---|
| Size | 4.0 MB |
| Tags | CPython 3.12 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
e85fb56f955db469898d930613c29660bb5ab76fb395b3f04089d60e228b2ebe
|
|
BLAKE2b-256 checksum How to use checksums |
0580e05bf327f350a8ec64c94194f54740854ef77633124822f980e61a02834c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|