Release: 1.0.0 | Release Date: Not released

SQLAlchemy 1.0 Documentation

Alternate Class Instrumentation

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 Attribute Instrumentation.

Changed in version 0.8: The sqlalchemy.orm.instrumentation was split out so that all functionality having to do with non-standard instrumentation was moved out to sqlalchemy.ext.instrumentation. When imported, the module installs itself within sqlalchemy.orm.instrumentation so that it takes effect, including recognition of __sa_instrumentation_manager__ on mapped classes, as well instrumentation_finders being used to determine class instrumentation resolution.

API Reference

sqlalchemy.ext.instrumentation.INSTRUMENTATION_MANAGER = '__sa_instrumentation_manager__'

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.

class sqlalchemy.orm.instrumentation.InstrumentationFactory

Factory for new ClassManager instances.

class sqlalchemy.ext.instrumentation.InstrumentationManager(class_)

User-defined class instrumentation extension.

InstrumentationManager can be subclassed in order to change how class instrumentation proceeds. This class exists for the purposes of integration with other object management frameworks which would like to entirely modify the instrumentation methodology of the ORM, and is not intended for regular usage. For interception of class instrumentation events, see InstrumentationEvents.

The API for this class should be considered as semi-stable, and may change slightly with new releases.

dict_getter(class_)
dispose(class_, manager)
get_instance_dict(class_, instance)
initialize_instance_dict(class_, instance)
install_descriptor(class_, key, inst)
install_member(class_, key, implementation)
install_state(class_, instance, state)
instrument_attribute(class_, key, inst)
instrument_collection_class(class_, key, collection_class)
manage(class_, manager)
manager_getter(class_)
post_configure_attribute(class_, key, inst)
remove_state(class_, instance)
state_getter(class_)
uninstall_descriptor(class_, key)
uninstall_member(class_, key)
sqlalchemy.ext.instrumentation.instrumentation_finders = [<function find_native_user_instrumentation_hook at 0x7f087a7aba28>]

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.

class sqlalchemy.ext.instrumentation.ExtendedInstrumentationRegistry

Bases: sqlalchemy.orm.instrumentation.InstrumentationFactory

Extends InstrumentationFactory with additional bookkeeping, to accommodate multiple types of class managers.