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"

But when the value of the property is changed from an instance object, only the instance has this value:

instance = NewClass()
instance.attr = "new"
print(instance.attr)  # "new"
print(NewClass.attr)  # "val"

When deleting the property from the instance, the class value is used again:

instance = NewClass()
instance.attr = "new"
print(instance.attr)  # "new"

del instance.attr
print(instance.attr)  # "val"

Metadata

Release files for simple-classproperty 1.0.1

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.0.1
File Size Uploaded
simple-classproperty-1.0.1.tar.gz 3.0 kB Details

Built distribution (wheel)

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

Total release size: 18.2 kB

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

Download URL simple-classproperty-1.0.1.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b885171033095b08d84d8b94398427dfaacc45ba7491a7ef9ed61a98e6a7a07d
BLAKE2b-256 checksum
How to use checksums
015cf9e1675c02adad4f346d4c7706eb0eb6a1af5f3b257e39da8889359ad668
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.5.9

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

Download URL simple_classproperty-1.0.1-py3-none-any.whl
Size 15.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
46dafc4d1b3971f5a255741ec448863c8cdc57b58ad1c91c90dd0fa223d8f1c6
BLAKE2b-256 checksum
How to use checksums
4eddbff485d7d63c43e2f8433acfa478df8614282fa07c46c7182868d8a885ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.5.9

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

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

This release

1.0.1 This release

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