Type Stubs for QGIS
Python stubs for the PyQGIS module used in QGIS. Compatible with and tested on Pylance/pyright and MyPy.
Overview
The bulk of the qgis module is a SIP-generated wrapper over a C++ source that is only available at runtime. This means that developers are "flying blind" when writing code that uses the qgis module.
Type stubs are a declaration-only replication of the module interface that can be parsed by IDEs, linters, or static type checkers like Mypy or Pylance to provide the same functionality available for regular Python sources.
Installation
The qgis-stubs package can be installed through pip:
python -m pip install qgis-stubs
Alternatively, you may clone and install the latest version using the repository link:
python -m pip install git+https://github.com/leonhard-s/qgis-stubs.git
Caveats & Limitations
The Python modules used by QGIS are not without issues. Most of these are shared by the runtime implementation but are explicitly listed here to avoid confusion.
-
The
qgis.3dnamespace is not valid Python syntax as it starts with a number. At runtime, this module is instead available under theqgis._3dname, and the stub files replicate this behaviour.This may lead to errors/warnings due to apparent protected access of client code, which must be silenced using
# type: ignoreand/or# pylint: disable=protected-accesscomments. -
Some classes use
Noneas the name of a member, leading to invalid Python syntax such asDataResamplingMethod.None.Use of the built-in
getattr()function together with custom type annotations can be used to work around this issue:None_: DataResamplingMethod = getattr(DataResamplingMethod, 'None')
-
Compatibility fallback names for unscoped enumerators are not available as they are "monkey-patched" at runtime.
It was decided not to include these patches in the stubs as they lead to naming collisions and are almost all flagged as deprecated for QGIS 4.
Contributing
This repository contains an automated type stub generator, but new releases still require some manual edits depending on the version of QGIS targeted. Support for new QGIS versions is therefore not automatic.
If you encounter any issues such as missing or incorrect type hints or wish for this utility to be updated for a new version of QGIS, please do create an issue.
Metadata
Release files for qgis-stubs 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| qgis_stubs-0.5.0.tar.gz | 721.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| qgis_stubs-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.5 MB
Release files / qgis_stubs-0.5.0.tar.gz
| Download URL | qgis_stubs-0.5.0.tar.gz |
|---|---|
| Size | 721.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cd4bcaf060289d0c9fd4388201f943a3ac4ed3c3678374a8fff9f2beb0df85f0
|
|
BLAKE2b-256 checksum How to use checksums |
0a4d23fcea719a8a9e039602face6527786e7c168d877af9082cad1c97743fff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.
Transparency logRelease files / qgis_stubs-0.5.0-py3-none-any.whl
| Download URL | qgis_stubs-0.5.0-py3-none-any.whl |
|---|---|
| Size | 741.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aeb82df44ecc1a296fc52b8d258221810e32075b1da2ff427dbd20141c4c6500
|
|
BLAKE2b-256 checksum How to use checksums |
baa904f35f1261579994bb1e8c53a3f8762e7cfe36eac0da3e9ff1a27b24a6dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.
Transparency log