What are some resources for learning PyQGIS?

It would be interesting having a collection of books or websites that provide some practical examples for learning the syntax or accomplishing specific tasks.

Ideally, these resources should give a general guidance for both beginner and experienced users.

Seeking QGIS user interface tutorials and web resources is a very similar question, but it gives help for learning the QGIS user interface rather than PyQGIS.


1 Answer 1


This question has been converted to Community Wiki and wiki locked because it is an example of a question that seeks a list of answers and appears to be popular enough to protect it from closure. It should be treated as a special case and should not be viewed as the type of question that is encouraged on this, or any Stack Exchange site, but if you wish to contribute more content to it then feel free to do so by editing this answer.

The following resources give a general guidance for learning or using PyQGIS and generally assume a minimum proficiency of working with Python.

QGIS 3.x versions

  • PyQGIS 3 API Documentation: official documentation of the Python API. Documentation for each major release since v3.0 as well as the nightly version is provided;

  • PyQGIS Developer Cookbook: written for QGIS 2.x it is gradually updated to 3.x. It still may be helpful as a tutorial and a reference guide and gives a good overview of the principal functionalities.

QGIS 2.x versions

PyQGIS Documentation:

  • PyQGIS Developer Cookbook: official introduction to PyQGIS programming. It is intended to work both as a tutorial and a reference guide and gives a good overview of the principal functionalities;

  • PyQGIS API Documentation: inofficial documentation of the Python API by SourcePole. It provides a searchable interface, but was not updated since QGIS 2.8;

  • QGIS C++ API Documentation: official C++ API documentation. While describing the C++ API, it can be useful for pyqgis development.

Online books:

Tutorials / Blogs / Web resources:

  • [Anita Graser]: PyQGIS 101: Introduction to QGIS Python programming for non-programmers (tutorial for beginners)

  • Nathan Woodrow: a blog mostly about QGIS stuff that also treats specific topics about the using of PyQGIS. The author is one of the most active QGIS developers;

  • nyalldawson.net: a blog with several posts about the using of PyQGIS. The author is one of the most active QGIS developers;

  • "How To" in QGIS: the site provides some suggestions for solving problems using PyQGIS. When possible, these tips are offered through simple code samples. I'm the author of this blog;

  • QGIS Tutorials and Tips: a section of this blog provides a series of tutorials for learning PyQGIS scripting. The author is a very experienced GIS specialist;

  • Lutra Consulting: a list of posts, having the PyQGIS tag, that cover some topics about PyQGIS.

  • YouTube channel PyQGIS (dozens of videotutorials about using Python with QGIS - in german only, but the principles should become clear);

The following documentation resources should ease your PyQGIS development experience:

A diagram of the main PyQGIS relationships (by Thomas Gratier): https://raw.githubusercontent.com/webgeodatavore/qgis-class-diagram/master/diagramme_principal.png

Searchable documentation of PyQGIS classes (by SourcePole): http://geoapis.sourcepole.com

For example, the addFeature method you had problems with is described here: http://geoapis.sourcepole.com/qgispyapi/qgsvectorlayer#QgsVectorLayer.addFeature

enter image description here

As a second example, the setAttribute method is described here: http://geoapis.sourcepole.com/qgispyapi/qgsfeature#QgsFeature.setAttribute

enter image description here

Not sure what you mean in Getting into Python API of QGIS?, but there is an addFeatures() function of course. This works in QGIS 2.4:

mem_layer = QgsVectorLayer("Polygon?crs=epsg:4326&field=MYNUM:integer&field=MYTXT:string", "temp_layer", "memory")

if not mem_layer.isValid(): raise Exception("Failed to create memory layer")

mem_layer_provider = mem_layer.dataProvider()

my_polygon = QgsFeature()
my_polygon.setAttributes([10,"hello world"])



If you are unhappy with the API docs and the PyQGIS Cookbook, your last chance is to look into working plugins - they are open source after all - and you can easily see if they work in 2.4 ...

To improve documentation, the project happily accepts resources of any kind.

Another collection for informations about learning PyQGIS:

Here are some urls that might help you:

  1. PyQGIS Developer Cookbook https://docs.qgis.org/3.10/en/docs/pyqgis_developer_cookbook/
  2. QGIS Python API documentation https://qgis.org/pyqgis/3.14/

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