Skip to content

micropermission is a simple action-based permission library for Python

Notifications You must be signed in to change notification settings

9diov/micropermission

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

micropermission is a simple action-based permission library for Python. Permission rules are defined as ability to do some action against some resource.

Example usage

class Note(object):
    def __init__(self, msg):
        self.message = msg

# Class based 
p = Permission()
p.define_ability('read', Note)
n = Note('message')
assert p.can('read', n)

# Object based
n = Note('message')

p = Permission()
p.define_ability('read', n)
assert p.can('read', n)

# Proc based
p = Permission()
p.define_ability('read', Note, lambda n: n.message == 'hello')
n = Note('message')
assert not p.can('read', n)
n = Note('hello')
assert p.can('read', n)

# Decorator
p = Permission()
p.define_ability('read', Note)

@p.authorize('write', Note)
def read_note(n):
    pass

n = Note('hello')
read_note(n) # Raise PermissionDenied exception

About

micropermission is a simple action-based permission library for Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published