Skip to main content

SDK for working with Cerbos: an open core, language-agnostic, scalable authorization solution

Project description

Cerbos Python SDK

Python client for accessing Cerbos.

Cerbos is the open core, language-agnostic, scalable authorization solution that makes user permissions and authorization simple to implement and manage by writing context-aware access control policies for your application resources.

Usage

Making a request

import cerbos.sdk.model.*
from cerbos.sdk.client import CerbosClient

with CerbosClient("https://localhost:3592", debug=True, tls_verify=False) as c:
    p = Principal(
        "john",
        roles={"employee"},
        policy_version="20210210",
        attr={"department": "marketing", "geography": "GB", "team": "design"},
    )
    r = Resource(
        "XX125",
        "leave_request",
        policy_version="20210210",
        attr={
            "id": "XX125",
            "department": "marketing",
            "geography": "GB",
            "team": "design",
            "owner": "john",
        },
    )
    print(c.is_allowed("view:public", p, r))

Testing with TestContainers

from cerbos.sdk.client import CerbosClient
from cerbos.sdk.container import CerbosContainer

container = CerbosContainer()
policy_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "store")
container.with_volume_mapping(policy_dir, "/policies")

with container:
    container.wait_until_ready()

    host = container.http_host()
    with CerbosClient(host) as c:
        ...

Get help

Development

This project uses PDM with Pyprojectx for package management. The pw script should be used when working with this project.

Adding a new dependency

./pw pdm add dataclasses-json

Adding a tool

# Add black to lint group
./pw pdm add -dG lint black

Formatting code

./pw format

Running tests

./pw test

Running a REPL

./pw pdm run python

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cerbos-0.1.0.tar.gz (15.0 kB view hashes)

Uploaded Source

Built Distribution

cerbos-0.1.0-py3-none-any.whl (11.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page