Descriptors: secret weapon of frameworks
2024-11-27 , Dorneles Treméa Auditorium
Language: English

The descriptor protocol is an obscure feature widely used by frameworks to link Python classes to database tables, JSON payloads, and dynamic forms. Understand this secret weapon and wield it wisely!


Most Python frameworks that use Python class syntax to specify structures with typed fields implement descriptor classes, which provide 'get', 'set' and 'delete' method to enforce rules and perform conversions when the fields are read, updated, or deleted. Standard Python classes themselves depend of the descriptor protocol: that's what makes a function acessed via a class or object behave as a method.

Luciano Ramalho wrote Fluent Python / Python Fluente, an international bestseller published in 9 languages.

This speaker also appears in: