Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Python bindings to facilitate PyCasbin-on-CPP #84

Closed
EmperorYP7 opened this issue Mar 14, 2021 · 13 comments · Fixed by #123, #128, #129, #130 or #135
Closed

Python bindings to facilitate PyCasbin-on-CPP #84

EmperorYP7 opened this issue Mar 14, 2021 · 13 comments · Fixed by #123, #128, #129, #130 or #135
Assignees
Labels
enhancement New feature or request

Comments

@EmperorYP7
Copy link
Member

EmperorYP7 commented Mar 14, 2021

The project has the potential to utilize its C++ API for PyCasbin-on-CPP through Python bindings which will allow us to call C++ code from Python. CPython exposes various endpoints for us to make bindings, but this approach will be cumbersome and vulnerable to a lot of errors and memory leaks which won't be easy to debug. pybind11 can be used for making Python bindings and modules with C++11 as it is based on Boost::Python library.

@Zxilly
Copy link

Zxilly commented Mar 28, 2021

Yes, this is our plan.
Before actually create the wrapper, we need to assure that casbin-cpp have all api of pycasbin.
Pycasbin on cpp will be regard as an optional high performance backend of pycasbin. But not a separate library.

@EmperorYP7
Copy link
Member Author

@Zxilly I tried to make a boilerplate for the workflow to make these bindings and management of pybind11 module with CMake.
Here's the dev branch: https://github.com/EmperorYP7/casbin-cpp/tree/python-bindings kindly look at ./CMakeLists.txt and /ext/Findpybind11.cmake

Is it somewhat similar to what you envisioned for this?

@EmperorYP7
Copy link
Member Author

Here's the dev branch: https://github.com/EmperorYP7/casbin-cpp/tree/python-bindings kindly look at ./CMakeLists.txt and /ext/Findpybind11.cmake

@hsluoyz @xcaptain is this approach feasible?

@Zxilly
Copy link

Zxilly commented Apr 5, 2021

Good work.
You can create a Pull Request for this.

@hsluoyz
Copy link
Member

hsluoyz commented Apr 6, 2021

@EmperorYP7 I don't know the detailed Py-Cpp binding techniques, but we want:

  1. Compatible across all OS: Windows, Linux, macOS
  2. Simple, modern
  3. Good performance

@EmperorYP7
Copy link
Member Author

@hsluoyz yes, the bindings will be cross-platform. The performance will be similar to the resultant of Boost.Python library. It would be significantly more efficient than native Python performance.

@EmperorYP7
Copy link
Member Author

Good work.
You can create a Pull Request for this.

Sure. But I think I should research it a bit more before diving in.

@hsluoyz
Copy link
Member

hsluoyz commented Apr 6, 2021

@EmperorYP7 does pybind11 require CMake? I think we are not using CMake in this repo now? I remembered we are using .sln for Windows MSVC and makefile for Linux, the repo doesn't even build for macOS yet. How to resolve this?

@EmperorYP7
Copy link
Member Author

EmperorYP7 commented Apr 6, 2021

does pybind11 require CMake?

Not necessarily, but it's the best way to get it done. Details: https://pybind11.readthedocs.io/en/stable/compiling.html

I think we are not using CMake in this repo now?

The project currently supports building the casbin library through CMake.

the repo doesn't even build for macOS yet

It does through CMake. But not reliably.
Screenshot 2021-04-06 at 4 47 55 PM

@hsluoyz I am willing to work on an easy-to-maintain build system based on CMake. This would also include .sln and .proj files on building for Windows while also being compatible with Linux and macOS. Kindly see this file: https://github.com/EmperorYP7/casbin-cpp/blob/python-bindings/CMakeLists.txt

@hsluoyz
Copy link
Member

hsluoyz commented Apr 6, 2021

lgtm!

@hsluoyz
Copy link
Member

hsluoyz commented Oct 28, 2021

@EmperorYP7 can you share what parts are still missing to make PyCasbin-on-CPP work? Maybe @sheny1xuan and @noob20000405 can continue the work. Should we open this issue again or raise a new issue to track the progress?

@EmperorYP7
Copy link
Member Author

can you share what parts are still missing to make PyCasbin-on-CPP work?

I completely missed this one!

  • Making pycasbin module pip installable instead of building it locally from the source.
  • Benchmarking pycasbin's performance to compare it with Python's casbin implementation

@hsluoyz
Copy link
Member

hsluoyz commented Jan 20, 2022

@EmperorYP7 great! Created two issues:

#180

#181

# for free to join this conversation on GitHub. Already have an account? # to comment