# How can I load a Toolkit framework in my hook?

**URL:** <https://community.shotgridsoftware.com/t/how-can-i-load-a-toolkit-framework-in-my-hook/115>\
**Category:** Pipeline Integrations\
**Tags:** coding, hooks\
**Created:** [July 17, 2019, 3:00pm UTC](https://community.shotgridsoftware.com/t/how-can-i-load-a-toolkit-framework-in-my-hook/115 "2019-07-17T15:00:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![philip.scadding](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/philip.scadding/32/30_2.png) [@philip.scadding](https://community.shotgridsoftware.com/u/philip.scadding)\
**Post date:** [July 17, 2019, 3:00pm UTC](https://community.shotgridsoftware.com/t/how-can-i-load-a-toolkit-framework-in-my-hook/115/1 "2019-07-17T15:00:59Z")

</div>

[Toolkit frameworks](https://developer.shotgunsoftware.com/tk-core/platform.html#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`](https://github.com/shotgunsoftware/tk-multi-workfiles2/blob/3566876b4ec5c9afc7a8ae453f088fbd427a9794/info.yml#L253-L256).

**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()`](https://developer.shotgunsoftware.com/tk-core/core.html?highlight=load_framework#sgtk.Hook.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](https://developer.shotgunsoftware.com/tk-core/core.html#sgtk.Hook.load_framework) for the `load_framework` method.

---

<div class="post-metadata">

**Author:** ![Rhea\_Fischer](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/rhea_fischer/32/2630_2.png) [@Rhea\_Fischer](https://community.shotgridsoftware.com/u/Rhea_Fischer)\
**Post date:** [August 3, 2023, 9:56pm UTC](https://community.shotgridsoftware.com/t/how-can-i-load-a-toolkit-framework-in-my-hook/115/2 "2023-08-03T21:56:26Z")

</div>

Contrary to the [documentation here](https://developer.shotgunsoftware.com/tk-core/core.html#sgtk.Hook.load_framework), a hook called from an engine **cannot** call `self.load_framework`.

The load\_framework method checks for `self.__parent.engine`, which assumes the parent is an app.

Hooks run from an engine must use `self.parent.frameworks["<framework_name>"]`

[Hook.load\_framework version source](https://github.com/shotgunsoftware/tk-core/blob/0990437c5fbc07cb5d8ba90ef4d91646703576f0/python/tank/hook.py#L449)

---

<div class="post-metadata">

**Author:** ![Jaziel](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/jaziel/32/3640_2.png) [@Jaziel](https://community.shotgridsoftware.com/u/Jaziel)\
**Post date:** [August 16, 2023, 8:00pm UTC](https://community.shotgridsoftware.com/t/how-can-i-load-a-toolkit-framework-in-my-hook/115/3 "2023-08-16T20:00:04Z")

</div>

But the documentation is not wrong, specifies the load\_framework only works on Hooks executed from apps and frameworks:

> This method only works for hooks that are executed from apps and frameworks.

or am I missing something? 🤔

---

<div class="post-metadata">

**Author:** ![Rhea\_Fischer](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/rhea_fischer/32/2630_2.png) [@Rhea\_Fischer](https://community.shotgridsoftware.com/u/Rhea_Fischer)\
**Post date:** [August 22, 2023, 10:55pm UTC](https://community.shotgridsoftware.com/t/how-can-i-load-a-toolkit-framework-in-my-hook/115/4 "2023-08-22T22:55:00Z")

</div>

I stand corrected. Could swear the doc was corrected too 😀
