🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

Python Advanced

What is Python Descriptors?

Objects that define __get__, __set__, or __delete__ methods, controlling how attribute access works on other objects.

Descriptors are the mechanism behind properties, class methods, static methods, and slots in Python. When an object defines __get__(), __set__(), or __delete__(), it becomes a descriptor. Data descriptors (with __set__ or __delete__) take precedence over instance dictionaries, while non-data descriptors (only __get__) defer to instance attributes. This protocol powers Django ORM fields, SQLAlchemy columns, and validation frameworks. Understanding descriptors reveals how Python's attribute access truly works — when you access obj.attr, Python calls type(obj).__dict__['attr'].__get__(obj, type(obj)) if attr is a descriptor.

Related Terms

Pathlib
A modern Python module providing an object-oriented interface for filesystem paths, replacing os.path operations.
Poetry
A modern Python dependency management and packaging tool that handles virtual environments, locking, and publishing.
ABC (Abstract Base Class)
A class that defines a common interface for subclasses by declaring abstract methods that must be implemented.
Pydantic
A data validation library that uses Python type annotations to validate and serialize data with automatic error reporting.
Type Hints
Optional annotations that indicate the expected types of variables, function parameters, and return values.
Python Metaclass
A class whose instances are classes themselves — the class of a class that controls how classes are created and behaved.
View All Python Terms →