code: def _to_svg(spec, path) -> Union[str, None]:
      from .. import _kbridge as kbr
  
      svg = kbr._generate_svg(spec.as_dict())
      if isinstance(path, str):
          abspath = _makedirs(path)
          with io.open(abspath, mode="w", encoding="utf-8") as f:
              f.write(svg)
              return abspath
      else:
          path.write(svg.encode())
          return None
  
imports: import io
  import json
  import os
  from typing import Union
  from lets_plot._global_settings import get_global_bool, has_global_value, FRAGMENTS_ENABLED
label_desc: Use image node_id 7 for calling a global function with example usage: _to_svg(spec, path) and returns: None, abspath