Skip to main content

An extensible library for managing object-level permissions with support for SQLAlchemy, Peewee, Pony, and Django.

Project description

Latest version Travis CI

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.



pip install guardrail

guardrail supports Python >= 2.7 or >= 3.3 and pypy.


Define your models as usual, using the registry.agent and 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

class User(Base):
    name = pw.CharField()
class Post(Base):
    name = pw.CharField()
class Comment(Base):
    name = pw.CharField()

factory = PeeweePermissionSchemaFactory((Base, ))

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


MIT licensed. See the LICENSE file for details.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for guardrail, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size guardrail-0.1.1.macosx-10.5-x86_64.tar.gz (25.0 kB) File type Dumb Binary Python version any Upload date Hashes View
Filename, size guardrail-0.1.1.tar.gz (12.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page