How to Execute a Query from within a Python Step in Pipedream to a Remote MariaDB?

This topic was automatically generated from Slack. You can find the original thread here.

Hi there. I’m struggling a bit with this. From within a Python step, I would like to send data to a remote MariaDB. I tried using the mariadb module in Python, but I think that’s not the intended way on how to do it in Pipedream. I think the way to go is to add a MySQL connection/app to the step and use it to execute queries to the DB. And here I’m failing. How do I call that connection? I asked Pi but the answer is confusing me (most probably because of a lack of knowledge :see_no_evil:. Can someone maybe share an example of a simple implementation on how to execute a query from within a python step? I would highly appreciate it. Thanks in advance and best regards, Stefan

Hi , you can connect an app to your Python code step follow the document here: GitHub

Please let me know if it helps

Hi . Thanks for your feedback. Now knowing that I did the right thing, I come up with a follow-up question. I assume the correct module to use for MySQL/MariaDB within python would be import mysql.connector or import mariadb Unfortunately, this throws both of them are throwing an exception which seems to be a missing driver. Could there be an issue with the MySQL module?

The connection I’m trying is db_conn = mysql.connector.connect(pd.inputs['mysql']['$auth'])

Hi , thank you for your response. I can reproduce your issue on my side. I’ve created a ticket here for tracking: [FEATURE] Python - Support Mariadb package · Issue #14809 · PipedreamHQ/pipedream · GitHub

On another note, you can try the package pymysql PyMySQL · PyPI, I tested and it can import correctly

Hi . Thank you for the ticket and thank you for the tip to use pymsql. Going to give it a try. Thanks :pray::skin-tone-2: