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.2.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.2-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pryvacy-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 faf60faa370d612b29eb519eeff04c7fc4a8be04ec91b2d1a7b34f6f96f53356
MD5 f258bf41374839ef352401e3fa670672
BLAKE2b-256 7cf57a45dac2e6bb3b790e4c14df8e90e987eeed7c44608b00a1b345c3bda72e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pryvacy-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1483181348df1eca2565b68a448f50370c0d6316ef7baa658f409e6b0b82a83f
MD5 aeda025d7a7d80d8772723f22deffaf3
BLAKE2b-256 f112036486b85d6c866147cc9545d06d9081d33196b49c768772cf1cb1ff289b

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