Is it possible to run a Python app on a WordPress site? Is it possible to run a Python app on a WordPress site? wordpress wordpress

Is it possible to run a Python app on a WordPress site?


I suggest you develop a REST API in Python and extend your Wordpress site to consume that API.

For the Python side, you could go with Flask and use Flask-RESTful.

For the Wordpress side, have a look at this question.


Sure, if you meet a couple of conditions:

  • The server your wordpress site is on also has python
  • And you have the ability run arbitrary python scripts on said server.

Here's a (very contrived) example of how to do it from a plugin:

call-python.php (plugin file):

<php/*Plugin name: Call PythonAuthor:......*/$pyScript = "/path/to/app.py";exec("/usr/bin/python $pyScript", $output);var_dump($output);

And the python script app.py:

print("Hello, World")

And that's it! That will dump Hello, world to the body. Obviously you'll need a bit more for a more complicated python app, but it will work.

Like others are saying, there may be better "more correct" ways of doing it. But if your end goal is to run a python app from WordPress it's possible.