from qgis.core import QgsApplication # Initialize QGIS app = QgsApplication([], True) app.initQgis() # Work with QGIS here... # Exit QGIS QgsApplication.exitQgis()In this example, we import the QgsApplication class from the qgis.core package and create an instance of the class. We then use the `initQgis` method to initialize QGIS and the `exitQgis` method to exit QGIS when we are done. Package library: qgis.core.