Skip to content

session

Classes

SexpWrapper dataclass

Lightweight handle for an R object stored in the worker.

The worker keeps the real rpy2 Sexp in an internal cache and replaces it in results with this wrapper. When passed back to the worker, the wrapper is resolved to the original Sexp again.

Notes
  • SexpWrapper instances are only meaningful within the lifetime of the worker process that produced them. After a worker restart, previously returned wrappers can no longer be reattached.
  • This type exists to keep the main process free of rpy2 / embedded-R state.

PayloadRef

Bases: TypedDict

Encoded argument/result payload sent over the control pipe.

A payload is:

  • codec: the codec identifier used by the registry
  • meta: JSON-serializable metadata needed to reconstruct the value
  • buffers: shared-memory buffer references backing the payload

Request

Bases: TypedDict

IPC request message sent from main process to worker.

Attributes:

Name Type Description
id str

Correlation id for the request/response pair.

cmd {'CALL', 'SHUTDOWN', 'PING', '_RUN_TEST_BY_NAME'}

Command type.

target str

Worker target spec (see _resolve_module_target()).

args, kwargs

Encoded arguments.

Response

Bases: TypedDict

IPC response message sent from worker back to the main process.

EnvironmentConfig dataclass

Worker environment configuration.

This configuration is applied in the worker before importing/using brms.

Parameters:

Name Type Description Default
r_home str or None

Override for R_HOME. If None, the worker will rely on system detection.

None
startup_scripts list[str]

R code snippets executed in the worker after initialization.

list()
environment_name str

brmspy environment name (used to determine ~/.brmspy/environment/<name>/Rlib).

'default'
runtime_path str or None

Path to a brmspy runtime bundle to activate in the worker.

None
env dict[str, str]

Extra environment variables applied when spawning the worker.

dict()

Functions

to_dict()

Serialize configuration for persistence to JSON.

from_dict(obj) classmethod

Deserialize configuration from a JSON object.

from_obj(obj) classmethod

Normalize None | dict | EnvironmentConfig into an EnvironmentConfig.

EncodeResult dataclass

Result of encoding a Python value for IPC transfer.

Attributes:

Name Type Description
codec str

Codec identifier.

meta dict[str, Any]

JSON-serializable metadata required for decoding.

buffers list[ShmRef]

Shared-memory blocks backing the encoded payload.

Encoder

Bases: Protocol

Protocol implemented by codecs in the session codec registry.