According to the latest official QGIS 3.X API reference there is a class that should insert attribute table of a layer. I tried to do it, but got an error.
Here is a piece of code I used:
from PyQt5.QtCore import * from PyQt5.QtGui import * from qgis.core import * from qgis.gui import * project = QgsProject.instance() manager = project.layoutManager() layout = QgsPrintLayout(project) layout.initializeDefaults() layout.setName('console') manager.addLayout(layout) itemMap = QgsLayoutItemMap.create(layout) tbl = QgsLayoutItemAttributeTable.create(layout) layer_attr = QgsProject.instance().mapLayersByName(u'buildings') tbl.setVectorLayer(layer_attr) layout.addLayoutItem(tbl)
And after the last line I get an error
TypeError: QgsLayout.addLayoutItem(): argument 1 has unexpected type 'QgsLayoutItemAttributeTable'
Can't understand why it is happening because QgsLayoutItemAttributeTable logically should be supported by layout methods. Main things in my code were taken from this question.