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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pryvacy-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 92211f3d17f735ba37e1a8b3ecf09e4b16d0cc61a9ba0ee353d5aff25ccff73c
MD5 fe1e3028f46a9a045b26625173eda39a
BLAKE2b-256 8fa386de0b3b66b68ee6253ba1aaa844dc2f3bc5807d4bdfe26d03a853c015d2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pryvacy-0.1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6bc16601f53516aeff98b376201f706e65825d8618e7fe71d8e87ae45e1e3946
MD5 4701971f5c875b7a26ce7fd543d55f31
BLAKE2b-256 8035d7298506e9b1889765cea8ed902ec3563de931f98ddf31e048c048c8a582

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