Python 2.7 with Webpy - flup or modwsgi?

ghz 15hours ago ⋅ 5 views

I am unsure which of the two I should go for. Flup or modwsgi.

Flup seems to have very little documentation and even less people adding to the code. modwsgi on the other hand seems to be widely supported.

I just want to start running my webpy environmental so that I can utilize Python scripts online. But this thing stops me from moving ahead. Any suggestions?

Answer

Given your situation where you're trying to run a web application using Web.py and are evaluating between Flup and mod_wsgi, I can help you decide by pointing out some key differences and suggestions based on your goals.

1. Flup:

  • Flup is a lightweight Python WSGI server that is simple to set up and suitable for development environments. It can also be used in production, but it doesn't have as much traction as other WSGI servers.
  • Pros:
    • Easier to set up for small projects or development environments.
    • Lightweight and easy to configure.
    • Can work with multiple WSGI servers and is sometimes used in cases where you want something simpler than more heavyweight solutions like mod_wsgi.
  • Cons:
    • Very limited documentation.
    • Fewer active users and contributors.
    • Lacks the long-term support and features that are available in more widely adopted servers like mod_wsgi.
    • Hasn’t been updated in a long time (as you mentioned).

2. mod_wsgi:

  • mod_wsgi is a robust and widely supported WSGI server that runs as a module within Apache, which is one of the most commonly used web servers.
  • Pros:
    • Strong community support and widely used in production environments.
    • Actively maintained and updated.
    • Better scalability and performance for production environments.
    • Full-fledged integration with Apache and other tools.
    • More comprehensive documentation and tutorials available.
    • If you are already using Apache or plan to scale your application, mod_wsgi is a great choice.
  • Cons:
    • Slightly more complex to set up, especially if you're not familiar with Apache configuration.
    • Typically requires more configuration than Flup, but that’s only a barrier for initial setup.

Recommendation:

If your goal is to get something up and running quickly with minimal hassle, Flup may seem appealing. However, if you're planning to run this application in a production environment, especially if you’re considering scaling or need better support, I strongly recommend going with mod_wsgi.

Here’s why mod_wsgi is likely the better option:

  • Widely used: If you're using Web.py (which is a small framework), mod_wsgi is definitely the most widely used server to run Python web apps on Apache. It has a large user base and plenty of resources.
  • Better long-term support: You’ll find a lot more tutorials, articles, and examples of how to set up mod_wsgi with Web.py.
  • Stability & Performance: For production-ready deployments, mod_wsgi provides better performance, especially for handling concurrent requests.

Steps to Get Started with mod_wsgi and Web.py:

  1. Install mod_wsgi: You can install mod_wsgi via apt (on Ubuntu/Debian systems) or brew (on macOS), or by using pip if you're setting up in a virtual environment. Here’s how you might install it:

    sudo apt-get install libapache2-mod-wsgi
    sudo systemctl restart apache2
    
  2. Configure Apache: After installing mod_wsgi, you need to configure Apache to serve your Python web application using the mod_wsgi module. Here’s a basic configuration:

    • Edit /etc/apache2/sites-available/000-default.conf (or your specific site configuration file):
      <VirtualHost *:80>
          ServerName yourdomain.com
      
          DocumentRoot /path/to/your/webapp
          WSGIScriptAlias / /path/to/your/webapp/app.wsgi
      
          <Directory /path/to/your/webapp>
              Require all granted
          </Directory>
      </VirtualHost>
      
    • Create a app.wsgi file in your project folder (same directory as your Web.py app):
      import sys
      sys.path.insert(0, '/path/to/your/webapp')
      
      from web import application
      from your_script import your_app
      
      app = application(your_app.urls, globals())
      application = app.wsgifunc()
      
      Replace /path/to/your/webapp with the actual path to your application and your_app with your actual Web.py app module.
  3. Restart Apache: After configuration, restart Apache to apply the changes:

    sudo systemctl restart apache2
    
  4. Verify: Visit your domain or localhost in the browser to verify everything is working.

In Conclusion:

  • If you are just experimenting or running a very small application (e.g., for a local project or prototype), Flup might work.
  • However, for long-term scalability, better support, and easier troubleshooting, I recommend using mod_wsgi, especially for production environments.

Let me know if you need help with any specific configuration or setup steps!