Skip to content

xmlrpc_extended.asgi

ASGI 3-compliant XML-RPC application.


XMLRPCASGIApp

XMLRPCASGIApp

XMLRPCASGIApp(*, max_workers: int = _DEFAULT_MAX_WORKERS, max_request_size: int = _DEFAULT_MAX_REQUEST_SIZE, rpc_path: str = _DEFAULT_RPC_PATH, allow_none: bool = False, encoding: str | None = None, use_builtin_types: bool = False)

Bases: SimpleXMLRPCDispatcher

ASGI 3-compliant XML-RPC application.

Inherits :class:~xmlrpc.server.SimpleXMLRPCDispatcher for full compatibility with the standard registration API. Both async def and regular synchronous handler functions are supported.

Parameters:

Name Type Description Default
max_workers int

Thread-pool size for synchronous handler functions. async def handlers bypass the pool entirely.

_DEFAULT_MAX_WORKERS
max_request_size int

Maximum accepted request body in bytes. Requests larger than this receive 413 Payload Too Large.

_DEFAULT_MAX_REQUEST_SIZE
rpc_path str

URL path at which XML-RPC POST requests are accepted. Requests to any other path receive 404 Not Found.

_DEFAULT_RPC_PATH
allow_none bool

Whether None values are permitted in XML-RPC payloads.

False
encoding str | None

XML encoding override; None defaults to UTF-8.

None
use_builtin_types bool

Map XML-RPC dateTime/base64 to Python built-in :class:datetime.datetime / :class:bytes.

False
Example
app = XMLRPCASGIApp(rpc_path="/rpc", max_workers=4)
app.register_function(lambda a, b: a + b, "add")

# Run with: uvicorn mymodule:app

Initialise the ASGI application.

Parameters:

Name Type Description Default
max_workers int

Thread-pool size for synchronous handler functions.

_DEFAULT_MAX_WORKERS
max_request_size int

Maximum body in bytes (default 1 MiB).

_DEFAULT_MAX_REQUEST_SIZE
rpc_path str

URL path accepted for XML-RPC POST requests.

_DEFAULT_RPC_PATH
allow_none bool

Allow None in XML-RPC payloads.

False
encoding str | None

XML encoding; None uses UTF-8.

None
use_builtin_types bool

Map XML types to Python built-ins.

False

Raises:

Type Description
ValueError

If max_workers < 1 or max_request_size < 1.

Source code in src/xmlrpc_extended/asgi.py
def __init__(
    self,
    *,
    max_workers: int = _DEFAULT_MAX_WORKERS,
    max_request_size: int = _DEFAULT_MAX_REQUEST_SIZE,
    rpc_path: str = _DEFAULT_RPC_PATH,
    allow_none: bool = False,
    encoding: str | None = None,
    use_builtin_types: bool = False,
) -> None:
    """Initialise the ASGI application.

    Args:
        max_workers: Thread-pool size for synchronous handler functions.
        max_request_size: Maximum body in bytes (default 1 MiB).
        rpc_path: URL path accepted for XML-RPC POST requests.
        allow_none: Allow ``None`` in XML-RPC payloads.
        encoding: XML encoding; ``None`` uses UTF-8.
        use_builtin_types: Map XML types to Python built-ins.

    Raises:
        ValueError: If ``max_workers < 1`` or ``max_request_size < 1``.
    """
    if max_workers < 1:
        raise ValueError("max_workers must be at least 1")
    if max_request_size < 1:
        raise ValueError("max_request_size must be at least 1")

    super().__init__(allow_none=allow_none, encoding=encoding, use_builtin_types=use_builtin_types)
    self._max_request_size = max_request_size
    self._rpc_path = rpc_path
    self._max_workers = max_workers
    self._executor: ThreadPoolExecutor | None = None

__call__ async

__call__(scope: _ASGIScope, receive: _ASGIReceive, send: _ASGISend) -> None

ASGI 3 callable entry point.

Dispatches to :meth:_handle_lifespan for lifespan scopes and :meth:_handle_http for http scopes. Other scope types are silently ignored to stay forward-compatible with future ASGI extensions.

Parameters:

Name Type Description Default
scope _ASGIScope

ASGI connection scope dict.

required
receive _ASGIReceive

Async callable that yields incoming ASGI events.

required
send _ASGISend

Async callable for sending ASGI response events.

required
Source code in src/xmlrpc_extended/asgi.py
async def __call__(
    self,
    scope: _ASGIScope,
    receive: _ASGIReceive,
    send: _ASGISend,
) -> None:
    """ASGI 3 callable entry point.

    Dispatches to :meth:`_handle_lifespan` for ``lifespan`` scopes and
    :meth:`_handle_http` for ``http`` scopes.  Other scope types are
    silently ignored to stay forward-compatible with future ASGI extensions.

    Args:
        scope: ASGI connection scope dict.
        receive: Async callable that yields incoming ASGI events.
        send: Async callable for sending ASGI response events.
    """
    scope_type = scope.get("type")
    if scope_type == "lifespan":
        await self._handle_lifespan(scope, receive, send)
    elif scope_type == "http":
        await self._handle_http(scope, receive, send)

close

close() -> None

Shut down the thread pool gracefully.

Called automatically during the ASGI lifespan shutdown event. Call this explicitly when using the app outside of a lifespan-aware ASGI server (e.g. in tests).

Source code in src/xmlrpc_extended/asgi.py
def close(self) -> None:
    """Shut down the thread pool gracefully.

    Called automatically during the ASGI lifespan shutdown event.  Call
    this explicitly when using the app outside of a lifespan-aware ASGI
    server (e.g. in tests).
    """
    if self._executor is not None:
        self._executor.shutdown(wait=True)
        self._executor = None