Simple Python classproperty decorator
This module provides a simple way for defining class properties.
Install
You can install this Python module via pip:
pip install simple-classproperty
Otherwise the module can be downloaded from PyPI: https://pypi.org/project/simple-classproperty/
Usage
- Import the module:
from simple_classproperty import ClasspropertyMeta, classproperty
- Create a class with a class property:
class NewClass(metaclass=ClasspropertyMeta): _attr = "val" @classproperty def attr(cls): return cls._attr
Don't forget to set themetaclass! - (Optional) Define also a setter and deleter for the newly created class property (this works like the standard python
property):@attr.setter def attr(cls, value): cls._attr = value @attr.deleter def attr(cls): del cls._attr
Tips
The classproperty is also accessible from an instance:
instance = NewClass()
print(instance.attr) # "val"
When the value of the property is changed from an instance object, the class property will be changed. All other instances will have this new value:
instance1 = NewClass()
instance2 = NewClass()
instance1.attr = "new"
print(instance1.attr) # "new"
print(instance2.attr) # "new"
print(NewClass.attr) # "new"
This behavior is the same when a property gets deleted from an instance.
Metadata
Release files for simple-classproperty 1.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| simple-classproperty-1.4.1.tar.gz | 15.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| simple_classproperty-1.4.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.7 kB
Release files / simple-classproperty-1.4.1.tar.gz
| Download URL | simple-classproperty-1.4.1.tar.gz |
|---|---|
| Size | 15.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9f5bad2140aec61492ef430c957c3d848ebf548f5c03d6af2b7daa45726b739a
|
|
BLAKE2b-256 checksum How to use checksums |
ef663cea62dd10bf34acef800b7d8fa2c1730b95a12573d813357814fe16059a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12
|
Release files / simple_classproperty-1.4.1-py3-none-any.whl
| Download URL | simple_classproperty-1.4.1-py3-none-any.whl |
|---|---|
| Size | 16.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0235fe1e17bca89730cdfdd8e696ac974d5271a166f11dae0fbfdda2cda9df89
|
|
BLAKE2b-256 checksum How to use checksums |
3109335b352a1af5e00502776b69e1febaf9509abdf19e3d359baa7ea47cafc2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12
|