How to invoke Python scripts from Grafana?

Wanted to understand how to invoke scripts (e.g. Python) from Grafana? I want to use Grafana front end for user to enter some data and hit a submit button. This should in turn invoke a script at back end (something like a CGI script). The script will in turn fetch data from an external source (such as a sensor) and then update Grafana dash board. How can this be achieved?
Thanks in advance