There are numerous RPC solutions which allow you to cross between one language and another, but I've had the most experience—and the most satisfying experience—using XML-RPC. So far it's solved all the problems that I've encountered, and it's simple to understand and straightforward to use. And it's an excellent solution for distributed systems, since you can effortlessly cross over machine boundaries (you do, however, need to come up with your own callback approach when starting long-running processes on remote machines).
Python has the philosophy of "batteries included," which means that there's a very good chance that whatever you need is part of the standard library. This isn't just convenient; the standard libraries tend to get much greater focus and support than open-source projects, so the quality of the code tends to be better.
Python's SimpleXMLRPCServer library allows you to easily create a server. In the following example, I show you how to code a simple server that provides two services to manipulate strings:
import sys
from random import shuffle
from SimpleXMLRPCServer import SimpleXMLRPCServer
class MyFuncs:
def reverse(self, str) :
x = list(str);
x.reverse();
return ''.join(x);
def scramble(self, str):
x = list(str);
shuffle(x);
return ''.join(x);
server = SimpleXMLRPCServer(("localhost", 8000))
server.register_instance(MyFuncs())
server.serve_forever()
You can publish regular functions (not associated with a class), but I find the class approach is cleaner. This particular server is located on the current machine at port 8000, and that's all the client needs to know.
Once the
server is started, you need to make a client that will connect to the server and
call the services. This is also very easy to do with Python using the standard ServerProxy class in the xmlrpclib library:
from xmlrpclib import ServerProxy
server = ServerProxy("http://localhost:8000")
print server.reverse('giraffe')
print server.scramble('giraffe')
Once you make a connection to the server, that server acts like a local object. You call the server's methods just like they're ordinary methods of that object.
This is about as clean an RPC implementation as you can hope for (and other Python RPC libraries exist; for example, CORBA clients), but it's all text based. It's not very satisfying when you're trying to create polished applications with nice GUIs. What is preferable is the best of all worlds—Python (or your favorite language) doing the heavy lifting under the covers, and Flex creating the user experience.