Skip to main content

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 Foo are able to access public_method, protected_method, private_method.
  • Code outside Foo and not inside any Foo's subclass methods can only access public_method.
  • Methods inside Foo's subclasses (either decorated with @pryvacy or not) can access public_method and protected_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

  • @private and @protected are 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

pryvacy-0.1.4.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

pryvacy-0.1.4-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

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

Hashes for pryvacy-0.1.4.tar.gz
Algorithm Hash digest
SHA256 e24803b2c528afbd1f52ad251ad29368e2f9730e81371ca83b9f6a955c7d713a
MD5 3c0d46767961a760a49d4a9d92b373e1
BLAKE2b-256 4b350afdd82f312c0acef481d6f20d26e0aa230d996c493991d5c84f6e721728

See more details on using hashes here.

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

Hashes for pryvacy-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 405c23731d77eae3f459f6cd1347de1f24cbbdb282bd031c3cd0b107068cf699
MD5 f7aa4b1386ed89d9984135ac52f7e46d
BLAKE2b-256 8b8f04f8ced4cf628b2defc886d99071e5eff306e0822d78f10e92fd1bb4a7ce

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