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.

Homepage: https://guardrail.readthedocs.org/

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

License

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.

Source Distribution

guardrail-0.1.1.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

guardrail-0.1.1.macosx-10.5-x86_64.tar.gz (25.0 kB view details)

Uploaded Source

File details

Details for the file guardrail-0.1.1.tar.gz.

File metadata

  • Download URL: guardrail-0.1.1.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for guardrail-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2279eae52aa00108a9197c3ea594db561df60720e79d970de620423b6842abe9
MD5 14177c9e583b2a715eb50e7e975c2a83
BLAKE2b-256 566840cd6d0aa7d3bf7bd62d2214671b7cf1402b47dd0cac74c97b8632d893fa

See more details on using hashes here.

File details

Details for the file guardrail-0.1.1.macosx-10.5-x86_64.tar.gz.

File metadata

File hashes

Hashes for guardrail-0.1.1.macosx-10.5-x86_64.tar.gz
Algorithm Hash digest
SHA256 e2016b5555f4efc7c1876ad94ef8033b35d7c89970d96e27494f89a7ba08fb43
MD5 8a457648cf380c3e9cbda4bda626b101
BLAKE2b-256 23ef0dd6a4a149f8df00bcf01668c504de2040f7b5057f936d960db1bc5dd9b1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page