python_script component does not allow any imports. This makes it very limited in data processing.
Such a basic use-case as JSON data processing (e.g. received from a webhook or MQTT) within a python string is not possible.
When I pass webhook JSON data using a template to the script - all I get is not a dictionary but a dictionary string instead. And this is fine as long as there is some way to process such string.
Unfortunately imports are forbidden in scripts. So is the
eval keywork. However there is a safer alternative for
ast.eval_literal. However it requires import - so again not possible to use it.
I propose to add a feature to allow execution of
This would solve things like this: How to pass trigger.value_json (Python dict) to python_script?
…and many others caused by another Ha limitation - templates rendered always as strings instead of native Python types.