Skip to content

xmlrpc_extended.client

Optional client helpers for XML-RPC callers.


XMLRPCClient

XMLRPCClient

XMLRPCClient(uri: str, *, timeout: float = 30.0, allow_none: bool = False, use_builtin_types: bool = False)

Context-manager wrapper for :class:~xmlrpc.client.ServerProxy.

Ensures the underlying connection is closed on exit and enforces an explicit connection timeout so hung servers do not block callers indefinitely.

Parameters:

Name Type Description Default
uri str

Full URL of the XML-RPC endpoint, e.g. "http://127.0.0.1:8000/".

required
timeout float

Socket timeout in seconds (default: 30.0).

30.0
allow_none bool

Whether None values are permitted in payloads.

False
use_builtin_types bool

Use Python built-in types for XML-RPC date/binary.

False

Example::

with XMLRPCClient("http://127.0.0.1:8000/", timeout=5.0) as proxy:
    result = proxy.my_method(arg1, arg2)

.. note:: Retrying failed requests is the caller's responsibility. XML-RPC methods are not necessarily idempotent, so automatic retries would risk duplicate side-effects. Wrap the with block in your own retry loop when retrying is safe.

Source code in src/xmlrpc_extended/client.py
def __init__(
    self,
    uri: str,
    *,
    timeout: float = 30.0,
    allow_none: bool = False,
    use_builtin_types: bool = False,
) -> None:
    self._uri = uri
    self._timeout = timeout
    self._allow_none = allow_none
    self._use_builtin_types = use_builtin_types
    self._proxy: xmlrpc.client.ServerProxy | None = None