Giter VIP home page Giter VIP logo

pryvacy's Introduction

pryvacy - a set of access control decorators for python

PyPI Version

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

  @private
  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~

  1. 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!
  1. The test_back_and_forth test is failing. This scenario is unlikely to happen but I will try to come up with a performant solution.

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

pryvacy's People

Contributors

huy-dna avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.