Another option is to use the [`materialize()`](https://qgis.org/pyqgis/master/core/QgsFeatureSource.html#qgis.core.QgsFeatureSource.materialize) method. <!-- language: python --> from qgis import processing layer = QgsProject.instance().mapLayersByName('Langham_SPZs_v1_diss')[0] outfn2 = "Langham_SPZs_final.shp" layer.selectByExpression("number='2'") layer2 = layer.materialize(QgsFeatureRequest().setFilterFids(layer.selectedFeatureIds())) layer.selectByExpression("number='3'") layer3 = layer.materialize(QgsFeatureRequest().setFilterFids(layer.selectedFeatureIds())) processing.run("native:difference", {'INPUT' : layer3, 'OVERLAY' : layer2, 'OUTPUT': outfn2}) *Note:* this method is available since QGIS 3.0. ---------- **References:** - [PyQGIS Developer Cookbook | 21. Cheat sheet for PyQGIS](https://docs.qgis.org/3.22/en/docs/pyqgis_developer_cookbook/cheat_sheet.html#layers)