static_class_property
static_class_property provides a tiny @classproperty decorator for
Python classes. It lets a method be read like a property on the class while the
getter still receives the class object, making it useful for values computed
from other class attributes.
Why it exists
Python's built-in @property is for instance attributes. Stacking @property
with @staticmethod or @classmethod does not create a class-level property,
so this package supplies the descriptor needed for that pattern.
Installation
pip install static_class_property
The package declares support for Python 3.8 and newer and has no runtime dependencies.
Usage
from static_class_property import classproperty
class Settings:
env = "prod"
@classproperty
def label(cls):
return f"settings:{cls.env}"
assert Settings.label == "settings:prod"
Settings.env = "dev"
assert Settings.label == "settings:dev"
Use the getter argument like cls in a @classmethod: it is bound to the owner
class each time the attribute is read.
How it works
classproperty subclasses property and implements __get__. On access, it
wraps the original getter with classmethod, binds it to the owner class, and
calls it immediately.
Behavior and limitations
- The value is recomputed on every access; there is no caching.
- The decorator is intended for read-only computed class values.
- Assigning to the attribute on the class replaces the descriptor, as with any normal class attribute.
Development
pip install -r requirements_dev.txt
pip install -e .
make test
make lint
Docs can be built with make docs.
License
MIT License.
Changelog
0.0.1
- First release on PyPI.
Release files for static-class-property 0.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 | |
|---|---|---|---|
| static_class_property-0.0.2.tar.gz | 8.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| static_class_property-0.0.2-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size:12.5 kB
Release files / static_class_property-0.0.2.tar.gz
| Download URL | static_class_property-0.0.2.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
114f38b9dfe12db1371c3f93c9160df0bc8d47ae05d56b4adb645db5dd34eca9
|
|
BLAKE2b-256 checksum How to use checksums |
257179e5ca21a501ea6dd9f75d1d607c0717f9790f6269c30b079392b5f47a6b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / static_class_property-0.0.2-py2.py3-none-any.whl
| Download URL | static_class_property-0.0.2-py2.py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
0dcd63fe316713a4e072e0463366b90d16ffe27d24fc72e2c95ffdcd86b12a29
|
|
BLAKE2b-256 checksum How to use checksums |
44fcaf79f0de0f13ff579958fdfb7112bd001e5dc21c9b30338ebca4db7301d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|