Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Python equivalent of Tomcat?

This question likely betrays a misconception, but I'm curious what the "Tomcat" of the Python world is.

All of my web programming experience is in Java (or Groovy) so I think in Java terms. And when I think of making a basic web-app, I think of writing some servlets, building a WAR file, and deploying it in Tomcat or another servlet container.

In Python, suppose I wrote some code that was capable of responding to HTTP requests, what would I do with it? How would I deploy it?

Specifically: What is the most commonly used container in Python? And is there an equivalent of a WAR file, a standard packaging of a web-app into one file that works in the various containers?

like image 594
Eric Wilson Avatar asked May 27 '11 19:05

Eric Wilson


People also ask

Can Apache Tomcat be used for Python?

Jython/Python has a rich set of libraries that you can use within you Tomcat application, but before you can start using these libraries you need to make them available to your application. To do this: Download the Jython installer from the link above.

What is Servlet equivalent in Python?

DSA (Self-Paced) CIP (Self-Paced) JAVA / Python / C++ (Self-Paced)

Is Tomcat still relevant?

Nowadays, Apache Tomcat is widely used by many companies as it implements many of the Java EE specifications, such as: Java Servlet.

Is Tomcat front end or backend?

This allows rapid development of both the back-end (embedded tomcat can restart quickly for back-end changes), AND front-end code (any changes made to html/javascript/css can be picked up with just a refresh while the app is running in embedded mode).


2 Answers

There are different approaches which have one thing in common: They usually communicate via WSGI with their "container" (the server receiving the HTTP requests before they go to your Python code).

There are various containers:

  • wsgiref - a very simple reference implementation which is nice during development
  • Apache with mod_wsgi
  • most other Webservers with a module adding WSGI support
  • many more
like image 156
ThiefMaster Avatar answered Sep 21 '22 02:09

ThiefMaster


when I think of making a basic web-app, I think of writing some servlets, building a WAR file, and deploying it in Tomcat or another servlet container.

That's nice, but irrelevant. That's just a Java-ism, and doesn't apply very widely outside Java.

In Python, suppose I wrote some code that was capable of responding to HTTP requests, what would I do with it? How would I deploy it?

That depends.

What is the most commonly used container in Python?

There isn't one.

And is there an equivalent of a WAR file, a standard packaging of a web-app into one file that works in the various containers?

There isn't one.


HTTP is a protocol for producing a response to a request. That's it. It's really a very small thing.

You have CGI scripts which can respond to a request. The Python cgi library can do that. http://docs.python.org/library/cgi.html.

This is relatively inefficient because the simple CGI rule is "fire off a new process for each request." It can also be insecure if the script allows elevated privileges or badly planned-out uploads.

You have the mod_wsgi framework to connect Apache to Python. This can behave like CGI, or it can have a dedicated Python "daemon" running at the end of a named pipe.

The WSGI standard defines a format for request and response processing that's very handy and very extensible. Most of the frameworks -- in one way or another -- are WSGI compatible.

Finally, there are more complete frameworks that include class definitions for requests and responses, URL parsing, Authentication, Authorization, etc., etc.

Here's a list: http://wiki.python.org/moin/WebFrameworks

like image 20
S.Lott Avatar answered Sep 23 '22 02:09

S.Lott