Wednesday, 2 April 2008

Calling Python from Perl

After a long silence this is definitely worth an entry - the Perl Inline module for calling code in various other languages from Perl...

I've been looking into integrating NERC DataGrid Security (all written in Python) into the existing BADC web site Perl CGI code - quick dirty if necessary.

The NDG Security Single Sign On service has a http interface so this should be straightforward - Perl on one side of the interface and Python the other. However the various SOAP interfaces with WS-Security added into the mix doesn't make it very attractive. I've not looked into Perl SOAP support - and this may be great - but if we are migrating all our Perl code to Python it would seem a wasted effort.
Inline is really impressive. I had a python client call to the NDG Attribute Authority working in minutes - Perl calling Python calling a SOAP Service and returning the response back to Perl as a local variable:

Perl <-> Python <-> SOAP + WS-Security <-> Python Attribute Authority Web service

Installation was fairly straightforward on Ubuntu - libinline-perl package is available but Inline-Python required downloaded and install from CPAN.

I was expecting all kinds of shared library link errors but all works perfectly. It's nice when things work simply easily and quickly for a change :)

#!/usr/bin/env perl
use Inline Python => <<'END';
def getAAHostsInfo():
    from import AttAuthorityClient
    import os

    aaClnt = AttAuthorityClient(uri="http://localhost:5000/AttributeAuthority",

    allHostsInfo = aaClnt.getAllHostsInfo()
    return "All hosts info = %s" % allHostsInfo

print getAAHostsInfo(), "\n";

No comments: