PYRO - Python Remote Objects

Example

Quickly now, how does it work? A scenario

  1. The programmer writes a module 'test' containing a class 'testclass', which will be accessed remotely.
  2. The server creates one or more instances of the 'testclass', and registers them with the Pyro Naming Service.
  3. The client queries the Naming Service for the location of those objects. It gets a Pyro URI for them.
  4. The client asks Pyro to create proxies for the remote object URIs.
  5. As the proxy appears just like the real 'testclass', the client can now invoke methods on the remote objects, as if it were normal (local) objects.

Minimal example code: the Server

import Pyro.core
import Pyro.naming

class JokeGen(Pyro.core.ObjBase):
    def joke(self, name):
        return "Sorry "+name+", I don't know any jokes."

daemon=Pyro.core.Daemon()
ns=Pyro.naming.NameServerLocator().getNS()
daemon.useNameServer(ns)
uri=daemon.connect(JokeGen(),"jokegen")
daemon.requestLoop()

Minimal example code: the Client

import Pyro.core

# finds object automatically if you're running the Name Server.
jokes = Pyro.core.getProxyForURI("PYRONAME://jokegen")

print jokes.joke("Irmen")

If you don't like having to start a Name Server... or want to know more...

Then you are lucky because Pyro provides a direct-lookup feature. And in the Example chapter in the manual, a lot more is explained.