code: def add_osm_layer(self):
          
          path = resources_path('osm', 'WorldOSM.gdal')
          layer = QgsRasterLayer(path, self.tr('OpenStreetMap'))
          project = QgsProject.instance()
  
          # Try to add it as the last layer in the list
          # False flag prevents layer being added to legend
          project.addMapLayer(layer, False)
          root = QgsProject.instance().layerTreeRoot()
          index = len(root.findLayers()) + 1
          # LOGGER.info('Inserting layer %s at position %s' % (
          #    layer.source(), index))
          root.insertLayer(index, layer)
          project.addMapLayer(layer)
docs: Add OSM tile layer to the map.
  
          This uses a gdal wrapper around the OSM tile service - see the
          WorldOSM.gdal file for how it is constructed.