This post/topic might provide some answers:
The example above demonstrates how to import functions/classes from an external Python file into a GhPython component. However I also import and run functions from that same file by assigning them to Rhino keyboard shortcuts. Here’s a recent example:
The trick here is to be a bit unpythonic and use semicolons to add multiple lines of code into a one line string. That is, the macro on the F7 keyboard shortcut in the screenshot is:
-RunPythonScript (import ahd; ahd.flipBackgroundColor())
There’s a 200 character limit, so one could actually add quite a bit of Python directly within the macro too!
It probably requires additional macro formatting, but I think one might add them here.
If not, and probably advisable in general on the Rhino side, one can make actual commands. And again, things probably look a bit different with the scripting options provided in Rhino 8.