Exploring a QGIS API in the Python Console

The QGIS APIs can be browsed in the documentation web page, but if you want to access the documentation directly in the Python Console, you can use some useful Python commands. The help command shows a synthesis of the API information available in the web documentation. Try to edit the Python Console with this command:

help(iface)

The console will show all the methods of the QgisInterface class and a synthetic example of how to use this in Python syntax instead of C++ syntax. For example, if you want to show the result type of the call iface.activeLayer type:

help(iface.activeLayer)

The following lines will be displayed:

Help on built-in function activeLayer: activeLayer(...) QgisInterface.activeLayer() ...

Get Mastering QGIS - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.