Access control decorators for python classes
APACHE-2.0 License
pip install pryvacy
The package provides 3 access control decorators: @private
, @public
, @protected
that can be used on methods and nested classes (currently only @private
can be used on nested classes)
from pryvacy import pryvacy, private, public, protected
@pryvacy
class Foo():
@public
def public_method(self):
pass
@protected
def protected_method(self):
pass
@private
def private_method(self):
pass
Access control rules:
Foo
are able to access public_method
, protected_method
, private_method
.Foo
and not inside any Foo
's subclass methods can only access public_method
.Foo
's subclasses (either decorated with @pryvacy
or not) can access public_method
and protected_method
.public_method
, protected_method
, private_method
.Disclaimer: The package has not been tested thoroughly! Use with caution! Any contributions are appreciated~
protected_method
and private_method
. class Foo():
...
class Bar(Foo):
Foo().public_method() # OK!
Foo().protected_method() # Exception!
Foo().private_method() # Exception!
test_back_and_forth
test is failing. This scenario is unlikely to happen but I will try to come up with a performant solution.@private
and @protected
are not supported on nested classes yet.
No way to enforce access policy on class and instance attributes.
Benchmark decorated classes
Test comprehensively the decorators interaction with the whole ecosystem
Implement @private and @protected on nested classes