System Requirements
   Environment Variables
   The mozpython built-in module
   PyXPCOM support
How to help


MozPython embeds the Python interpreter in Mozilla. With MozPython you can execute Python scripts in Mozilla. Output sent to sys.stdout by a script is displayed in Mozilla's browser window, where it is interpreted as HTML.

If you have written a Web application with Python CGI scripts you can now have your application be executed offline running the same scripts in Mozilla.

In this respect MozPython is similar to MozPHP. But with MozPython you can do more. If you have PyXPCOM installed on your system you can access Mozilla internals from your Python scripts.


Copyright (c) 2004 Dr. Thomas Schilz

MozPython is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

MozPython is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

System Requirements

MozPython has been developed and tested with Mozilla 1.5 under Linux and Windows. It won't work with versions of Mozilla older than 1.3 and it has not been tested with other operating systems.

The Mozilla 1.5 binaries should work with Mozilla Firebird 0.7 too.

Of course you also need to have Python installed on your system.


Response headers are not (yet) processed.
As a consequence you cannot set cookies in your scripts.
Probably many others I'm not aware of.
If you find one, please inform me. Better yet, fix it.


Precompiled binaries are available here for Mozilla 1.5 and Python 2.3 under Linux and Windows. The downloadable zip files are named, where x denotes the MozPython version, y the Mozilla version, z the Python version, and os the operating system.


Download the suitable for your Mozilla and Python version and extract it in your Mozilla installation directory. You should now find the following files in the components directory:

In directory python/xpcom you should find mpdlpxpc.dll.

Make sure that Python is installed on your system and that the Python DLL is in your PATH. (For example, the DLL for Python 2.3 is named python23.dll.)


Download suitable for your Mozilla and Python version and extract it in your Mozilla installation directory. You should now find the following files in the components directory:

In directory python/xpcom you should find

Make sure that Python is installed on your system and that the Python shared library (eg. is in your library search path.

All platforms

Close any open Mozilla windows. Backup and then delete compreg.dat and xpti.dat in the components directory.

Restart Mozilla. As a simple test if MozPython has been installed correctly download and extract it in some directory DIR on your local hard disk. Then open cfh://DIR/ As a result you should see something like this:

Now click at the GET Test link, and the result should look as follows:

Finally enter some text, eg. foo into the input field and click at the POST Test button. Now you should get this:


Open your Python script files using the cfh protocol as shown above. They must have the extension .py.

Output of a script to sys.stdout is collected and upon the script's completion, is sent to the browser window. Output to sys.stdout is expected to be HTML. Output to sys.stderr is sent to the JavaScript console.

If the script terminates with a non zero exit status an error message is displayed in the JavaScript console.

Environment variables

MozPython sets some environment variables that are normally set by a Web server when executing a CGI script. One of them is SERVER_SOFTWARE which is set to MozPython.

The mozpython built-in module

MozPython adds a built-in module mozpython to Python. So besides the SERVER_SOFTWARE variable mentioned above, another way to determine if a script is running in Mozilla is to try importing this module. It has an attribute version providing access to the MozPython version.

PyXPCOM support

If you have PyXPCOM installed on your system, then MozPython will add an attribute docShell to the mozpython module. It provides access to the nsISupports interface of the browser window's nsDocShell instance. docShell can be queried for other interfaces to get access for example to the Mozilla GUI. in is a very simple sample script. It prints the URI of the script and the navigator XUL document and resizes the document window inside the browser window. Load cfh://DIR/, and the result should look similar to this:

PyXPCOM is part of the Mozilla sources but it is not compiled into the standard Mozilla distribution. For your convenience I've put binaries for Linux and Windows into the downloads directory. The naming scheme is similar to that of the MozPython binaries. Extract the appropriate Zip file for your system to your Mozilla installation directory. This will put some files into the components directory and create a directory named python in the Mozilla directory. Don't move these files to somewhere else or PyXPCOM won't work!

For more information about PyXPCOM see ActiveState's PyXPCOM page.



MozPython consists of three components:
A stream converter for the conversion of documents with MIME type text/python to HTML. PyToHTMLConv opens the documents, feeds them to the Python interpreter and passes their output on to the browser window.
A protocol handler that partly implements the file protocol and the http protocol. It assigns MIME type text/python to documents with extension .py. (It also assigns MIME type text/php to documents with extension .php. This is for MozPHP which also uses this protocol handler.)
A small auxiliary library needed for PyToHTMLConv beeing able to dynamically load and use PyXPCOM's _xpcom library.


If you have a problem using or compiling MozPython, please read the FAQ. If you can't find a solution for your problem there, try to find out what is going wrong by reading the sources. If you find a solution please send the modifications you made to If you really can't fix the problem yourself, send an email to with a detailed description of the problem and of the computing environment you are working with.


Your help is appreciated in the further development of MozPython.