Access QGIS rendering map context within QGIS Python function
project = QgsProject.instance()
projectLayoutManager = project.layoutManager()
layout = projectLayoutManager.layoutByName("Name of your layout")
map = layout.itemById("map")
map.scale()
project = QgsProject.instance()
projectLayoutManager = project.layoutManager()
layout = projectLayoutManager.layoutByName("Name of your layout")
map = layout.itemById("map")
map.scale()