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 4.0.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-4.0.1.tar.gz | 14.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| simple_classproperty-4.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.9 kB
Release files / simple_classproperty-4.0.1.tar.gz
| Download URL | simple_classproperty-4.0.1.tar.gz |
|---|---|
| Size | 14.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d51ea519c21e46e0bb9b566ae57f1045e4bed077db675cfd1c9bc884607526fe
|
|
BLAKE2b-256 checksum How to use checksums |
d64676cec43a43362fc823e1783e3bf86f51d1c84098c858b2ef6d65a7268b9b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.7.17 Linux/6.2.0-1012-azure
|
Release files / simple_classproperty-4.0.1-py3-none-any.whl
| Download URL | simple_classproperty-4.0.1-py3-none-any.whl |
|---|---|
| Size | 16.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
425640b2e2624391bb4a9c55f0e04276edf252cf5505302dc54545c6aa945edb
|
|
BLAKE2b-256 checksum How to use checksums |
e920da139b0c751f23dc058373bbcd00f7460eec60472c796f8b5baa8f9070b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.7.17 Linux/6.2.0-1012-azure
|