mxcubecore.ipc¶
IPC layer exposing a whitelist of HardwareObject methods to third-party clients, over a JSON-RPC/TCP or NanoMQ (MQTT) transport.
See IPC_FORMAT.md for the wire format.
- class mxcubecore.ipc.ErrorCode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
IntEnumError codes carried in an
mxcubecore.ipc.models.IPCError.The negative range below -32000 mirrors the JSON-RPC 2.0 reserved codes so a plain JSON-RPC client can interpret them, as defined by the JSON-RPC 2.0 spec.
- class mxcubecore.ipc.IPCError(*, code: int, message: str, data: Any | None = None)[source]¶
Bases:
BaseModelError payload carried in an IPCErrorResponse.
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class mxcubecore.ipc.IPCErrorResponse(*, jsonrpc: Literal['2.0'] = '2.0', id: str | int | None = None, error: IPCError)[source]¶
Bases:
_JsonRpcError reply to an IPCRequest.
id is None when the request’s id couldn’t be determined (e.g. parse error).
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class mxcubecore.ipc.IPCEvent(*, jsonrpc: ~typing.Literal['2.0'] = '2.0', method: str, params: ~typing.Dict[str, ~typing.Any] = <factory>)[source]¶
Bases:
_JsonRpcA server-initiated notification (no id, no reply expected).
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class mxcubecore.ipc.IPCRequest(*, jsonrpc: ~typing.Literal['2.0'] = '2.0', id: str | int, method: str, params: ~typing.Dict[str, ~typing.Any] = <factory>)[source]¶
Bases:
_JsonRpcA command sent by the client to invoke one whitelisted method.
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class mxcubecore.ipc.IPCResponse(*, jsonrpc: Literal['2.0'] = '2.0', id: str | int, result: Any = None)[source]¶
Bases:
_JsonRpcSuccessful reply to an IPCRequest.
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class mxcubecore.ipc.IPCServer(name: str)[source]¶
Bases:
HardwareObjectBeamline-configured IPC server. See IPC_FORMAT.md for the wire format and mxcubecore/ipc/whitelist.py for the whitelist rules.
- Parameters:
name (str)
- class HOConfig(*, transport: str = 'jsonrpc', host: str = '127.0.0.1', port: int = 9999, tls_cert_path: str | None = None, tls_key_path: str | None = None, broker_host: str = 'localhost', broker_port: int = 1883, topic_prefix: str = 'mxcube/ipc', tls_ca_cert_path: str | None = None, auth_token: str | None = None, allowed_methods: List[str] = [], events: List[Dict[str, Any]] = [], allow_debug_calls: bool = False, **extra_data: Any)[source]¶
Bases:
HOConfig- Parameters:
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'allow'}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- exception mxcubecore.ipc.IPCWhitelistError[source]¶
Bases:
ExceptionInvalid whitelist configuration or call to a non-whitelisted method.
- mxcubecore.ipc.build_whitelist(beamline: Any, allowed_methods: List[str]) Dict[str, WhitelistEntry][source]¶
Build the whitelist from the configured “role.method” entries.
- Raises:
IPCWhitelistError – when a role or method could not be resolved, or a method is not IPC-eligible.
- Parameters:
- Return type:
- mxcubecore.ipc.dispatch(beamline: Any, registry: Dict[str, WhitelistEntry], method_path: str, params: Dict[str, Any]) Any[source]¶
Validate params, call a whitelisted method and return a JSON-safe result.
- Raises:
IPCWhitelistError – when method_path is not whitelisted.
pydantic.ValidationError – when params don’t validate.
TypeError – when the method returns something other than its declared pydantic response model.
- Parameters:
- Return type:
- mxcubecore.ipc.ipc_method(request_model: Type[BaseModel] | None = None, response_model: Type[BaseModel] | None = None) Callable[[Callable], Callable][source]¶
Mark a method as IPC-eligible with explicit request/response models.
Only needed when the models can’t be inferred from the method signature.
Modules
Constants for the mxcubecore IPC layer: wire format version and error codes. |
|
Whitelist bypass for exploring and debugging - see IPC_FORMAT.md, "Debug bypass". |
|
Bridges HardwareObject signals (mxcubecore.dispatcher, used by HardwareObjectMixin.emit/.connect) into IPCEvent notifications pushed to the connected IPC client. |
|
The IPCServer's events: whitelist: which HardwareObject signals are forwarded as IPCEvents, and (optionally) the declared types of their positional arguments. |
|
Pydantic envelope models for the mxcubecore IPC wire format. |
|
IPCServer: a HardwareObject that exposes a whitelist of other HardwareObjects' methods to a single external client, over either a JSON-RPC/TCP or a NanoMQ (MQTT) transport. |
|
Whitelist of HardwareObject methods callable over IPC. |