Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

simple-classproperty

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-classproperty

Provides a 'classproperty' decorator.

  • 4.0.2
  • PyPI
  • Socket score

Maintainers
1

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.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc