๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout 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

Dictionary
A built-in data structure that stores key-value pairs with O(1) average lookup time using hash tables.
FastAPI
A modern, high-performance Python web framework for building APIs with automatic OpenAPI documentation and type validation.
Slots
A class mechanism that restricts attribute creation and reduces memory usage by using a fixed set of instance variables.
Pip Requirements File
A text file listing Python package dependencies with version specifications for reproducible project installations.
Python Property
A built-in decorator that lets you define methods that behave like attributes, enabling controlled access to instance data.
Walrus Operator
The := operator that assigns a value to a variable as part of an expression, introduced in Python 3.8.
View All Python Terms โ†’