Skip to content

Instantly share code, notes, and snippets.

@ivanlonel
Created June 8, 2024 00:33
Show Gist options
  • Save ivanlonel/90591aee96777feb3ff0051d549df116 to your computer and use it in GitHub Desktop.
Save ivanlonel/90591aee96777feb3ff0051d549df116 to your computer and use it in GitHub Desktop.
How to run Processing algorithms in standalone PyQGIS applications
import sys
from pathlib import Path
from qgis.core import QgsApplication
from qgis.core.contextmanagers import qgisapp
with qgisapp(guienabled=False, sysexit=False):
# Required before importing processing:
sys.path.append(str(Path(QgsApplication.prefixPath()) / "python/plugins"))
import processing
from processing.core.Processing import Processing
Processing.initialize()
result = processing.run(
"native:stringconcatenation", {"INPUT_1": "Hello ", "INPUT_2": "world!"}
)
print(result["CONCATENATION"])
print("Execution only reaches this line because we passed sysexit=False above.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment