indexdownloadinstallconfigappscompliancerelated

A WSGI server for jython

  1. Introduction to modjy
  2. License: Apache License Version 2.0
  3. A structural overview of modjy

1: Introduction to modjy

[top]

Python Web Server Gateway Interface, as specified in PEP-333, is a "simple and universal interface between web servers and [python] web applications or frameworks".

Modjy is an implementation of a WSGI compliant gateway/server for jython, built on Java/J2EE servlets. Which means that

  1. Jython WSGI applications run inside a Java/J2EE servlet container, e.g. Apache Tomcat
  2. Incoming requests are handled by the servlet container
  3. The container is configured to route requests to the modjy servlet
  4. The modjy servlet creates an embedded jython interpreter inside the servlet container, and loads a configured jython web application, e.g. Django, "the web framework for perfectionists with deadlines".
  5. The modjy servlet delegates the requests to the configured WSGI application or framework.
  6. The WSGI response is routed back to the client through the servlet container.

For further information about WSGI, see wsgi.org. For a detailed specification of WSGI see PEP-333: Python Web Server Gateway Interface, version 1.0.

A - What modjy is not

Since modjy was developed at the same time as the WSGI specification, the text below was written when few people knew what WSGI was and what it wasn't. These days, WSGI is much better known, and most python web frameworks support it. But still, it's worth leaving in the following paragraph, for completeness.

Modjy is not another python web framework! There are already enough frameworks for python, as can be seen on the Python web programming wiki. So much energy has gone into building those frameworks that there is little to be achieved by replicating that work. Instead, it is to be hoped that the authors of some of those frameworks will port their frameworks to WSGI, in which case they will be portable to every WSGI server, including modjy.

Which means that it is possible to run python web frameworks under jython and java.

2: License: Apache License Version 2.0

[top]

Modjy is released under the Apache License Version 2.0

The full text of the licence, including all terms and conditions, is included in the Download.

3: A structural overview of modjy

[top]

A - Architecture

The architecture of modjy is very simple, from a J2EE point of view. It consists of a single java servlet class, which is a thin wrapper around the required jython functionality. Since the java servlet is multithreaded, only one instance of it will ever run in a given container (unless configured otherwise). This java servlet also initializes the jython runtime, setting some necessary parameters beforehand.

The java servlet then creates a single instance of the jython-implemented modjy_servlet class, to which all incoming HTTP requests are delegated. Depending on configuration, modjy_servlet creates 1 or more instances of the jython WSGI application object, as described in How modjy locates application callable objects. It then creates WSGI environment and start_response_callable objects, and invokes the application.

More details on how to configure modjy to use single vs. multi threading, etc, see the Configuration reference.

B - Code structure

The principal jython class for implementation of modjy is the modjy_servlet class. This class uses mixins to factor out code by functionality, so that the structure can be more easily evolved, components replaced, etc.

Modjy has been updated to work on jython 2.2, and will no longer run on jython 2.1.