code: def rename_fields(layer, fields_to_copy):
      
      for field in fields_to_copy:
          index = layer.fields().lookupField(field)
          if index != -1:
              layer.startEditing()
              layer.renameAttribute(index, fields_to_copy[field])
              layer.commitChanges()
              LOGGER.info(
                  'Renaming field %s to %s' % (field, fields_to_copy[field]))
          else:
              LOGGER.info(
                  'Field %s not present in the layer while trying to renaming '
                  'it to %s' % (field, fields_to_copy[field]))
docs: Rename fields inside an attribute table.
  
      Only since QGIS 2.16.
  
      :param layer: The vector layer.
      :type layer: QgsVectorLayer
  
      :param fields_to_copy: Dictionary of fields to copy.
      :type fields_to_copy: dict