Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python CLI for Casbin

License

NotificationsYou must be signed in to change notification settings

Chimou0/casbin-python-cli

 
 

Repository files navigation

PyPI - Python VersionPyPI - LicensePyPI - PyCasbin Version

Features

  • casbin-editor Integration: Full API compatibility with casbin-editor for multi-language backend support
  • Unified JSON Response Format: Standardized{"allow": boolean|null, "explain": array|null} response format
  • Method Name Mapping: Automatic conversion between Java-style command names and Python method names
  • Comprehensive API Coverage: Support for policy execution, management, RBAC operations, and data retrieval
  • Cross-platform Binaries: Automated builds for Windows, macOS, and Linux
  • Dynamic Command Execution: Reflection-based method invocation similar to Java version

Installation

Prerequisites

  • Python 3.8+
  • pip package manager

Installation Methods

Clone from repository:

git clone https://github.com/casbin/casbin-python-cli.gitcd casbin-python-clipip install -r requirements.txt

Usage

Basic Command Structure

python -m casbin_cli.client [command] [options] [args]

Examples

Policy Execution:

# Basic enforcementpython -m casbin_cli.client enforce -m"examples/rbac_model.conf" -p"examples/rbac_policy.csv""alice""data1""read"{"allow":true,"explain":null}# Enforcement with explanationpython -m casbin_cli.client enforceEx -m"examples/rbac_model.conf" -p"examples/rbac_policy.csv""alice""data1""read"{"allow":true,"explain":["alice","data1","read"]}

Policy Management:

# Add policypython -m casbin_cli.client addPolicy -m"examples/rbac_model.conf" -p"examples/rbac_policy.csv""eve""data3""read"{"allow":true,"explain":null}# Get all policiespython -m casbin_cli.client getPolicy -m"examples/rbac_model.conf" -p"examples/rbac_policy.csv"{"allow":null,"explain":[["alice","data1","read"],["bob","data2","write"]]}

RBAC Operations:

# Get user rolespython -m casbin_cli.client getRolesForUser -m"examples/rbac_model.conf" -p"examples/rbac_policy.csv""alice"{"allow":null,"explain":["data2_admin"]}# Get role userspython -m casbin_cli.client getUsersForRole -m"examples/rbac_model.conf" -p"examples/rbac_policy.csv""data2_admin"{"allow":null,"explain":["alice"]}

Data Retrieval:

# Get all subjectspython -m casbin_cli.client getAllSubjects -m"examples/rbac_model.conf" -p"examples/rbac_policy.csv"{"allow":null,"explain":["alice","bob","data2_admin"]}# Get all objectspython -m casbin_cli.client getAllObjects -m"examples/rbac_model.conf" -p"examples/rbac_policy.csv"{"allow":null,"explain":["data1","data2"]}

API Compatibility

The Python CLI maintains full compatibility with the Java version through:

  • Command Interface: Identical command-line arguments (-m,-p, etc.)
  • Method Name Mapping: Automatic conversion from Java camelCase to Python snake_case
  • Response Format: Standardized JSON responses matching Java implementation
  • Error Handling: Consistent error reporting across all backends

Supported APIs

CategoryCommandsStatus
Policy Executionenforce,enforceEx,enforceWithMatcher
Policy ManagementaddPolicy,removePolicy,getPolicy,hasPolicy
RBAC OperationsgetRolesForUser,getUsersForRole,hasRoleForUser
Data RetrievalgetAllSubjects,getAllObjects,getAllActions
Grouping PoliciesgetGroupingPolicy,addGroupingPolicy,removeGroupingPolicy
Named PoliciesgetNamedPolicy,getAllNamedRoles
Filtered QueriesgetFilteredPolicy,getFilteredGroupingPolicy

Project Structure

casbin-python-cli/  ├── .github/  │   └── workflows/  │       └── release.yml           # GitHub Actions CI/CD  ├── scripts/  │   ├── update_version.py         # Version management  │   └── build_binaries.py         # Binary building  ├── casbin_cli/  │   ├── __init__.py  │   ├── __version__.py            # Version information│   ├── client.py                 # Main CLI entry point & argument parsing│   ├── command_executor.py       # Dynamic command execution & method mapping│   ├── enforcer_factory.py       # PyCasbin enforcer creation│   ├── response.py               # Standardized JSON response formatting│   └── utils.py                  # Utility functions├── examples/                     # Example model and policy files│   ├── rbac_model.conf          # RBAC model configuration│   ├── rbac_policy.csv          # RBAC policy data│   ├── basic_model.conf         # Basic model configuration│   └── basic_policy.csv         # Basic policy data├── tests/                       # Test files (if any)├── .releaserc.json              # Semantic release configuration├── package.json                 # Node.js dependencies for release automation├── requirements.txt             # Python dependencies├── setup.py                     # Package setup and distribution└── README.md                    # This file

Requirements

  • Python 3.8+
  • PyCasbin 2.3.0+

License

This project is licensed under the Apache License 2.0 - see theLICENSE file for details.


Note: This Python CLI is part of the Casbin ecosystem and designed to work seamlessly with casbin-editor for multi-language backend support. For more information about Casbin, visitcasbin.org.

About

Python CLI for Casbin

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python100.0%

[8]ページ先頭

©2009-2025 Movatter.jp