Toolkit frameworks can be useful for writing code that can be then reused in a number of different Apps or Engines.
Normally if you are writing a custom App or Engine, you would import the framework using sgtk.platform.import_framework()
, and this requires that the App sets the framework as a dependency in the app’s info.yml
.
Frameworks in App hooks
However, if you want to use a framework, in an App hook you can do so using the Hook
class’s load_framework()
.
This method allows you to import a framework that hasn’t been explicitly set as a dependency for the App. Note the framework must still be included in your configuration environment settings.
Frameworks in core hooks
It is not possible to import a framework into a core hook. In order to load a framework within a hook, an app or engine must be running. This is because the manifest for that app or engine is used to find the framework dependencies and determine which version of the framework to load. Since in a core hook there is no app or engine running that can be used to determine version dependencies, this is not possible.
This is also noted in the documentation for the load_framework
method.