Package: py-qgis-wps
Py-QGIS-WPSNew in 1.8: OGC apiprocessessupportPy-QGIS-WPS is an implementation of theWeb Processing Servicestandard from the Open Geospatial Consortium based on the QGIS Processing API.Since 1.8 Py-QGIS-WPS supportsOGC API REST processes apiThis implementation allows you to expose and run on a server:QGIS Processing algorithms available on DesktopQGIS Processing models and scriptsQGIS plugins having a Processing provider according to theirmetadata.txtfileIt is written in Python and was originally a fork ofPyWPS.Requirements and limitations :Python 3.7 minimumWindows not officially supportedRedis serverDocumentationLatest documentation is available ondocs.3liz.orgWhy Py-QGIS-WPS ?Py-QGIS-WPS differs fromPyWPSin the following:QGIS centricHandle all request in asynchronous way: all jobs run in a non-blocking way, even
when synchronous operation is requested.Use multiprocessing Pool to handle task queue instead instantiating a new process each time.Uniform Logging with the 'logging' moduleImplements OGCprocessesapi.Use Redis for asynchronous status storage.Support streamed/chunked requests for stored dataAdd extensions to WPS: TIMEOUT and EXPIRENo Windows supportAll these changes where not easy to implement without some drastic changes of the original code and we think
that it  deviates too much from the PyWPS original intentions.That is, we have decided to fork the original project and go along with it.So, we are really grateful to the original authors of PyWPS for the nice piece of software that helped us very much
to start quickly this project.Why moving to Tornado instead WSGIWe need to support asyncio: asyncio requires a blocking running loop. This cannot be achieved simply in a WSGI architecture.Tornado is fully integrated with native pythonasynciolibrary and provide a great framework for developing a http server.Extensions to WPSTIMEOUT extensionSpecify the timeout for a process: if the process takes more than TIMEOUT seconds to run, the worker is then killed and an
error status is returned.Set theTIMEOUT=<seconds>in  GET requests.In POST requests, set thetimeout=<seconds>attribut in the<ResponseDocument>tag.The server may configure maximum timeout value.EXPIRE extensionSpecify the expiration time for stored results: after EXPIRE seconds after the end of the wps process, all results will be
flushed from disks and local cache. Trying to request the results again will return a 404 HTTP  error.Set theEXPIRE=<seconds>in  GET requests.In POST requests, set theexpire=<seconds>attribut int the<ResponseDocument>tag.The server may configure maximum expiration value.Status APINow implemented with the processes api:
The status REST api will return the list of the stored status for all running and terminated wps processes.Example for returning all stored status:http://localhost:8080/jobsExample for returning status for one given job from its id:http://localhost:8080/jobs/<job_id>Extensions toprocessesapi:Fileshttp://localhost:8080/jobs/<job_id>/filesRunning QGIS processingWPS input/output layer mappingWith QGIS desktop, QGIS processing algorithms usually apply on a QGIS source project and computed layers are displayed in the same context as the source project.Py-qgis-wps works the same way: a qgis project will be used as a source of input layers.
The difference is that, when an algorithm runs, it creates a qgis project file associated to the current task and register computed layers to it.The created project may be used as OWS source with Qgis Server. Output layers are returned as complex objects
holding a reference to a WMS/WFS uri that can be used directly with Qgis server. The uri template is configurable
using theserver/wms_response_uriconfiguration setting.Contextualized input parametersTasks parameters are contextualized using theMAPquery param. If aMAPparameters is given when
doing aDescripProcessrequests, allowed values for input layers will be taken from the qgis source project
according the type of the input layers.QGIS project (.qgs) files and project stored in Postgres databases are both supported.The best practice is to always provide aMAPparameters and include the possible input layer in a qgs project. This way you
may connect whatever data source supported by qgis and use them as input data in a safe way.If you need to pass data to your algorithm from client-side, prefer inputs file parameter and small payloads.DependenciesSeerequirements.txtfile.Installation from python packageADVICE: You should always install in a python virtualenv. If you want to use system packages, setup your environment
with the--system-site-packagesoption.See the official documentation for how to setup a python virtualenv:https://virtualenv.pypa.io/en/stable/.From sourceInstall in development modemakebuild
pipinstall-e.From python package serverpipinstallpy-qgis-wpsRunning the serverThe server from a command line interface:The server does not run as a daemon by itself, there are several ways to run a command as a daemon.For example:Use Supervisorhttp://supervisord.org/will give you full control over logs and server status notifications.Use thedaemoncommand.Use DockerRunning the serverUsageusage: wpsserver [-h] [-d] [-c [PATH]]
                 [--version] [-p PORT] [-b IP] [-u SETUID]

