Web Browser Programming in Python
TODO: merge in and research these, found on comp.lang.python
Yes, Python can do it... on Windows.
Two (examples) ways:
ActiveScripting (PythonScript), included in PyWin32
Gestalt (who mix Python, Ruby & JavaScript, via Silverlight)
TODO: Add mention of IPython Notebook which can be run remotely, easily on AWS, and used within your browser. The HTML client can also interact with JavaScript and DOM, though this feature isn't quite merged yet. There's a lot being done on it, but it's already being used and probably should be mentioned here.
This topic covers ways in which python can be used in web browsers to control, create or manipulate the content within a user's web browser, or a web-based technology (such as much more); and KDE's KHTMLPart.
To clarify what type of technology goes onto this page, some examples of types of technology that can and cannot be added to this section:
Specifically excluded from the list is technology that simply generates static HTML content. So, an HTML pretty-printer library, as the resultant HTML simply uses the browser for "display" purposes rather than using the browser as an "application execution environment", is out. Such technologies can instead be found at WebClientProgramming.
Plugins for Web Browsers that provide direct access to the DOM model of the web browser. In exactly the same way that most web browsers have JavaScript by default as a language that can directly access the DOM model of the web browser, a plugin or other system that can do the same thing (with Python using <script type="text/python" /> instead of JavaScript using <script language="javascript" />) should be listed on this page.
Python-based technology that auto-generates or compiles JavaScript definitely counts, as the resultant JavaScript would be executed by the web browser.
Technology that simply uses JavaScript or depends on JavaScript libraries (such as mochikit, extjs or prototype) does not count, but a Python-based wrapper library around a JavaScript engine definitely counts.
This latter example requires some further explanation: Pyjamas, for example, is a Python-to-JavaScript compiler that can include inline JavaScript. So, although the input to Pyjamas is part Python, part JavaScript, the output is pure JavaScript that runs in a web browser, and so any such "mixed" language libraries should be included on this page.
Python-to-JavaScript Compilers
These are tools that convert Python into JavaScript, that can then be run either stand-alone, using technology such as Spidermonkey, Google's V8 engine (for example, using Py2js is a maintained project that provides a Python-to-JavaScript compiler.
Documentation with extensive examples using a diversity of JavaScript libraries. Native JavaScript code can be inserted anywhere in the Python source. Can be used in combination with Django or Bottle to have the same language on client and server side. Many Brython is a Python 3 implementation that runs in a browser, providing <script type="text/python">...</script>.
Embedding Python inside Web Browsers
This section describes projects where a Python interpreter itself has been embedded into the web browser. Instead of downloading the standard Python executable and libraries, these projects come with the CPython runtime and libraries pre-embedded (and, as such, are typically very large downloads).
PyXPComExt has the full Python interpreter embedded. PyXPCOMExt is the interpreter as a XULRunner extension; Firebreath is an NPAPI plugin that extends access to the full features of DOM programming out to other programming languages, including python.
Python Wrappers around Web "Libraries" and Browser Technology
This section describes projects where you can (or have to) create your own web browser application in Python. It includes web browser "engines" that have Python interfaces to access, control and present web pages and web-relevant rich media content (such as Adobe Flash).
Webkit that provides direct access to the DOM model. PyWebKitGtk has been incorporated into the build, rather than being built separately. Unlike the patched version of PyWebKitGtk, PythonWebKit does not go via gobject to access DOM functions but instead calls the Webkit DOM functions direct.
PyWebKitGtk - PyKHTML makes them much more tolerable (see dom.py). However, there are limitations in PyKDE's DOM bindings (that many people will never encounter) that you should investigate thoroughly before utilising PyKDE for seriously heavy-duty DOM model manipulation. To avoid those limitations you should ensure that the entire KDE platform is compiled with C++ RTTI enabled (it is typically disabled by most distributions, by default).
WebKit with the Objective-C bindings (MacOS X users only). mshtml.py port. Note that creation and use of XMLHttpRequest is also shown in PyjamasDesktop's mshtml.py.
- python-wxWebKit is beginning to provide Python access to DOM model manipulation - via python bindings that are auto-generated using SWIG. The goal of the project is to provide full access to the entire DOM model, and this goal is, as of May 2011, approximately 25% completed.
Python Wrappers around Web Browser "Test Suite" Libraries
This section describes projects where you can test web applications, initiated from the command-line with python bindings.
Windmill is a web testing tool designed to let you painlessly automate and debug your web application. Like selenium, it also has Python bindings.