forked fromcasbin/casbin-python-cli
- Notifications
You must be signed in to change notification settings - Fork0
Chimou0/casbin-python-cli
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
- 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
- Python 3.8+
- pip package manager
Clone from repository:
git clone https://github.com/casbin/casbin-python-cli.gitcd casbin-python-clipip install -r requirements.txtpython -m casbin_cli.client [command] [options] [args]
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"]}
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
| Category | Commands | Status |
|---|---|---|
| Policy Execution | enforce,enforceEx,enforceWithMatcher | ✅ |
| Policy Management | addPolicy,removePolicy,getPolicy,hasPolicy | ✅ |
| RBAC Operations | getRolesForUser,getUsersForRole,hasRoleForUser | ✅ |
| Data Retrieval | getAllSubjects,getAllObjects,getAllActions | ✅ |
| Grouping Policies | getGroupingPolicy,addGroupingPolicy,removeGroupingPolicy | ✅ |
| Named Policies | getNamedPolicy,getAllNamedRoles | ✅ |
| Filtered Queries | getFilteredPolicy,getFilteredGroupingPolicy | ✅ |
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- Python 3.8+
- PyCasbin 2.3.0+
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
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Languages
- Python100.0%