Skip to main content

Simple Python classproperty decorator

PyPI package PyPI version

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

  1. Import the module:
    from simple_classproperty import ClasspropertyMeta, classproperty
    
  2. 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 the metaclass!
  3. (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.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simple-classproperty 4.0.0
File Size Uploaded
simple_classproperty-4.0.0.tar.gz 14.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for simple-classproperty 4.0.0
File Interpreter ABI Platform
simple_classproperty-4.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.9 kB

Release files / simple_classproperty-4.0.0.tar.gz

Download URL simple_classproperty-4.0.0.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
22e83e3677b5b35b31c7a99ae86635aa6e7673b26068ddb8689797df2cf69aeb
BLAKE2b-256 checksum
How to use checksums
58803deaeb89e4f9698a208afa1c3560d60bcda1fe9bb33cfe21c390ff19ad8c
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.0-py3-none-any.whl

Download URL simple_classproperty-4.0.0-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3cfc794f0703f2b3e7e64a073bf70824845de26d2840f26e40382a62c3844bfd
BLAKE2b-256 checksum
How to use checksums
5095e6dcbb0201435456889f75421c7a77b37ec7915b8645f2f0a4b325cfb3c1
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 history Release notifications | RSS feed

4.0.2

2 release files

4.0.1

2 release files

This release

4.0.0 This release

2 release files

3.0.0

2 release files

2.0.0

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3

2 release files

1.2

2 release files

1.1

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page