tags:

views:

474

answers:

5

Dear All,

I have written a bunch of Perl libraries (actually Perl classes) and I want to use some of them in my Python application. Is there a natural way to do this without using SWIG or writing Perl API for Python. I am asking for a similar way of PHP's Perl interface. If there is no such kind of work for Perl in Python. What is the easiest way to use Perl classes in python?

+1  A: 

Check out PyPerl.

WARNING: PyPerl is currently unmaintained, so don't use it if you require stability.

splicer
yeah actually stability is an important metric for me.
systemsfault
You're probably best to port your Perl classes to Python then. AFAIK, PyPerl is currently the only easy way to call Perl code from Python code.
splicer
or port the python code to perl :D. which may take less time because the amount of perl code is much bigger than the python one. But in this case, i will miss the chance of writing code in Python but this is tolerable i guess :).
systemsfault
+2  A: 

You've just missed a chance for having Python running on the Parrot VM together with Perl. On April 1st, 2009 PEP 401 was published, and one of the Official Acts of the FLUFL read:

  • Recognized that C is a 20th century language with almost universal rejection by programmers under the age of 30, the CPython implementation will terminate with the release of Python 2.6.2 and 3.0.2. Thereafter, the reference implementation of Python will target the Parrot virtual machine. Alternative implementations of Python (e.g. Jython, IronPython, and PyPy ) are officially discouraged but tolerated.
gimel
Uh oh, you're in trouble: "This document is the property of the Python Steering Union (not to be confused with the Python Secret Underground, which emphatically does not exist). We suppose it's okay for you to read this, but don't even think about quoting, copying, modifying, or distributing it."
mpeters
Will the Steering Union reconsider ?
gimel
I think the "April 1st" part should perhaps be made bold. I was rather confused until I reread it more carefully.
alberge
Makes one sad, contemplating the early (4 months) obsolescence of PEP401.
gimel
+2  A: 
S.Lott
actually i tried to mean by Perl API for Python was the same thing you described in your second step. I also have to provide a small api for Python because my Perl libraries are pm files and they are not standalone executable files so i'd have to write pl file which allows access to py libraries.
systemsfault
+5  A: 

Personally, I would expose the Perl libs as services via XML/RPC or some other such mechanism. That way you can call them from your Python application in a very natural manner.

Shane C. Mason
thanx shane at the moment i am considering 2 options either rewriting in python or implement an API for communicating two languages using sockets.
systemsfault
+4  A: 

I haven't tried it, but Inline::Python lets you call Python from Perl.

You should be able to use a thin bit of perl to load your python app and then use the perl python package that comes with I::P to access your Perl objects.

daotoad