Script python in backend

Hi everyone.

I have a functional datasource backend that is querying a sql database.
Before returning the response whith the dataframe, i want to run a python script with some results of the query in args.

I’m having issues to find a way to run a local python script. So i wonder, is it even possible ?

Thank you.

@gerryjouaud I would recommend to create a Python web-server which will serve requests to the data source. It will fit in the Grafana architecture perfectly compare to running Python script on demand.

2 Likes

Thanks a lot for answering !
We will think about your solution :slight_smile:

For my knowledge, can you explain me if it’s possible to paste a python file in the grafana environment /home maybe ? I can’t find this env in linux.

Thanks a lot

@gerryjouaud Technically you can put it in the /home, but I don’t the reason to do it.

Grafana utilizes Go backend and can execute Go executable as a part of the backend data source. As I mentioned, utilizing external services is the best option to run Python scripts.

1 Like

Thanks for your help :slight_smile:

What does the python script do that the datasource cannot?

We have a massive quantity of functions in Python, so we won’t translate them in Golang !

so my question is not about golang. what things are you doing in python, data processing that your datasource cannot do?

you should maybe look into creating a python flask rest api server that queries the database then does the post processing

We were thinking about the interest to make our own backend datasource plugin to process calculations on the fly. But as you said; we choosed the API solution :slight_smile:

1 Like