On this page
  1. xmlrpc
  2. Import
  3. Overview
  4. Quick Start
  5. Implementation Walkthrough
  6. 1. Calling a Remote Endpoint and Registering Server Handlers
  7. Gotchas & Boundaries

xmlrpc

Prev: xml | Up: stdlib_module | Next: zipapp
Rel: email, json, mailbox, mimetypes, base64
Ref: docs.python.org — xmlrpc
Tags: #public #python3 #stdlib


Import

import xmlrpc

Overview

Package providing an XML-RPC client (xmlrpc.client) and server (xmlrpc.server) for remote procedure calls over HTTP using XML payloads. Reach for xmlrpc when integrating with existing XML-RPC endpoints (such as Supervisor, Odoo, or legacy internal services); for new APIs, prefer JSON over HTTP or gRPC.

Quick Start

import xmlrpc.client

# Marshal and unmarshal an XML-RPC call payload without needing a live network server
payload = xmlrpc.client.dumps((6, 7), methodname="multiply")
params, method = xmlrpc.client.loads(payload)
assert (method, params) == ("multiply", (6, 7))

Implementation Walkthrough

1. Calling a Remote Endpoint and Registering Server Handlers

Use ServerProxy as a context manager on the client side, and SimpleXMLRPCServer (with register_function or register_instance) on the server side:

import xmlrpc.client
from xmlrpc.server import SimpleXMLRPCServer

# Client usage
def call_remote_add(endpoint_url: str, a: int, b: int) -> int:
    with xmlrpc.client.ServerProxy(endpoint_url, allow_none=True) as proxy:
        return proxy.add(a, b)

# Server setup
def build_server(host: str, port: int) -> SimpleXMLRPCServer:
    srv = SimpleXMLRPCServer((host, port), allow_none=True, logRequests=False)
    srv.register_function(lambda a, b: a + b, "add")
    return srv

Gotchas & Boundaries

Linked from

Related notes