# Descriptor

say it: **“dih-SKRIP-ter”** **/dɪˈskrɪptər/**

An object that controls reading and setting an attribute; the machinery behind @property.

## What is a **descriptor**?

A **descriptor** is an object that controls what happens when an attribute is read or set. It's the machinery behind `@property`, and you can write your own for rules you reuse.

```python
class Positive:
    def __set_name__(self, owner, name):
        self.name = "_" + name

    def __get__(self, obj, owner):
        return getattr(obj, self.name)

    def __set__(self, obj, value):
        if value <= 0:
            raise ValueError("must be positive")
        setattr(obj, self.name, value)

class Product:
    price = Positive()
```

Level: Master · [More Python terms at this level](https://www.ask-codey.com/glossary?category=python&level=5)

Updated: November 17, 2026

Source: https://www.ask-codey.com/glossary/descriptor
