Skip to content
ocx
install

HostEnv

HostEnvclassdataclass#

Re-exported from ocx_sdk._typesView source
class HostEnv(source: Mapping[str, str])

A snapshot of the environment a spawned ocx inherits.

The mapping is copied and made read-only at construction, so neither a later mutation of the source dict nor a write through .source can rewrite a snapshot that was already taken. (A read-only snapshot is not picklable — an implementation detail, not a contract.)

repr lists key names only. An ambient snapshot holds OCX_AUTH_* values, and a repr is exactly what a traceback or a pytest diff prints.

sourceattributeinstance attribute#

source: Mapping[str, str]

ambientmethodclassmethod#

def ambient() -> HostEnv

Return a snapshot of the current os.environ.

cleanmethodclassmethod#

def clean() -> HostEnv

Return an empty environment.

Hermetic, and a documented footgun: spawned tools lose PATH and fail in ways that read like anything but a missing variable. minimal() is the recovery.

minimalmethodclassmethod#

def minimal(windows: bool | None = None) -> HostEnv

Return only the platform-essential variables from the ambient env.

PATH, HOME, and TMPDIR everywhere; SYSTEMROOT and TEMP on Windows. Variables that are not set are simply absent.

Parameters

NameTypeDefaultDescription
windowsbool | NoneNoneForce the platform branch. Defaults to detecting the host; tests pass it explicitly so both branches run anywhere.

onlymethod#

def only(*keys: str) -> HostEnv

Return a snapshot narrowed to keys that are actually set.

withoutmethod#

def without(*keys: str) -> HostEnv

Return a snapshot with keys removed.