1. Introduction

PSE is an application server framework that lets you build complex web-based applications in Python. It works as an apache module built in conjunction with mod_python. The application uses compiled ``servlets'' written in Python to produce application output. This means that each page runs very fast because it is the result of executing compiled Python code -- no need for parsing past the first run, as with PHP or other web application servers.

Each servlet has two components, the template and the code module. This kind of architecture allows the separation of presentation and implementation, i.e. the HTML designer and the Python programmer. The template file is a syntactically valid HTML file with processing instructions and/or custom tags defined by the programmer. This file is parsed and translated into an executable Python script, which is compiled and stored. A template file has the file extenson .pt.

The code module is a regular Python module, which is also compiled and stored in the same way that Python itself compiles and stores modules. When a web request is made, PSE executes the code module first in the global namespace, then executes the template servlet in the same global namespace as the code module. This allows any Python generated from the template to access everything that was created by the code module. A code module has the same base file name as the template, but with the extension .py.

It is possible to create a template without any code module. This frees the HTML designer to create working mock-ups of pages that can be filled in later by program logic created by the Python programmer in the code module. It is not possible to create a stand-alone code module without a template, although the template could be an empty file. This is for security reasons; it allows modules to be placed in the application directory so they can be imported by other modules, but never executed as a stand-alone script.

Template files get compiled to .ptc files. An intermediate file ending in .pty is stored to aid in debugging, which contains the source code for the compiled servlet. The code module is compiled to a file ending in .pyc or .pyo, the same as normal python modules. In addition, output from a servlet execution can be cached according to whatever rules the programmer specifies, which results in a .pto file. When output is cached, the servlet will not be executed until the cached file expires, and only the cached file will be sent instead.

There are tools to pre-compile the template and code modules. If a directory only consists of .ptc and .pyc (or .pyo) files, PSE will only use them and never look for the source files. This way users of the application will never have to experience a delay due to parsing and compiling of any files, and you can distribute only optimized compiled files to protect your intellectual property in the source code.