Stack Exchange network consists of 178 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
How do I get the layer by name using PyQGIS 3?
If you are sure there is one layer named LAYER_NAME, the shortest way:
layer = QgsProject.instance().mapLayersByName('LAYER_NAME')
In that way, you can get a layer in a group layer.
# OUT: <qgis._core.QgsVectorLayer object at ...>
Retrieve a list of matching registered layers by layer name.