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.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| simple_classproperty-4.0.2.tar.gz | 14.9 kB | Without provenance | Details for simple_classproperty-4.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| simple_classproperty-4.0.2-py3-none-any.whl | Python 3 | none | any | Details for simple_classproperty-4.0.2-py3-none-any.whl |
Total release size: 31.1 kB
Release files / simple_classproperty-4.0.2.tar.gz
| Download URL | simple_classproperty-4.0.2.tar.gz |
|---|---|
| Size | 14.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
71ba436fc868f540c1908ecb0ef78ce14ea6fb1320cf4addd84945fb92988d5f
|
|
BLAKE2b-256 checksum How to use checksums |
6372f18598765a3a14fff37eb9daaf21f9907e5685afef57187bc9bda5cdcb20
|
| 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-1015-azure
|
Release files / simple_classproperty-4.0.2-py3-none-any.whl
| Download URL | simple_classproperty-4.0.2-py3-none-any.whl |
|---|---|
| Size | 16.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ac13ae65df997257e72888fd3c875c97d711ae2b625ead93be28b7d79c8d0b7a
|
|
BLAKE2b-256 checksum How to use checksums |
0e9161e9f76d7afc991bee5c6bbb175e6c22c03ac4bf6aad5c0eaa82b6088757
|
| 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-1015-azure
|
Security for simple-classproperty 4.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.