WPS server

optional arguments:
  -h, --help            show this help message and exit
  -d, --debug           Set debug mode  
  -c [PATH], --config [PATH]
                        Configuration file
  --version             Return version number and exit
  -p PORT, --port PORT  http port
  -b IP, --bind IP      Interface to bind to
  -u SETUID, --setuid SETUID
                        uid to switch toRequests to OWS servicesThe OWS requests use the following format:/ows/?<ows_query_params>Example:http://myserver:8080/ows/?SERVICE=WPS&VERSION=1.0.0&REQUEST=GetCapabilitiesConfigurationFrom config ini fileBy default, the wps server is not using any config file, but one can be used with the--configoption.
A config file is a simple ini file, a sample config file is given with the sources.From environment variablesThe server can be configured with environnement variables:Configuration is done with environment variables:QGSWPS_SERVER_WORKDIR: set the current dir processes, all processes will be running in that directory.QGSWPS_SERVER_HOST_PROXY: When the service is behind a reverse proxy, set this to the proxy entrypoint.QGSWPS_SERVER_PARALLELPROCESSES: Number of parallel process workersQGSWPS_SERVER_RESPONSE_TIMEOUT: The max response time before killing a process.QGSWPS_SERVER_RESPONSE_EXPIRATION: The max time (in seconds) the response from a WPS process will be available.QGSWPS_SERVER_WMS_SERVICE_URL: The base url for WMS service. Default to /wms. Responses from processing will
be retourned as WMS urls. This configuration variable set the base url for accessing results.QGSWPS_SERVER_RESULTS_MAP_URILoggingQGSWPS_LOGLEVEL: the log level, should beINFOin production mode,DEBUGfor debug output.REDIS storage configurationQGSWPS_REDIS_HOST: The redis hostQGSWPS_REDIS_PORT: The redis port. Default to 6379QGSWPS_REDIS_DBNUM: The redis database number used. Default to 0Qgis project Cache configurationQGSWPS_CACHE_ROOTDIR: Absolute path to the qgis projects root directory, projects referenced with the MAP parameter will be searched at this locationProcessing configurationQGSWPS_PROCESSSING_PROVIDERS_MODULE_PATH: Path to look for processing algorithms provider to publish, algorithms from providers specified here will be runnable as WPS processes.Exposing algorithms as WPS servicesNote that since 1.1 , the__algorithms__.pymethod for declaring providers is no longer supported.Processing providers following the same rules as  Qgis regular plugin with a special factory entrypoint:WPSClassFactory(iface)in the__init__.pyfile.Themetadata.txtfileAs regular QGIS plugin, a metadata.txt file must be present with a special entrywps=Trueindicating that
the plugin is available as a WPS service provider.Registering providersTheifaceparameter is a instance ofWPSServerInterfacewhich provide aregisterProvider( provider: QgsAlgorithmProvider, expose: bool = True) -> Anymethod.Exposed providers as WPS services must be registered using theregisterProvidermethodExample:defWPSClassFactory(iface:WPSServerInterface)->Any:fromTestAlgorithmProvider1importAlgorithmProvider1fromTestAlgorithmProvider2importAlgorithmProvider2iface.registerProvider(AlgorithmProvider1())iface.registerProvider(AlgorithmProvider2())Controlling what is exposed:Processing algorithm with the flagFlagHideFromToolboxset will not be exposed as WPS process.Parameters with the flagFlagHiddenset won't be exposed in aDescribeProcessrequestReferencesOGC standardsOGC Api processesIntroduction to WPSPy-qgis-server at FOSS4G 2019.