Skip to main content

Flake8 plugin for QGIS python plugins.

Project description


PyPI version Downloads CI Code on Github Code style: black Imports: isort pre-commit

A flake8 plugin for QGIS3 python plugins written in Python.

Made with Cookiecutter template cookiecutter-flake8-plugin. Inspired by flake8-simplify.


Install with pip:

pip install flake8-qgis


Just call flake8 . in your package or flake


  • QGS101: Don't use from-imports from qgis protected members (example)
  • QGS102: Don't use imports from qgis protected members (example)
  • QGS103: Don't use from-imports from PyQt directly (example)
  • QGS104: Don't use imports from PyQt directly (example)
  • QGS105: Don't pass QgisInterface as an argument (example)
  • QGS106: Don't import gdal directly, import if from osgeo package (example)

You might have good reasons to ignore some rules. To do that, use the standard Flake8 configuration. For example, within the setup.cfg file:

ignore = QGS101, QGS102



# Bad
from qgs._core import QgsMapLayer, QgsVectorLayer
from qgis._core import QgsApplication

# Good
from qgs.core import QgsMapLayer, QgsVectorLayer
from qgis.core import QgsApplication


# Bad
import qgs._core.QgsVectorLayer as QgsVectorLayer

# Good
import qgs.core.QgsVectorLayer as QgsVectorLayer


# Bad
from PyQt5.QtCore import pyqtSignal

# Good
from qgis.PyQt.QtCore import pyqtSignal


# Bad
import PyQt5.QtCore.pyqtSignal as pyqtSignal

# Good
import qgis.PyQt.QtCore.pyqtSignal as pyqtSignal


# Bad: iface passed as argument
def some_function(somearg, iface):
    # do something with iface

# Good: iface imported
from qgis.utils import iface

def some_function(somearg):
    # do something with iface
# in classFactory the passing is OK, since QGIS injects it
def classFactory(iface):
    # preferably do not pass the iface to plugin


# Bad
import gdal
import ogr

# Good
from osgeo import gdal

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

flake8_qgis-1.0.0.tar.gz (10.6 kB view hashes)

Uploaded source

Built Distribution

flake8_qgis-1.0.0-py3-none-any.whl (5.8 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page