I need a list containing all the vector layers in a QGIS session. I have this code to get all layers, how can I put a filter to get only vector layers?

layers = QgsProject.instance().mapLayers().values()

1 Answer 1


Use a list comprehension and filter only vector layers:

layers = [l for l in QgsProject.instance().mapLayers().values() if l.type() == QgsVectorLayer.VectorLayer]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.