# Passing python functions and storing via message handlers in Perspective

**URL:** <https://forum.inductiveautomation.com/t/passing-python-functions-and-storing-via-message-handlers-in-perspective/46610>\
**Category:** Ignition\
**Tags:** perspective, ignition81\
**Created:** [May 12, 2021, 6:29am UTC](https://forum.inductiveautomation.com/t/passing-python-functions-and-storing-via-message-handlers-in-perspective/46610 "2021-05-12T06:29:47Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [May 12, 2021, 12:33pm UTC](https://forum.inductiveautomation.com/t/passing-python-functions-and-storing-via-message-handlers-in-perspective/46610/4 "2021-05-12T12:33:08Z")

</div>

Generally speaking functions are `first class` in python and yes you can pass them. It’s what allows you to make decorators in general. You can do stuff like

```auto
def timer_function(func, args, kwargs):
    start_time = time.time()
    result = func(*args, **kwargs)
    end_time = time.time()
    print end_time - start_time

```

and then call this on any generic function to time it.

You can store functions in a list and then evaluate them in a certain order and store a list of results

```auto
my_funcs = [someModule.foo, module.bar, foo.bar]
results = [func() for func in my_funcs]

```

You can assign them to a variable (though use case wise I don’t have anything for this)

```auto
x = someModule.foo
x()

```

You most likely don’t want to just be able to send back any function via message handler to be run on the gateway as if someone is able to spoof a client and knows just a little ignition or say some of your functions that relate to deleting/updating your database, then you could be in a world of hurt.

Heres a [post](http://forum.inductiveautomation.com/t/using-importlib-to-run-any-function-on-the-gateway/33915) I made about it a while back, but my method was passing a string of the function name and then importing it with importlib. However to make sure I was safe I would need to white list what functions would be acceptable for a client to call and I was able to do that with string comparisons. If you’re passing a function object back directly I am not sure how you would have a whitelist.

---

_[View the full topic](https://forum.inductiveautomation.com/t/passing-python-functions-and-storing-via-message-handlers-in-perspective/46610)._
