I would like to rewrite some of my QGIS plugins to use more common functions used by all of my plugins.

There exist some older functions (GIS2) like



and something newer like

https://github.com/boundlessgeo/lib-qgis-commons https://pypi.org/project/qgiscommons/ or https://github.com/inasafe/inasafe/tree/master/safe/utilities

Are there any other known collections of PyQGIS3 common functions that can be used to do basic tasks like load vectorlayers, show comboboxes, create toolbar-actions or something like that without having to write these code-snippets everytime on your own?


If I want to lad a vectorlayer I can make use of the function load_layer from https://github.com/qgis/pyqgis_wrappers/blob/master/parfait/layer_wrappers.py

 def load_layer(filename, name = None):
    Tries to load a layer from the given file
    :param filename: the path to the file to load.
    :param name: the name to use for adding the layer to the current project.
    If not passed or None, it will use the filename basename
    name = name or os.path.splitext(os.path.basename(filename))[0]
    qgslayer = QgsVectorLayer(filename, name, 'ogr')
    if not qgslayer.isValid():
        qgslayer = QgsRasterLayer(filename, name)
        if not qgslayer.isValid():
            raise RuntimeError('Could not load layer: ' + unicode(filename))

return qgslayer
  • 1
    This is a very open ended question. I think there's a better chance to get an answer on the QGIS developer mailing list - if anything like that exists for QGIS3
    – underdark
    Commented Feb 15, 2019 at 18:37

1 Answer 1


Great initiative!

As a brand-new PyQGIS user, I don't have (and don't know of) appropriately packaged collections. However, a number of "cookbooks" have code snippets that would be easy to package/fill in the gaps, perhaps:

  1. https://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/index.html (still 2.18, but hopefully updated soon to reflect 3.6 LTR?)

  2. https://pcjericks.github.io/py-gdalogr-cookbook/index.html

  3. http://www.green-forums.info/greenlib/geolibrary/Lawhead%20J/QGIS%20Python%20Programming%20Cookbook.%2020%20%2852%29/QGIS%20Python%20Programming%20Cookboo%20-%20Lawhead%20J.pdf (a commercial 2015 book, but seems to have been released for download)

  • The linked PyQGIS Developer Cookbook is already for QGIS 3 - and not for 2.18 as stated!
    – geraldo
    Commented Feb 20, 2019 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.