[development] ANN: module 'PyBridge'

David McNab rebirth at orcon.net.nz
Sat Jul 14 23:11:56 UTC 2007


Hi Drupal hackers,

As someone who loves, admires and respects the fine framework that
Drupal is, yet much prefers Python over PHP as a programming language, I
suspect I may not be alone.

So as an experiment, I've created a module called 'PyBridge', which
allows simple Drupal page modules to be written in Python.

Module and doco are available from:
http://www.freenet.org.nz/pybridge

The basic idea is that after installing the module, you can place python
modules (say, 'hdlr_fred.py') in a directory, and these will be
available via the path 'pybridge/fred'.

Within the python module, you can access nearly all the drupal API and
globals; I've exploited some Python OO voodoo to make this easy and
transparent.

The Python module gets spawned via popen, and function calls, variable
gets/sets etc are done as a flow of serialised command packets to/from
the python process' stdio.

You can:
 - get/set PHP locals/globals - arrays, numbers, strings
 - call PHP functions - PHP builtins and Drupal API funcs
 - execute arbitrary PHP expressions and code (and yes, folks, I've
   included a whole section of security precautions to help people
   mitigate the risks of this)
 - return a string, which will be taken as the page content

You can't:
 - retrieve PHP objects - but you can retrieve their attributes and
   invoke their methods

Performance penalty is moderate but not over the top.

URL aliases can be used to render the ugly 'pybridge/fred' URIs into
something nicer.

If this interests anyone, I'd love to hear from you.
For someone with good PHP and Drupal API knowledge, this could be
spruced up into something quite nice. For example, adding configuration
options.

Cheers
David





More information about the development mailing list