Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: Added python bindings for casbin::Config #139

Merged
merged 4 commits into from
Aug 15, 2021

Conversation

EmperorYP7
Copy link
Member

@EmperorYP7 EmperorYP7 commented Aug 10, 2021

Fixes #84 partially

Signed-off-by: Yash Pandey (YP) yash.btech.cs19@iiitranchi.ac.in


Description

This code:

  • Implements python bindings for casbin::Config
  • Modified the API to facilitate the bindings
  • Added python tests for pycasbin.Config and pycasbin.Model

The workflow enabled by the API exposed to the python side can be abstracted as follows:

import pycasbin as casbin

# For casbin.Config
config = casbin.Config.NewConfig('path/to/config/file.ini')
config = casbin.Config.NewConfigFromText('<contents of the config>')
ok = config.GetBool('<key>')
num_value = config.GetInt('<key')

# ... and so on

# For casbin.Model
model = casbin.Model.NewModel() # empty model
model = casbin.Model.NewModelFromFile('path/to/model.conf')
model = casbin.Model.NewModelFromString('<contents of the model>')

# Demonstrating casbin.Model.LoadModelFromConfig
config = casbin.Config.NewConfig('path/to/model.conf')
model = casbin.Model.NewModel()
model.LoadModelFromConfig(config)

Screenshots

Screenshot 2021-08-10 at 9 59 06 PM

Signed-off-by: Yash Pandey (YP) <yash.btech.cs19@iiitranchi.ac.in>
Signed-off-by: Yash Pandey (YP) <yash.btech.cs19@iiitranchi.ac.in>
Signed-off-by: Yash Pandey (YP) <yash.btech.cs19@iiitranchi.ac.in>
Signed-off-by: Yash Pandey (YP) <yash.btech.cs19@iiitranchi.ac.in>
@EmperorYP7
Copy link
Member Author

@hsluoyz @xcaptain Kindly review this one

@hsluoyz hsluoyz merged commit 24d43ce into casbin:master Aug 15, 2021
@github-actions
Copy link

🎉 This PR is included in version 1.37.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python bindings to facilitate PyCasbin-on-CPP
2 participants