# Script python in backend

**URL:** <https://community.grafana.com/t/script-python-in-backend/145248>\
**Category:** Grafana Plugin Development\
**Created:** [February 28, 2025, 12:13pm UTC](https://community.grafana.com/t/script-python-in-backend/145248 "2025-02-28T12:13:00Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerryjouaud](https://avatars.discourse-cdn.com/v4/letter/g/838e76/32.png) [@gerryjouaud](https://community.grafana.com/u/gerryjouaud)\
**Post date:** [February 28, 2025, 12:13pm UTC](https://community.grafana.com/t/script-python-in-backend/145248/1 "2025-02-28T12:13:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mikhailvolkov](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/mikhailvolkov/32/41625_2.png) [@mikhailvolkov](https://community.grafana.com/u/mikhailvolkov)\
**Post date:** [February 28, 2025, 6:26pm UTC](https://community.grafana.com/t/script-python-in-backend/145248/2 "2025-02-28T18:26:48Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![gerryjouaud](https://avatars.discourse-cdn.com/v4/letter/g/838e76/32.png) [@gerryjouaud](https://community.grafana.com/u/gerryjouaud)\
**Post date:** [March 4, 2025, 7:35am UTC](https://community.grafana.com/t/script-python-in-backend/145248/3 "2025-03-04T07:35:58Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![mikhailvolkov](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/mikhailvolkov/32/41625_2.png) [@mikhailvolkov](https://community.grafana.com/u/mikhailvolkov)\
**Post date:** [March 4, 2025, 11:55am UTC](https://community.grafana.com/t/script-python-in-backend/145248/4 "2025-03-04T11:55:56Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![gerryjouaud](https://avatars.discourse-cdn.com/v4/letter/g/838e76/32.png) [@gerryjouaud](https://community.grafana.com/u/gerryjouaud)\
**Post date:** [March 7, 2025, 12:51pm UTC](https://community.grafana.com/t/script-python-in-backend/145248/5 "2025-03-07T12:51:23Z")

</div>

Thanks for your help 🙂

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [March 7, 2025, 1:05pm UTC](https://community.grafana.com/t/script-python-in-backend/145248/6 "2025-03-07T13:05:15Z")

</div>

What does the python script do that the datasource cannot?

---

<div class="post-metadata">

**Author:** ![gerryjouaud](https://avatars.discourse-cdn.com/v4/letter/g/838e76/32.png) [@gerryjouaud](https://community.grafana.com/u/gerryjouaud)\
**Post date:** [March 7, 2025, 1:22pm UTC](https://community.grafana.com/t/script-python-in-backend/145248/7 "2025-03-07T13:22:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [March 7, 2025, 2:04pm UTC](https://community.grafana.com/t/script-python-in-backend/145248/8 "2025-03-07T14:04:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gerryjouaud](https://avatars.discourse-cdn.com/v4/letter/g/838e76/32.png) [@gerryjouaud](https://community.grafana.com/u/gerryjouaud)\
**Post date:** [March 7, 2025, 2:12pm UTC](https://community.grafana.com/t/script-python-in-backend/145248/9 "2025-03-07T14:12:07Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/grafana/original/2X/e/ef5308cc58c9e5a13187b5012eb99f406928462f.png) [@system](https://community.grafana.com/u/system)\
**Post date:** [March 7, 2026, 2:13pm UTC](https://community.grafana.com/t/script-python-in-backend/145248/10 "2026-03-07T14:13:00Z")

</div>

Closed on March 7, 2026, 2:13pm UTC

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
