module documentation

Extensible class instrumentation.

The sqlalchemy.ext.instrumentation package provides for alternate systems of class instrumentation within the ORM. Class instrumentation refers to how the ORM places attributes on the class which maintain data and track changes to that data, as well as event hooks installed on the class.

Note

The extension package is provided for the benefit of integration with other object management packages, which already perform their own instrumentation. It is not intended for general use.

For examples of how the instrumentation extension is used, see the example :ref:`examples_instrumentation`.

Class ​Extended​Instrumentation​Registry Extends .InstrumentationFactory with additional bookkeeping, to accommodate multiple types of class managers.
Class ​Instrumentation​Manager User-defined class instrumentation extension.
Constant INSTRUMENTATION​_MANAGER Attribute, elects custom instrumentation when present on a mapped class.
Variable instrumentation​_finders An extensible sequence of callables which return instrumentation implementations
Class _​Class​Instrumentation​Adapter Adapts a user-defined InstrumentationManager to a ClassManager.
Function ​_install​_instrumented​_lookups No summary
Function ​_install​_lookups Undocumented
Function ​_reinstall​_default​_lookups Restore simplified lookups.
Function find​_native​_user​_instrumentation​_hook Find user-specified instrumentation management for a class.
Variable ​_instrumentation​_factory Undocumented
INSTRUMENTATION_MANAGER: str =

Attribute, elects custom instrumentation when present on a mapped class.

Allows a class to specify a slightly or wildly different technique for tracking changes made to mapped attributes and collections.

Only one instrumentation implementation is allowed in a given object inheritance hierarchy.

The value of this attribute must be a callable and will be passed a class object. The callable must return one of:

  • An instance of an .InstrumentationManager or subclass
  • An object implementing all or some of InstrumentationManager (TODO)
  • A dictionary of callables, implementing all or some of the above (TODO)
  • An instance of a .ClassManager or subclass

This attribute is consulted by SQLAlchemy instrumentation resolution, once the sqlalchemy.ext.instrumentation module has been imported. If custom finders are installed in the global instrumentation_finders list, they may or may not choose to honor this attribute.

Value
'__sa_instrumentation_manager__'
instrumentation_finders =

An extensible sequence of callables which return instrumentation implementations

When a class is registered, each callable will be passed a class object. If None is returned, the next finder in the sequence is consulted. Otherwise the return must be an instrumentation factory that follows the same guidelines as sqlalchemy.ext.instrumentation.INSTRUMENTATION_MANAGER.

By default, the only finder is find_native_user_instrumentation_hook, which searches for INSTRUMENTATION_MANAGER. If all finders return None, standard ClassManager instrumentation is used.

def _install_instrumented_lookups():

Replace global class/object management functions with ExtendedInstrumentationRegistry implementations, which allow multiple types of class managers to be present, at the cost of performance.

This function is called only by ExtendedInstrumentationRegistry and unit tests specific to this behavior.

The _reinstall_default_lookups() function can be called after this one to re-establish the default functions.

def _install_lookups(lookups):

Undocumented

def _reinstall_default_lookups():
Restore simplified lookups.
def find_native_user_instrumentation_hook(cls):
Find user-specified instrumentation management for a class.
_instrumentation_factory =

Undocumented