Learning about Python application deployment - possible recommendations

  • #1
fog37
1,568
108
Hello,
I want to learn about servers and deploying Python applications simply (without going to AWS, Azure, etc. but something a little more complicated than deploying my app to streamlit Cloud). I would like to get some recommendations given the multitude of options.

My goal is to create a personal website/blog that can be accessed by remote users who can run a simple Python regression model and get the prediction results in their browser. I believe these are the steps:
  1. Develop a Flask app: create a Flask app that contains my simple scikit-learn regression model.
  2. Buy a Domain name from Domain Registrar: First I need to buy a domain name from an online domain registrar. What do you think about Google Domains?
  3. Web Server: I need to purchase a service that supports Python and WSGI. Some online options are Digitalocean, Heroku, PythonAnywhere... Which one would you recommend? For now, let's consider Digitalocean. I believe I will need to upload the web pages (i.e. the website) and the Flask app on Digitalocean...Digitalocean offers Droplets, which are virtual private servers (essentially virtual machines VM). The next steps involve choosing the web server itself. For example Nginx, which will be used as a reverse proxy to forward requests from web clients (browsers) to the WSGI server (ex: Gunicorn) to the Flask app (which plays the role of the application server) and deliver responses back to the clients. Nginx needs to be downloaded to the Droplet. Nginx, like all web servers, can only handle static files (html files, CSS files, images, JS files) without bothering the application server (Flask app). But if the web clients require dynamic content (Ex: predictions from the regression model), Nginx first accepts the HTTP request, forward it to WSGI (Gunicorn) which sends it to the Flask app (I guess Gunicorn, and any other WSGI, is not really a server but an interface...).
What about the website itself? What do you think is the most streamlined and easier (but not too easy) solution to create a website these day? I don't plan to creating html files, CSS sheets, JS files, etc. Do you recommend Wordpress? I guess I would then need to upload the Wordpress files to the Droplet. Some other components must be downloaded to work with the Wordpress files?​

4. Database: Lastly, what if I wanted to also include in this education activity a database server? Which one would you recommend that is not too hard and not too easy to learn, setup, and can do the job? MySQL? SQlite? I will need to download such server on my Oceanoptics. The database server will talk directly to the application server (Flask app), correct?​

Summary
Request: Web client= Chrome ---> Web server=NginX (inside Digitaloptics VM) ------> WSGI=Gunicorn--Application server=Flask App ----> Database Server (MySQL)
Response: Web client=Chrome <--- Web server=Nginx<------WSGI=Gunicorn--Application server=Flask App<----Database Server (MySQL)


How does all this sound?

Thank you for your help!
 
Computer science news on Phys.org
  • #2
I don't know what you mean by "not too easy" but I would go the shared hosting way if I were you.

Choosing the appropriate provider you will have:
  • your domain name registration included
  • your email easy to set up
  • SSL easy set up
  • a firewall easy to set up
  • a database included (usually MySQL)
  • Apache (maybe also Nginx) set up
  • cPanel to manage your web hosting server which will ease your load a lot and provide dozens of software that can be installed with one click (For example How to deploy a Flask App in cPanel).
And with shared hosting, it will cost you less for a low-traffic website.
 
  • Informative
  • Like
Likes fog37 and FactChecker
  • #3
Thank you.
Would you ever Docker containerize the Python application before putting it on the server?
I am appreciating the isolation Docker containers provide but it is an extra step and wonder when it is absolutely necessary...
 
  • #4
Isn't Docker to ease the process of sharing an application? You seem to want to run it only on your server, accepting requests from clients and sending back the results of your application. You wouldn't share the application itself with anyone, so this extra step would seem unnecessary. But I'm not a Docker expert. From what I've seen with Flask (which I'm no expert either), your application would run directly on your website with no extra step.

Personally, I would run a Python program directly with a shell command and get the results. You can use PHP or the like to execute a shell command, but even with only Apache, you can set it up for SSI (Server Side Includes) and execute any Python script. No need for intermediaries. Just make sure you sanitize your user input carefully, if any.

For example, I used this shtml file with Apache to read an SQLite database just to fill an HTML table:

relays-fr.shtml.png
proc/select-relays.sql:
proc-select-relays.sql.png
(Sorry for the text as images, I'm just tired of being blocked by the extra-sensitive security on PF)

And the result is this.

I like the challenge of simplicity and lightweight (as few programs as possible). And it is "not too easy" to accomplish what you want - the way you want it - securely and efficiently. :wink:
 
  • Like
Likes FactChecker
  • #5
I agree with @jack action . It seems like virtually everything should run on your server. There are real security concerns when things run on the client computer, although simple things can be built into the HTML you send them.
Keep in mind that your server will want to be able to conduct running conversations with multiple users without getting confused about who the server is talking to and what their current conversation status is. That involves some sort of database, simple or complex. And you will want to periodically clear out expired user-tracking information. My experience with this is decades old, so I don't know how much of this is aided by the utility packages that are currently available.
And @jack action 's advice about checking user inputs is right-on. It's amazing what mistakes can be made by general client users.
 
Last edited:
  • Like
Likes fog37
  • #6
From my studying/reading, a web server like Apache or Nginx is only capable of serving web clients static content.

In the case dynamic content is request (ex: results from a calculation) the server must talk to the application server (Flask app in my case). I think It can do it directly but apparently using a WSGI or a ASGI is the recommended way to do it in the case of Python applications. In the case of Java application, the middleman is not WSGI or ASGI but something similar (I think Node.js is the tool)...
 
  • #7
fog37 said:
From my studying/reading, a web server like Apache or Nginx is only capable of serving web clients static content.
Apache CGI
Nginx FastCGI

This is all included with the web server and it can handle Python scripts. Sometimes, the process is seamless as the setup is done automatically when installing the programs.

Web servers with FastCGI: https://en.wikipedia.org/wiki/FastCGI#Web_servers_that_implement_FastCGI

Languages that can be used with FastCGI: https://en.wikipedia.org/wiki/FastCGI#Language_bindings_for_its_API

https://en.wikipedia.org/wiki/Common_Gateway_Interface
 
  • Informative
  • Like
Likes fog37 and FactChecker
  • #8
jack action said:
Apache CGI
Nginx FastCGI

This is all included with the web server and it can handle Python scripts. Sometimes, the process is seamless as the setup is done automatically when installing the programs.

Web servers with FastCGI: https://en.wikipedia.org/wiki/FastCGI#Web_servers_that_implement_FastCGI

Languages that can be used with FastCGI: https://en.wikipedia.org/wiki/FastCGI#Language_bindings_for_its_API

https://en.wikipedia.org/wiki/Common_Gateway_Interface
Yes, so, based on Wikipedia, CGI (...Common Gateway Interface (CGI) is an interface specification that enables web servers to execute an external program to process HTTP or HTTPS user requests....) is similar to WSGI in the sense that they are both interfaces that the web server uses to connect with an application..
 

Similar threads

  • Programming and Computer Science
Replies
17
Views
1K
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Computing and Technology
Replies
4
Views
3K
Back
Top