# Using importlib to run any function on the gateway?

**URL:** <https://forum.inductiveautomation.com/t/using-importlib-to-run-any-function-on-the-gateway/33915>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [April 14, 2020, 1:36pm UTC](https://forum.inductiveautomation.com/t/using-importlib-to-run-any-function-on-the-gateway/33915 "2020-04-14T13:36:46Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 14, 2020, 2:34pm UTC](https://forum.inductiveautomation.com/t/using-importlib-to-run-any-function-on-the-gateway/33915/3 "2020-04-14T14:34:34Z")

</div>

The overall idea is fine, though. Just preload all your possible code in the gateway. Pass function name, positional parameters, and keyword parameters through your sendRequest() call.

Say you have script module 'beefyFunctions` set up with all the named functions (which can call other script modules as needed). Create a message handler ‘beefy’ like so:

```auto
functionName, args, kwargs = [payload[x] for x in ['functionName', 'args', 'kwargs']]
return getattr(beefyFunctions, functionName)(*args, **kwargs)

```

Then in a client, you’d do this:

```auto
payload = {'functionName': 'somePreloadedFunction', 'args': someArgsTuple, 'kwargs': someArgsDictionary}
result = system.util.sendRequest('myProject', 'beefy', payload)

```

---

_[View the full topic](https://forum.inductiveautomation.com/t/using-importlib-to-run-any-function-on-the-gateway/33915)._
