Skip to content

API Reference - Util

pypermission.util.role.role_dag(*, root_roles: set[str] | None = None, include_subjects: bool = True, include_permissions: bool = True, db: Session) -> nx.DiGraph

Generate a directed acyclic graph (DAG) that reflects the role hierarchy from the viewpoint of the root_roles. By definition, the resulting DAG does not contain any roles that are descendants of those root roles.

Parameters:

Name Type Description Default
root_roles set[str] | None

Root Roles of the generated DAG. If its None, all existing Roles will be included.

None
include_subjects bool

Include assigned Subjects in the DAG.

True
include_permissions bool

Include granted Permissions in the DAG.

True

Returns:

Type Description
DiGraph

The generated DAG.

pypermission.util.plot.plot_factory(*, dag: nx.DiGraph, auto_open: bool = False, file_path: str = 'dag.html') -> None

Generate an interactive HTML visualization of an RBAC DAG and save it to file_path.

Parameters:

Name Type Description Default
dag DiGraph

The RBAC system DAG.

required
auto_open bool

Automatically opens the plot in the browser.

False
file_path str

Path and filename for the generated HTML as string.

'dag.html'

Raises:

Type Description
PyPermissionError

Raised when the input DAG is empty, indicating that there is no data to plot.