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.1.tar.gz (6.9 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.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pryvacy-0.1.1.tar.gz
  • Upload date:
  • Size: 6.9 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.1.tar.gz
Algorithm Hash digest
SHA256 aa2e312178a2a5fb9c9696073da78cdf5fbbbf2a2e25fad640b653c52bd89bcc
MD5 fd0564f0de446bfadc1666cdb1ebe648
BLAKE2b-256 7d6012658728266a6fc40fb70688ad634c250e32a7678588c4f19f657c8ee895

See more details on using hashes here.

File details

Details for the file pryvacy-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pryvacy-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 828e80786389abbc099b6a0cc97c76e005cf470c330f6d2da63a67f212d3cb9a
MD5 4faa68a12ed0bd6b4e60e5a044ed4453
BLAKE2b-256 457f30d8c32b68743002a65005ec4029bf2f51921918885fab15ee1dfd3acd7f

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