We can easily add the map from map canvas to print composer but is there any possible way to add vector layer directly to the print composer in QGIS either by PyQGIS script or by using some plugin or by any default feature.
I was working on something similar last night, like Stew says if you use QgsVectorLayer rather than iface, and set the last parameter to 'False' you can add 'hidden' layers i.e. they don't appear in the TOC or mapcanvas - but they're there :
layer = QgsVectorLayer(shapepath, lyr_name, "ogr") QgsProject.instance().addMapLayer(layer, False) # if set to true it'll appear on the mapcanvas
After if you want to check they exist:
lyr_list = QgsProject.instance().mapLayers() print(lyr_list)
But that only solves half your question... In map composer you can add these layers to your legend (simply by turning off the auto-update and manually adding a layer) - however I don't think that you can add a layer to the layout-map that isn't visible on the map canvas...