An extensible library for managing object-level permissions with support for SQLAlchemy, Peewee, Pony, and Django.
Project description
guardrail is a Python library for managing object-level permissions that’s designed to integrate with arbitrary databases and web frameworks. guardrail is inspired by django-guardian and currently supports the SQLAlchemy, Peewee, Pony, and Django ORMs.
guardrail is easy to integrate with any Python web framework. Documentation and usage examples coming soon.
Install
pip install guardrail
guardrail supports Python >= 2.7 or >= 3.3 and pypy.
Examples
Define your models as usual, using the registry.agent and registry.target decorators to set up permissions relationships:
import peewee as pw
from guardrail.core import registry
from guardrail.ext.peewee import PeeweePermissionSchemaFactory
database = pw.SqliteDatabase(':memory:')
class Base(pw.Model):
class Meta:
database = database
@registry.agent
class User(Base):
name = pw.CharField()
@registry.target
class Post(Base):
name = pw.CharField()
@registry.target
class Comment(Base):
name = pw.CharField()
factory = PeeweePermissionSchemaFactory((Base, ))
registry.make_schemas(factory)
database.connect()
database.create_tables([User, Post, Comment], safe=True)
database.create_tables(registry.permissions, safe=True)
Then use the permission manager to perform CRUD operations on permissions between any agent and target models:
from guardrail.ext.peewee import PeeweePermissionManager
manager = PeeweePermissionManager()
user = User.create(name='fred')
post = Post.create(name='news of the world')
comment = Comment.create(name='dragon attack')
manager.add_permission(user, post, 'edit')
manager.add_permission(user, comment, 'delete')
manager.has_permission(user, post, 'edit') # True
manager.remove_permission(user, comment, 'delete')
manager.has_permission(user, comment, 'delete') # False
Project Links
License
MIT licensed. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for guardrail-0.1.0.macosx-10.5-x86_64.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a74d3ed2253509f3b6b39928d43af66ad5ab67bfc951b22d936b8cd8e4e6ee8 |
|
MD5 | 25daf314c2cf580d0cd8e186e1b264f4 |
|
BLAKE2b-256 | d8d3d4e71c0074492f13cc07869542bce7202652e6f2e21f3157220bfab39ae8 |