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 1.3.3

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 1.3.3
File Size Uploaded
simple-classproperty-1.3.3.tar.gz 16.2 kB Details

Built distribution (wheel)

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

Total release size: 32.4 kB

Release files / simple-classproperty-1.3.3.tar.gz

Download URL simple-classproperty-1.3.3.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4d5f0e35e5d52c116495a8a831d7865f4872c7925758de9bb6a03f2295b7e71a
BLAKE2b-256 checksum
How to use checksums
62af2e8516683f8f88cc2c6c1f75c3e4885ba622d1030ffbae2be43accc75958
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.6.14

Release files / simple_classproperty-1.3.3-py3-none-any.whl

Download URL simple_classproperty-1.3.3-py3-none-any.whl
Size 16.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
afd92830cc20b5975e0936c78b8a6c7a07a4e050f5de192a6e020d337a9f6fc8
BLAKE2b-256 checksum
How to use checksums
5e30292c3be1429711e389ed1b37a290041759f785b19426598df10a522c75b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.6.14

Release history Release notifications | RSS feed

4.0.2

2 release files

4.0.1

2 release files

4.0.0

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

This release

1.3.3 This release

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