The Mighty Dot - Customize Attribute Access with Descriptors

Track:
Python Core, Internals, Extensions
Type:
Tutorial
Level:
advanced
Duration:
180 minutes

Abstract

Whenever you use a dot in Python you access an attribute. While this seems a very simple operation, behind the scenes many things can happen. This tutorial looks into this mechanism that is regulated by descriptors. You will learn how a descriptor works and what kind of problems it can help to solve. Python properties are based on descriptors and solve one type of problems. Descriptors are more general, allow more use cases, and are more re-usable. Descriptors are an advanced topic. But once mastered, they provide a powerful tool to hide potentially complex behavior behind a simple dot.

In this tutorial you will:

  • Learn how to use Python's descriptors to add new functionality to attribute access
  • Acquired solid background knowledge on how descriptors work
  • Work with practical examples for applying descriptors
  • Learn when to use a property or reach for a descriptor
  • Get to know how popular Python libraries apply descriptors for tasks such as data structure access, REST-APIs, ORMs, and serialization