class PyOpenColorIO.Context


A context defines some overrides to a Config. For example, it can override the search path or change the value of a context variable.


Only some Config::getProcessor methods accept a custom context; otherwise, the default context instance is used (see Config::getCurrentContext).

Context Variables

The context variables allow changes at runtime using environment variables. For example, a color space name (such as src & dst for the ColorSpaceTransform) or a file name (such as LUT file name for the FileTransform) could be defined by context variables. The color transformation is then customized based on some environment variables.

In a config the context variables support three syntaxes (i.e. ${VAR}, $VAR and VAR%) and the parsing starts from longest to shortest. So, the resolve works like ‘$TEST_$TESTING_$TE’ expands in this order ‘2 1 3’.

Config authors are recommended to include the “environment” section in their configs. This improves performance as well as making the config more readable. When present, this section must declare all context variables used in the config. It may also provide a default value, in case the variable is not present in the user’s environment.

A context variable may only be used in the following places: - the :ref:`ColorSpaceTransform` to define the source and the destination color space names, - the :ref:`FileTransform` to define the source file name (e.g. a LUT file name), - the search_path, - the cccid of the :ref:`FileTransform` to only extract one specific transform from the CDL & CCC files.

Some specific restrictions are worth calling out: - they cannot be used as either the name or value of a role, - the context variable characters $ and % are prohibited in a color space name.

Context(*args, **kwargs)

Overloaded function.

  1. __init__(self: PyOpenColorIO.Context) -> None

  2. __init__(self: PyOpenColorIO.Context, workingDir: str = ‘’, searchPaths: List[str] = [], stringVars: Dict[str, str] = {}, environmentMode: PyOpenColorIO.EnvironmentMode = <EnvironmentMode.ENV_ENVIRONMENT_LOAD_PREDEFINED: 1>) -> None

addSearchPath(path: str)None

Seed all string vars with the current environment.

resolveFileLocation(*args, **kwargs)

Overloaded function.

  1. resolveFileLocation(self: PyOpenColorIO.Context, filename: str) -> str

Build the resolved and expanded filepath using the search_path when needed, and check if the filepath exists. If it cannot be resolved or found, an exception will be thrown. The method argument is directly from the config file so it can be an absolute or relative file path or a file name.


The filepath existence check could add a performance hit.


The context variable resolution is performed using resolveStringVar().

  1. resolveFileLocation(self: PyOpenColorIO.Context, filename: str, usedContextVars: PyOpenColorIO.Context) -> str

Build the resolved and expanded filepath and return all the context variables used to resolve the filename (empty if no context variables were used).

resolveStringVar(*args, **kwargs)

Overloaded function.

  1. resolveStringVar(self: PyOpenColorIO.Context, string: str) -> str

Resolve all the context variables from the string. It could be color space names or file names. Note that it recursively applies the context variable resolution. Returns the string unchanged if it does not contain any context variable.

  1. resolveStringVar(self: PyOpenColorIO.Context, string: str, usedContextVars: PyOpenColorIO.Context) -> str

Resolve all the context variables from the string and return all the context variables used to resolve the string (empty if no context variables were used).

setEnvironmentMode(mode: PyOpenColorIO.EnvironmentMode)None
setSearchPath(path: str)None
setWorkingDir(dirName: str)None
class PyOpenColorIO.Context.StringVarNameIterator
self[arg0: int]str
class PyOpenColorIO.Context.StringVarIterator
self[arg0: int]tuple
class PyOpenColorIO.Context.SearchPathIterator
self[arg0: int]str