def serialize(self, *, fmt: str = 'nodelink', file: Union[None, str, TextIO] = None, **kwargs):
        """Serialize the graph to an object or file if given.

        For additional I/O, see the :mod:`pybel.io` module.
        """
        if file is None:
            return self._serialize_object(fmt=fmt, **kwargs)
        elif isinstance(file, str):
            with open(file, 'w') as file_obj:
                self._serialize_file(fmt=fmt, file=file_obj, **kwargs)
        else:
            self._serialize_file(fmt=fmt, file=file, **kwargs)
Serialize the graph to an object or file if given.

        For additional I/O, see the :mod:`pybel.io` module.