code: def remove_provenance_project_variables():
      
      project_context_scope = QgsExpressionContextUtils.projectScope(
          QgsProject.instance())
      existing_variable_names = project_context_scope.variableNames()
  
      # Save the existing variables that's not provenance variable.
      existing_variables = {}
      for existing_variable_name in existing_variable_names:
          existing_variables[existing_variable_name] = \
              project_context_scope.variable(existing_variable_name)
      for the_provenance in provenance_list:
          if the_provenance['provenance_key'] in existing_variables:
              existing_variables.pop(the_provenance['provenance_key'])
  
      # Removing generated key from dictionary (e.g.
      # action_checklist__0__item_list__0)
      will_be_removed = []
      for existing_variable in existing_variables:
          for the_provenance in provenance_list:
              if existing_variable.startswith(
                      the_provenance['provenance_key']):
                  will_be_removed.append(existing_variable)
                  continue
      for variable in will_be_removed:
          existing_variables.pop(variable)
  
      # Need to change to None, to be able to store it back.
      non_null_existing_variables = {}
      for k, v in list(existing_variables.items()):
          if v is None or (hasattr(v, 'isNull') and v.isNull()):
              non_null_existing_variables[k] = None
          else:
              non_null_existing_variables[k] = v
  
      # This method will set non_null_existing_variables, and remove the
      # other variable
      QgsExpressionContextUtils.setProjectVariables(
          QgsProject.instance(),
          non_null_existing_variables)
docs: Removing variables from provenance data.