QGIS & PyQGIS

Driving QGIS from Python: Processing algorithms, layouts, plugins and headless runs.

Four ways to run a QGIS algorithm, all resolving to the same call. the dialog and your script make the same callthe toolbox dialogthe model builderqgis_process, in a shellprocessing.run(), in codenative:buffer · {"INPUT": …, "DISTANCE": 25}There is no separate scripting API, which is why the History panel is the documentation

QGIS is a very large library of tested spatial algorithms that happens to ship with a user interface. Driving it from Python means using the same Processing framework the interface uses — there is no separate scripting API, which is why the History panel records the exact call the dialog made, and why a script and a manual run cannot silently diverge.

The difficulty is almost never the algorithms. It is the environment: which Python has the bindings, what the prefix path has to be, initialising Processing separately from the application, keeping a reference to a layer so C++ does not collect it mid-run, and exiting cleanly so a scheduled job actually finishes. None of those produce a Python traceback when they go wrong.

Below: the concepts cover the object model and the extension points; the how-to guides run algorithms, build models, style layers and export layouts; and the fixes are the import errors, the missing algorithms and the segmentation faults.

Learning paths run through this topic too — see the end of this page.

🧭 Start with the concepts

The ideas the how-to guides below assume you already have.

Show every concept in this topic

⚙️ Then do the task

Step-by-step walkthroughs with code you can copy and adapt.

Show every how-to guide in this topic

🔧 When it breaks

The errors this topic produces, with the cause explained rather than just the command.

Related topics

Subjects that keep coming up alongside this one, most overlap first.

Keep browsing

QGIS & PyQGIS sits in Tools. Every topic on the site is listed on the topics index.