Metadata-Version: 2.4
Name: static_class_property
Version: 0.0.2
Summary: Static Class Property
Home-page: https://github.com/maximz/static-class-property
Author: Maxim Zaslavsky
Author-email: maxim@maximz.com
License: MIT license
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: requires-python
Dynamic: summary

# static_class_property

[![](https://img.shields.io/pypi/v/static_class_property.svg)](https://pypi.python.org/pypi/static_class_property)
[![CI](https://github.com/maximz/static-class-property/actions/workflows/ci.yaml/badge.svg?branch=master)](https://github.com/maximz/static-class-property/actions/workflows/ci.yaml)
[![](https://img.shields.io/badge/docs-here-blue.svg)](https://static-class-property.maximz.com)
[![](https://img.shields.io/github/stars/maximz/static-class-property?style=social)](https://github.com/maximz/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

```bash
pip install static_class_property
```

The package declares support for Python 3.8 and newer and has no runtime
dependencies.

## Usage

```python
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

```bash
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.
