Differences between revisions 15 and 16
Revision 15 as of 2009-04-22 12:32:31
Size: 6375
Editor: cpc2-nmkt1-0-0-cust410
Comment: pypy appears to have dropped javascript compilation as a back-end
Revision 16 as of 2009-05-07 20:00:38
Size: 6516
Editor: cpc2-nmkt1-0-0-cust410
Comment:
Deletions are marked like this. Additions are marked like this.
Line 26: Line 26:
 * PyXPComExt has the full Python interpreter embedded. [[http://pyxpcomext.mozdev.org/|PyXPCOMExt]] is the interpreter as a XULRunner extension; [[http://developer.mozilla.org/en/PyDOM|PyDOM]] is a library that will almost certainly be needed, that allows you to manipulate the browser's DOM model using python. The API is (almost) identical to that of javascript.  * PyXPComExt has the full Python interpreter embedded. [[http://pyxpcomext.mozdev.org/|PyXPCOMExt]] is the interpreter as a XULRunner extension; [[http://developer.mozilla.org/en/PyDOM|PyDOM]] is a library that will almost certainly be needed, that allows you to manipulate the browser's DOM model using python. The API is (almost) identical to that of javascript. Effectively, where browsers have built-in support for 'lang="javascript"', PyXPComExt adds <script lang="python"> .... </script> to Firefox.

Web Browser Programming in Python

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 webkit, the technology behind Safari, Midori, the OLPC Browser, Adobe AIR, Google Chrome and much more; Gecko, the engine behind Firefox, XULRunner and 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.
  • 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 (except with python) 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 library 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 pyv8), or in a web browser (where, in order to be useful, the applications must of course interface with the DOM model of the browser, typically using an AJAX library). Note: as of April 2009, pyjamas appears to be the only actively maintained python-to-javascript compiler.
  • Pyjamas is a Python-to-Javascript compiler and AJAX-based Web Toolkit and Framework that allows users to write code in standard python that will be run in a web browser, after translation to javascript. pyjs - the compiler - can also be used as a stand-alone javascript compiler.

  • Py2Js is an unmaintained project that can still be downloaded here. It is purely a python-to-javascript compiler / translator.

  • PyPy is compiler technology that contains an alternative python interpreter front-end and also supports javascript as output on the back-end. Using Pypy/JS describes how to integrate with libraries such as mochikit. Note: when last checked (2009 april) the pypy team appear to have removed all documentation mentioning support for javascript as a back-end in pypy, and have removed all tutorials on the subject.

Embedding Python inside Web Browsers

  • This section describes projects where the python interpreter itself can and has been embedded into the web browser. Instead of downloading the standard python executable and libraries, these projects come with the python 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; PyDOM is a library that will almost certainly be needed, that allows you to manipulate the browser's DOM model using python. The API is (almost) identical to that of javascript. Effectively, where browsers have built-in support for 'lang="javascript"', PyXPComExt adds <script lang="python"> .... </script> to Firefox.

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).
  • PyWebKitGtk - PyWebkitGtk is a python wrapper around Webkit that embeds the Webkit "engine" as a GTK widget. The standard version of pywebkitgtk is unable to provide access to the DOM model, treating pywebkit as a hands-off widget that can be used to write your own Web Browser (see demobrowser.py). However, a patch to webkit and a corresponding patch to pywebkitgtk will soon bring DOM model manipulation to python: see PyjamasDesktop for details.

  • PyWebkitQt4 is a python wrapper again around Webkit but this time as a Qt4 widget. Bindings to the DOM model have not been added to PyWebkitQt4, and so you can only use PyWebkitQt4 to create your own web browser, rather than manipulate the DOM model content itself.

  • PyKDE - KDE contains python bindings to KHTMLPart (which is very similar to Webkit). This allows you to embed HTML into an application window. The Python bindings to the DOM model are slightly... obtuse. to say the least, and PyKHTML - 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.

  • Webkit with the ObjectiveC bindings (MacOSX users only). Webkit itself has ObjectiveC bindings, on MacOSX. MacOSX's ObjectiveC technology comes with automatic bindings to all major programming languages, including python. Consequently, you can directly manipulate the DOM model from python.

  • HulaHop provides python access to DOM model manipulation - via XUL / Gecko Interfaces. HulaHop is part of the OLPC Sugar Project, but is available stand-alone. It depends on pydom (part of XULrunner).

WebBrowserProgramming (last edited 2017-11-28 19:43:54 by jacdeh)

Unable to edit the page? See the FrontPage for instructions.