PEP561 type stubs for PyQGIS
Project description
Type Stubs for QGIS
This package defines Python stub files (.pyi) for the PyQGIS wrapper module available in QGIS.
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.3d
namespace is not valid Python syntax as it starts with a number. At runtime, this module is instead available under theqgis._3d
name, 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: ignore
and/or# pylint: disable=protected-access
comments. -
Some classes use
None
as 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.
-
This module uses
PyQt5-stubs
for its Qt types, which does not support thePyQt5.Qsci
submodule. As a result, any classes derived from theQsci
namespace are typed asAny
and not checked.
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file qgis-stubs-0.2.0.post1.tar.gz
.
File metadata
- Download URL: qgis-stubs-0.2.0.post1.tar.gz
- Upload date:
- Size: 324.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96b9e6cb2deda1ad327b81334515ef9d88f9e92344cbf179de554be7b62154c8 |
|
MD5 | 946fbf7f13d1966bb90ad4f536711095 |
|
BLAKE2b-256 | 1b3869088df2e0679a6af90102193b350512646716c54b341a0169ee93194ae5 |
File details
Details for the file qgis_stubs-0.2.0.post1-py3-none-any.whl
.
File metadata
- Download URL: qgis_stubs-0.2.0.post1-py3-none-any.whl
- Upload date:
- Size: 330.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77e258342eec6ed6d8088701d490d951be83680a99733fa27a50959a88bedfce |
|
MD5 | e547699a8db58edfee9ccb5f5c3d15ea |
|
BLAKE2b-256 | c297e0ab7241e2b9f35e03d288f2bb1304c1a1d47219601d0df971a851f9db38 |