In SQLAlchemy’s tutorial, it mentions “instrumentation” but doesn’t appear to properly define what instrumentation is:
These class attributes exist as Python descriptors, and define
instrumentation for the mapped class. The functionality of this instrumentation includes the ability to fire on change events, track modifications, and to automatically
load new data from the database when needed.
What is instrumentation in this context?
instrumentation is the process of attaching attributes to a class, which are implemented as Python Descriptors (this link is mentioned in that sentence) such that any attribute get, set, or delete operation, that is:
… will invoke Python code for each event, rather than using Python’s default behavior of accessing/manipulating
myobject.__dict__directly. SQLAlchemy takes advantage of these hooks to provide behaviors such as lazy loading, as well as to record when the value of an attribute changes, for the purpose of implementing the unit of work pattern, where only those elements that have changed are rolled into UPDATE statements to be emitted to the database upon flush.