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

I have an idea for a web app and plan to learn Python as I go (right now I know html/css, some javascript, some php and sql). The app would be able to manipulate and analyze audio files, among other things.

Ideally, I’d like to make the app available through my wordpress site so that I can take advantage of WordPress’s login management and the plugin s2member’s subscription management and content restriction capabilities.

Read More

Is that possible? Would it even make sense?

If not, is there a better alternative to automate all of that (the subscription management, logins, payment processing, content restriction, etc) without having to code it myself?

Related posts

2 comments

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

  2. 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 Python
    Author:..
    ....
    */
    
    $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.

Comments are closed.