There are hundreds of systems to perform RPC in Python, but because it has powerful networking tools and is a dynamic language, everything we need is already built into the standard library.
You need to perform the following steps for this recipe:
- Using
xmlrpc.server
, we can easily create an XMLRPC-based server that exposes multiple services:
import xmlrpc.server class XMLRPCServices: class ExposedServices: pass def __init__(self, **services): self.services = self.ExposedServices() for name, service in services.items(): setattr(self.services, name, service) def serve(self, host='localhost', port=8000): print('Serving XML-RPC on {}:{}'.format(host, port)) self.server = xmlrpc.server.SimpleXMLRPCServer((host, port)) self.server.register_introspection_functions() self.server.register_instance(self.services, allow_dotted_names=True) ...