A set of access control descriptors for methods and nested classes
Project description
pryvacy - a set of access control decorators for python
Philosophy
- Incur as least overhead as possible when using the access control decorators
- Only classes that use the decorators need to be changed, other related classes do not need to -> Can be opted-in easily
Installation
pip install pryvacy
Usage
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
@privaye
def private_method(self):
pass
Access control rules:
- Methods inside
Fooare able to accesspublic_method,protected_method,private_method. - Code outside
Fooand not inside anyFoo's subclass methods can only accesspublic_method. - Methods inside
Foo's subclasses (either decorated with@pryvacyor not) can accesspublic_methodandprotected_method. - Nested classes methods can access
public_method,protected_method,private_method.
Pitfalls & Bugs
Disclaimer: The package has not been tested thoroughly! Use with caution! Any contributions are appreciated~
Currently, class-level code cannot access protected_method and private_method.
Example:
class Foo():
...
class Bar(Foo):
Foo().public_method() # OK!
Foo().protected_method() # Exception!
Foo().private_method() # Exception!
Current limitations
-
@privateand@protectedare not supported on nested classes yet. -
No way to enforce access policy on class and instance attributes.
Roadmap
-
Benchmark decorated classes
-
Test comprehensively the decorators interaction with the whole ecosystem
-
Implement @private and @protected on nested classes
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pryvacy-0.1.4.tar.gz.
File metadata
- Download URL: pryvacy-0.1.4.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/5.15.153.1-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e24803b2c528afbd1f52ad251ad29368e2f9730e81371ca83b9f6a955c7d713a
|
|
| MD5 |
3c0d46767961a760a49d4a9d92b373e1
|
|
| BLAKE2b-256 |
4b350afdd82f312c0acef481d6f20d26e0aa230d996c493991d5c84f6e721728
|
File details
Details for the file pryvacy-0.1.4-py3-none-any.whl.
File metadata
- Download URL: pryvacy-0.1.4-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/5.15.153.1-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
405c23731d77eae3f459f6cd1347de1f24cbbdb282bd031c3cd0b107068cf699
|
|
| MD5 |
f7aa4b1386ed89d9984135ac52f7e46d
|
|
| BLAKE2b-256 |
8b8f04f8ced4cf628b2defc886d99071e5eff306e0822d78f10e92fd1bb4a7ce
|