You can find the caller's globals by inspecting the call stack. However, pay attention to the remark in the docs of sys._getframe
:
CPython implementation detail: This function should be used for internal and specialized purposes only. It is not guaranteed to exist in all implementations of Python.
Anyway, the code you need to get the globals of the immediate caller is
sys._getframe(1).f_globals