Skip to main content

PEP561 type stubs for PyQGIS.

Project description

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.3d namespace is not valid Python syntax as it starts with a number. At runtime, this module is instead available under the qgis._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 as DataResamplingMethod.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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qgis_stubs-0.4.0.dev1.tar.gz (742.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qgis_stubs-0.4.0.dev1-py3-none-any.whl (762.8 kB view details)

Uploaded Python 3

File details

Details for the file qgis_stubs-0.4.0.dev1.tar.gz.

File metadata

  • Download URL: qgis_stubs-0.4.0.dev1.tar.gz
  • Upload date:
  • Size: 742.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qgis_stubs-0.4.0.dev1.tar.gz
Algorithm Hash digest
SHA256 915c9041ddc12b76555ce11c197a725d46493758b5e51c0f0fc0d0fb9afc3949
MD5 fa745a6ff2e8a7a96ba4a2cd6926f608
BLAKE2b-256 c9936d309f630ebbb0d44c5bac29c28a054d0010cc8fdd9c409bae4d3dbc3cf0

See more details on using hashes here.

Provenance

The following attestation bundles were made for qgis_stubs-0.4.0.dev1.tar.gz:

Publisher: publish-pypi.yml on leonhard-s/qgis-stubs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qgis_stubs-0.4.0.dev1-py3-none-any.whl.

File metadata

  • Download URL: qgis_stubs-0.4.0.dev1-py3-none-any.whl
  • Upload date:
  • Size: 762.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qgis_stubs-0.4.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 744a6ba7cd944033c63f0d9f93702ebad73528869ac8672d9e90f38eabb6eeb1
MD5 2f180d1ac2b791f9fd7fe529a2998ae3
BLAKE2b-256 51dfbb10585b08da7a8f9276f30aa7e70efdcea689ff0c41a88d5ec491a9e03e

See more details on using hashes here.

Provenance

The following attestation bundles were made for qgis_stubs-0.4.0.dev1-py3-none-any.whl:

Publisher: publish-pypi.yml on leonhard-s/qgis-stubs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page