Calling Python scripts w/ arguments on the backend via plugin?

AI-generated summary

In a discussion titled ‘Calling Python scripts w/ arguments on the backend via plugin?’, leighno5 — a non-front-end developer — seeks guidance on exposing a working Python script (which accepts user arguments) to Discourse moderators via a plugin. The script runs fine from the terminal, but they need a way for mods to input arguments via text fields and trigger execution via a button. They ask if the beginner’s plugin guide is the right starting point. merefield suggests using Ruby’s Open3 library to invoke external commands (like Python scripts) from within a plugin, referencing their own [Discourse Frotz plugin](https://github.com/merefie ld/discourse-frotz/blob/6054d38af0ab8e516a93416026f8e646f5c5ea56/lib/frotzbot.rb#L167) as an example. They also note that, since the user is already diving into backend plugin development, they might consider rewriting the logic in native Ruby — which they describe as a pleasant language. leighno5 thanks merefield for the helpful advice.

Let’s get this out of the way: I’m NOT a front-end guy at all. That said, I’ve written a Python script that runs on the same instance as my Discourse install, and upon execution certain methods take in arguments from the user. It works exactly as intended when run from the terminal. I need to figure out how to expose this to mods via plugin, where they can add the expected input in text fields and hit some kind of ‘execute’ button which in turn runs the script with the provided arguments. I have no idea where to begin. If someone could point me in the right direction, that’d be grand. Is it as simple as starting with the guide on writing plugins? I did go through this and I don’t remember that anything immediately jumped out as to being what I was looking for, but if I just need to go over it again and that’s the best place to start, please let me know! Thanks!

You can use Running external commands with Open3 - makandra dev
to call the command line in Ruby and plugins.

I use it here in my Discourse Frotz (Interactive Fiction) plugin: discourse-frotz/lib/frotzbot.rb at 6054d38af0ab8e516a93416026f8e646f5c5ea56 · merefield/discourse-frotz · GitHub to interact with the terminal.

But if you are going that far you might consider writing native Ruby all the way. It’s a very pleasant language.

Thanks so much, really appreciate your assistance!