Proper access modifiers for Python classes.
Project description
pyattr
While Python does have name mangling, it is not nearly as powerful as access modifiers found in languages such as C++. pyattr provides an easy-to-use API for access modifiers in Python, and is actively developed.
Installation
Installation via pip:
pip install pyattr
Usage
All you have to do is make your class inherit from the pyattr.Protected
class, and add super().__init__()
as the first line in the __init__
function of your class. And that's it! pyattr will handle the magic to make sure variables cannot be accessed / set where the shouldn't be. It also provides useful error messages to users.
Example
from pyattr import Protected
class Example(Protected):
def __init__(self) -> None:
super().__init__()
self.__name = "pyattr"
example = Example()
print(example.__name) # Error - '__name' is a protected attribute of 'Example'.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyattr-1.0.0.tar.gz
(3.2 kB
view hashes)
Built Distribution
pyattr-1.0.0-py3-none-any.whl
(3.4 kB
view hashes)