As part of the on-going project to build a library of rigging tools i wanted a better way to reload all imported custom modules

In python 3 we now use importlibs reload() function for reloading

import importlib

using sys.modules we can get a dictionary of all current imported modules with the key being the module name and value being the path to the module.

# {..., 'DRTools.utils.attrUtils' from 'C:\\Users/danri/Documents/maya/2023/scripts\\DRTools\\utils\\'>, ...}

Utilizing this we can only reload modules in a specific directory where our custom tools are located and reuse the function throughout our codebase. A neat trick to reload everything is to simply delete the key from the sys.modules dictionary, that way we we will be re-importing all the modules in our codebase at once. Avoiding a bunch of importlib.reload(MODULE)’s and chaining them together in our codebase.

def reload_DRig():
    modules_to_del = []
    for module in sys.modules.copy():
        # print(module)
        top_module = module.split('.')[0]
        if top_module == 'DRig':

    for module in modules_to_del:

Example use case from the joint orient tool

from DRig.utils import pyUtils

This is now alot cleaner and easier to use rather then repetitive lines of importlib.reload() It may be better to only reload modules that have been changed - but i do not deem that necessary for my use case.