Skip to content

Add pycasbin-on-cpp: Python bindings for casbin-cpp#2

Open
Copilot wants to merge 5 commits intomasterfrom
copilot/add-pycasbin-cpp-wrapper
Open

Add pycasbin-on-cpp: Python bindings for casbin-cpp#2
Copilot wants to merge 5 commits intomasterfrom
copilot/add-pycasbin-cpp-wrapper

Conversation

Copy link

Copilot AI commented Jan 8, 2026

Implements Python bindings for casbin-cpp to provide C++-powered performance for pycasbin. Expected 10-50x speedup for enforcement and 5-20x for policy loading.

Implementation

  • Build System: CMake-based setup.py with pybind11 integration, fetches nlohmann/json automatically
  • Core Bindings (src/bindings.cpp):
    • Enforcer class with enforcement, policy CRUD, RBAC, and management APIs
    • Type conversions: DataVector for enforce parameters, PoliciesValues to Python lists
    • FileAdapter support
  • Dependencies: Added as git submodules (pybind11 v3.0.2, casbin-cpp v1.53.2)

Usage

from pycasbin_cpp import Enforcer

e = Enforcer('model.conf', 'policy.csv')

# Enforcement
e.enforce(['alice', 'data1', 'read'])  # True/False
result, explain = e.enforce_ex(['alice', 'data1', 'read'])

# Policy management
e.add_policy(['bob', 'data2', 'write'])
policies = e.get_policy()  # Returns list of lists

# RBAC
roles = e.get_roles_for_user('alice')
e.add_role_for_user('bob', 'admin')

Installation

git clone --recursive https://github.com/casbin/pycasbin-on-cpp.git
cd pycasbin-on-cpp
pip install .
Original prompt

This section details on the original issue you should resolve

<issue_title>[feature] add the code of pycasbin-on-cpp</issue_title>
<issue_description>wrap the pycasbin based on: https://github.com/casbin/casbin-cpp

so C++ powers the new pycasbin lib. the speed will be fast.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@hsluoyz hsluoyz marked this pull request as ready for review January 8, 2026 16:12
Copilot AI and others added 4 commits January 8, 2026 16:18
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Copilot AI changed the title [WIP] Add pycasbin wrapper for C++ implementation Add pycasbin-on-cpp: Python bindings for casbin-cpp Jan 8, 2026
Copilot AI requested a review from hsluoyz January 8, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] add the code of pycasbin-on-cpp

3 participants