code: def write_keywords(layer, keywords):
          
          if not isinstance(layer, QgsMapLayer):
              raise Exception(
                  tr('The layer is not a QgsMapLayer : {type}').format(
                      type=type(layer)))
  
          source = layer.source()
          write_iso19115_metadata(source, keywords)
docs: Write keywords for a datasource.
  
          This is a wrapper method that will 'do the right thing' to store
          keywords for the given datasource. In particular, if the datasource
          is remote (e.g. a database connection) it will write the keywords from
          the keywords store.
  
          :param layer: A QGIS QgsMapLayer instance.
          :type layer: qgis.core.QgsMapLayer
  
          :param keywords: A dict containing all the keywords to be written
                for the layer.
          :type keywords: dict
  
          :raises: UnsupportedProviderError