Class: QgsProviderRegistry

A registry / canonical manager of data providers.

This is a Singleton class that manages data provider access.

Providers can be either loaded via libraries or native providers that are included in the core QGIS installation and accessed through function pointers.

Loaded providers may be restricted using QGIS_PROVIDER_FILE environment variable. QGIS_PROVIDER_FILE is regexp pattern applied to provider file name (not provider key). For example, if the variable is set to gdal|ogr|postgres it will load only providers gdal, ogr and postgres.

Methods

absoluteToRelativeUri

Converts absolute path(s) to relative path(s) in the given provider-specific URI.

createDb

Creates database by the provider on the path

createProvider

Creates a new instance of a provider.

createProviderLibrary

Returns a new QLibrary for the specified providerKey.

createRasterDataProvider

Creates new instance of raster data provider

createSelectionWidget

Returns a new widget for selecting layers from a provider.

createTransaction

Returns new instance of transaction.

dataItemProviders

Returns list of data item providers of the provider

databaseDrivers

Returns a string containing the available database drivers

decodeUri

Breaks a provider data source URI into its component paths (e.g. file path, layer name).

deleteStyleById

Deletes a layer style defined by styleId

directoryDrivers

Returns a string containing the available directory drivers

encodeUri

Reassembles a provider data source URI from its component paths (e.g. file path, layer name).

fileMeshDatasetFilters

Returns a file filter string for supported mesh dataset files.

fileMeshFilters

Returns a file filter string for supported mesh files.

filePointCloudFilters

Returns a file filter string for supported point clouds.

fileRasterFilters

Returns a file filter string for supported raster files.

fileTiledSceneFilters

Returns a file filter string for supported tiled scene files.

fileVectorFilters

Returns a file filter string for supported vector files.

fileVectorTileFilters

Returns a file filter string for supported vector tile files.

function

Gets pointer to provider function

getStyleById

Gets a layer style defined by styleId.

handleUnusableUri

Returns True if the specified uri can potentially be handled by QGIS, if additional dependencies or build-time requirements are present.

library

Returns path for the library of the provider.

libraryDirectory

Returns the library directory where plugins are found.

listStyles

Lists stored layer styles in the provider defined by providerKey and uri

loadStoredStyle

Loads a layer style from the provider storage, reporting its name.

loadStyle

Loads a layer style defined by uri

pluginList

Returns list of provider plugins found

preferredProvidersForUri

Returns the details for the preferred provider(s) for opening the specified uri.

protocolDrivers

Returns a string containing the available protocol drivers

providerCapabilities

Returns the provider capabilities

providerList

Returns list of available providers by their keys

providerMetadata

Returns metadata of the provider or None if not found

providersForLayerType

Returns a list of the provider keys for available providers which handle the specified layer type.

pyramidResamplingMethods

Returns list of raster pyramid resampling methods

querySublayers

Queries the specified uri and returns a list of any valid sublayers found in the dataset which can be handled by any registered data provider.

registerGuis

registerProvider

register a new vector data provider from its providerMetadata

registerUnusableUriHandler

Registers an unusable URI handler, used to handle unusable URIs which aren't handled by any registered providers, and construct user-friendly warnings as to why the URI is unusable.

relativeToAbsoluteUri

Converts relative path(s) to absolute path(s) in the given provider-specific URI.

saveLayerMetadata

Saves metadata to the layer corresponding to the specified uri.

saveStyle

Saves a layer style to provider

setLibraryDirectory

Sets library directory where to search for plugins

shouldDeferUriForOtherProviders

Returns True if the provider with matching providerKey should defer handling of the specified uri to another provider.

styleExists

Returns True if a layer style with the specified styleId exists in the provider defined by providerKey and uri.

uriIsBlocklisted

Returns True if the specified uri is known by any registered provider to be something which should be blocklisted from the QGIS interface, e.g. an internal detail only.

Static Methods

instance

Means of accessing canonical single instance

Attributes

Embedded

Manager

Standalone

class qgis.core.QgsProviderRegistry[source]

Bases: object

Embedded = 1
Manager = 2
class ProviderCandidateDetails[source]

Bases: object

Contains information pertaining to a candidate provider.

Added in version 3.18.

QgsProviderRegistry.ProviderCandidateDetails(metadata: Optional[QgsProviderMetadata], layerTypes: Iterable[Qgis.LayerType]) Constructor for ProviderCandidateDetails, with the specified provider metadata and valid candidate layerTypes.

QgsProviderRegistry.ProviderCandidateDetails(a0: QgsProviderRegistry.ProviderCandidateDetails)

layerTypes(self) List[Qgis.LayerType]

Returns a list of map layer types which are valid options for opening the target using this candidate provider.

Return type:

List[Qgis.LayerType]

metadata(self) QgsProviderMetadata | None[source]

Returns the candidate provider metadata.

Return type:

Optional[QgsProviderMetadata]

Standalone = 0
class UnusableUriDetails[source]

Bases: object

Contains information about unusable URIs which aren’t handled by any registered providers.

For example, if a QGIS install is built without the PDAL library then las/laz files are unusable. This class can then be used to construct friendly warnings to users advising them why the las/laz files cannot be used on their QGIS build.

Added in version 3.18.1.

QgsProviderRegistry.UnusableUriDetails(uri: Optional[str] = ‘’, warning: Optional[str] = ‘’, layerTypes: Iterable[Qgis.LayerType] = []) Constructor for UnusableUriDetails for the given uri, with the specified user-friendly, translated warning.

The optional layerTypes argument can be used to specify layer types which are usually valid options for opening the URI.

QgsProviderRegistry.UnusableUriDetails(a0: QgsProviderRegistry.UnusableUriDetails)

detailedWarning: str

Contains a longer, user-friendly, translated message advising why the URI is not usable.

layerTypes: List[Qgis.LayerType]

Contains a list of map layer types which are usually valid options for opening the target URI.

uri: str

URI which could not be handled.

warning: str

Contains a short, user-friendly, translated message advising why the URI is not usable.

class UnusableUriHandlerInterface[source]

Bases: object

An interface used to handle unusable URIs which aren’t handled by any registered providers, and construct user-friendly warnings as to why the URI is unusable.

For example, if a QGIS install is built without the PDAL library then las/laz files are unusable. This class can then be used to construct friendly warnings to users advising them why the las/laz files cannot be used on their QGIS build.

Added in version 3.18.1.

abstract details(self, uri: str | None) QgsProviderRegistry.UnusableUriDetails[source]

Returns the details for advising the user why the uri is not usable.

Parameters:

uri (Optional[str])

Return type:

QgsProviderRegistry.UnusableUriDetails

abstract matchesUri(self, uri: str | None) bool[source]

Returns True if the handle is an unusable URI handler for the specified uri.

Parameters:

uri (Optional[str])

Return type:

bool

class WidgetMode

Bases: int

absoluteToRelativeUri(self, providerKey: str | None, uri: str | None, context: QgsReadWriteContext) str[source]

Converts absolute path(s) to relative path(s) in the given provider-specific URI. and returns modified URI according to the context object’s configuration. This is commonly used when writing project files. If a provider does not work with paths, unmodified URI will be returned.

Return type:

str

Returns:

modified URI with relative path(s)

Note

this function may not be supported by all providers. The default implementation uses QgsPathResolver.writePath() on the whole URI.

Added in version 3.30.

Parameters:
createDb(self, providerKey: str | None, dbPath: str | None, errCause: str | None) bool[source]

Creates database by the provider on the path

Added in version 3.10.

Parameters:
  • providerKey (Optional[str])

  • dbPath (Optional[str])

  • errCause (Optional[str])

Return type:

bool

createProvider(self, providerKey: str | None, dataSource: str | None, options: QgsDataProvider.ProviderOptions = QgsDataProvider.ProviderOptions(), flags: Qgis.DataProviderReadFlags | Qgis.DataProviderReadFlag = Qgis.DataProviderReadFlags()) QgsDataProvider | None[source]

Creates a new instance of a provider.

Parameters:
  • providerKey (Optional[str]) – identifier of the provider

  • dataSource (Optional[str]) – string containing data source for the provider

  • options (QgsDataProvider.ProviderOptions = QgsDataProvider.ProviderOptions()) – provider options

  • flags (Union[Qgis.DataProviderReadFlags, Qgis.DataProviderReadFlag] = Qgis.DataProviderReadFlags()) – provider flags since QGIS 3.16

Return type:

Optional[QgsDataProvider]

Returns:

new instance of provider or None on error

createProviderLibrary(self, providerKey: str | None) QLibrary | None[source]

Returns a new QLibrary for the specified providerKey. Ownership of the returned object is transferred to the caller and the caller is responsible for deleting it.

If the provider uses direct provider function pointers instead of a library None will be returned.

Deprecated since version 3.10: Providers may not need to be loaded from a library.

Parameters:

providerKey (Optional[str])

Return type:

Optional[QLibrary]

createRasterDataProvider(self, providerKey: str | None, uri: str | None, format: str | None, nBands: int, type: Qgis.DataType, width: int, height: int, crs: QgsCoordinateReferenceSystem, createOptions: Iterable[str | None] = [])[source]

Creates new instance of raster data provider

See also

createProvider()

Added in version 3.10.

Parameters:
createSelectionWidget(self, providerKey: str | None, parent: QWidget | None = None, fl: Qt.WindowFlags | Qt.WindowType = Qt.WindowFlags(), widgetMode: QgsProviderRegistry.WidgetMode = QgsProviderRegistry.WidgetMode.Standalone) QWidget | None[source]

Returns a new widget for selecting layers from a provider. Either the parent widget must be set or the caller becomes responsible for deleting the returned widget.

Deprecated since version 3.10: Use QgsGui.sourceSelectProviderRegistry()->:py:func:~QgsProviderRegistry.createDataSourceWidget instead.

Parameters:
  • providerKey (Optional[str])

  • parent (Optional[QWidget] = None)

  • fl (Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags())

  • widgetMode (QgsProviderRegistry.WidgetMode = QgsProviderRegistry.WidgetMode.Standalone)

Return type:

Optional[QWidget]

createTransaction(self, providerKey: str | None, connString: str | None) QgsTransaction | None[source]

Returns new instance of transaction. Ownership is transferred to the caller

Added in version 3.10.

Parameters:
  • providerKey (Optional[str])

  • connString (Optional[str])

Return type:

Optional[QgsTransaction]

dataItemProviders(self, providerKey: str | None) List[QgsDataItemProvider]

Returns list of data item providers of the provider

Note

Ownership of created data item providers is passed to the caller.

Added in version 3.10.

Parameters:

providerKey (Optional[str])

Return type:

List[QgsDataItemProvider]

databaseDrivers(self) str[source]

Returns a string containing the available database drivers

Return type:

str

decodeUri(self, providerKey: str | None, uri: str | None) Dict[str, Any][source]

Breaks a provider data source URI into its component paths (e.g. file path, layer name).

Parameters:
  • providerKey (Optional[str]) – identifier of the provider

  • uri (Optional[str]) – uri string

Return type:

Dict[str, Any]

Returns:

map containing components. Standard components include “path”, “layerName”, “url”.

Note

this function may not be supported by all providers, an empty map will be returned in such case

Added in version 3.4.

deleteStyleById(self, providerKey: str | None, uri: str | None, styleId: str | None, errCause: str | None) bool[source]

Deletes a layer style defined by styleId

Added in version 3.10.

Parameters:
  • providerKey (Optional[str])

  • uri (Optional[str])

  • styleId (Optional[str])

  • errCause (Optional[str])

Return type:

bool

directoryDrivers(self) str[source]

Returns a string containing the available directory drivers

Return type:

str

encodeUri(self, providerKey: str | None, parts: Dict[str, Any]) str[source]

Reassembles a provider data source URI from its component paths (e.g. file path, layer name).

Parameters:
  • providerKey (Optional[str]) – identifier of the provider

  • parts (Dict[str, Any]) – parts as returned by decodeUri

Return type:

str

Returns:

datasource uri string

Note

this function may not be supported by all providers, an empty string will be returned in such case

See also

decodeUri()

Added in version 3.12.

fileMeshDatasetFilters(self) str[source]

Returns a file filter string for supported mesh dataset files.

Returns a string suitable for a QFileDialog of mesh datasets file formats supported by all data providers.

Added in version 3.6.

Return type:

str

fileMeshFilters(self) str[source]

Returns a file filter string for supported mesh files.

Returns a string suitable for a QFileDialog of mesh file formats supported by all data providers.

Added in version 3.6.

Return type:

str

filePointCloudFilters(self) str[source]

Returns a file filter string for supported point clouds.

Returns a string suitable for a QFileDialog of point cloud file formats supported by all data providers.

Added in version 3.18.

Return type:

str

fileRasterFilters(self) str[source]

Returns a file filter string for supported raster files.

Returns a string suitable for a QFileDialog of raster file formats supported by all data providers.

Note

This replaces QgsRasterLayer.buildSupportedRasterFileFilter()

Return type:

str

fileTiledSceneFilters(self) str[source]

Returns a file filter string for supported tiled scene files.

Returns a string suitable for a QFileDialog of tiled scene file formats supported by all data providers.

Added in version 3.34.

Return type:

str

fileVectorFilters(self) str[source]

Returns a file filter string for supported vector files.

Returns a string suitable for a QFileDialog of vector file formats supported by all data providers.

Return type:

str

fileVectorTileFilters(self) str[source]

Returns a file filter string for supported vector tile files.

Returns a string suitable for a QFileDialog of vector tile file formats supported by all data providers.

Added in version 3.32.

Return type:

str

function(self, providerKey: str | None, functionName: str | None) PyQt5.sip.voidptr | None[source]

Gets pointer to provider function

Parameters:
  • providerKey (Optional[str]) – identifier of the provider

  • functionName (Optional[str]) – name of function

Return type:

Optional[PyQt5.sip.voidptr]

Returns:

pointer to function or None on error. If the provider uses direct provider function pointers instead of a library None will be returned.

Deprecated since version 3.10: Any provider functionality should be accessed through QgsProviderMetadata.

getStyleById(self, providerKey: str | None, uri: str | None, styleId: str | None, errCause: str | None) str[source]

Gets a layer style defined by styleId.

See also

styleExists()

Added in version 3.10.

Parameters:
  • providerKey (Optional[str])

  • uri (Optional[str])

  • styleId (Optional[str])

  • errCause (Optional[str])

Return type:

str

handleUnusableUri(self, uri: str | None)[source]

Returns True if the specified uri can potentially be handled by QGIS, if additional dependencies or build-time requirements are present.

This can be used to show user-friendly warning messages advising them why a particular uri cannot be opened on their QGIS install. For example, if a QGIS install is built without the PDAL library then las/laz files are unusable, and this method can be used to retrieve a user-friendly warning as to why the las/laz files cannot be used on their QGIS build.

Warning

This method does not perform the test to actually determine if the given uri can be handled by any registered provider. It is assumed that prior to calling this method the caller has already determined in advance that the uri could not be handled.

Parameters:

uri (Optional[str]) -> (bool) – URI to test

Returns:

  • True if the uri was matched to a registered QgsProviderRegistry.UnusableUriHandlerInterface.

  • details: will be populated with details allowing construction of a user-friendly warning message

Added in version 3.18.1.

static instance(pluginPath: str | None = '') QgsProviderRegistry | None[source]

Means of accessing canonical single instance

Parameters:

pluginPath (Optional[str] = '')

Return type:

Optional[QgsProviderRegistry]

library(self, providerKey: str | None) str[source]

Returns path for the library of the provider.

If the provider uses direct provider function pointers instead of a library an empty string will be returned.

Deprecated since version 3.10: Providers may not need to be loaded from a library (empty string returned).

Parameters:

providerKey (Optional[str])

Return type:

str

libraryDirectory(self) QDir[source]

Returns the library directory where plugins are found.

Return type:

QDir

listStyles(self, providerKey: str | None, uri: str | None, ids: Iterable[str | None], names: Iterable[str | None], descriptions: Iterable[str | None], errCause: str | None) int[source]

Lists stored layer styles in the provider defined by providerKey and uri

Return type:

int

Returns:

-1 if not implemented by provider, otherwise number of styles stored

Added in version 3.10.

Parameters:
  • providerKey (Optional[str])

  • uri (Optional[str])

  • ids (Iterable[Optional[str]])

  • names (Iterable[Optional[str]])

  • descriptions (Iterable[Optional[str]])

  • errCause (Optional[str])

loadStoredStyle(self, providerKey: str | None, uri: str | None, styleName: str | None, errCause: str | None) str[source]

Loads a layer style from the provider storage, reporting its name.

Parameters:
  • providerKey (Optional[str]) – name of the data provider

  • uri (Optional[str]) – data source uri

  • styleName (Optional[str]) – the name of the style if available, empty otherwise

  • errCause (Optional[str]) – report errors

Return type:

str

Returns:

the style QML (XML)

Added in version 3.30.

loadStyle(self, providerKey: str | None, uri: str | None, errCause: str | None) str[source]

Loads a layer style defined by uri

Return type:

str

Returns:

the style QML (XML)

Added in version 3.10.

Parameters:
  • providerKey (Optional[str])

  • uri (Optional[str])

  • errCause (Optional[str])

pluginList(self, asHtml: bool = False) str[source]

Returns list of provider plugins found

Parameters:

asHtml (bool = False)

Return type:

str

preferredProvidersForUri(self, uri: str | None) List[QgsProviderRegistry.ProviderCandidateDetails]

Returns the details for the preferred provider(s) for opening the specified uri.

The preferred provider is determined by comparing the priority returned by QgsProviderMetadata.priorityForUri() for all registered providers, and selecting the provider with the largest non-zero priority.

An empty list may be returned, which indicates that no providers are available which returned a non-zero priority for the specified URI.

In the case that multiple providers returned the same priority for the URI then all of these providers will be returned.

Added in version 3.18.

Parameters:

uri (Optional[str])

Return type:

List[QgsProviderRegistry.ProviderCandidateDetails]

protocolDrivers(self) str[source]

Returns a string containing the available protocol drivers

Return type:

str

providerCapabilities(self, providerKey: str | None) Qgis.DataItemProviderCapabilities[source]

Returns the provider capabilities

Parameters:

providerKey (Optional[str]) – identifier of the provider

Deprecated since version 3.10: Use instead capabilities() method of individual data item provider.

Return type:

Qgis.DataItemProviderCapabilities

providerList(self) List[str][source]

Returns list of available providers by their keys

Return type:

List[str]

providerMetadata(self, providerKey: str | None) QgsProviderMetadata | None[source]

Returns metadata of the provider or None if not found

Parameters:

providerKey (Optional[str])

Return type:

Optional[QgsProviderMetadata]

providersForLayerType(self, type: Qgis.LayerType) Set[str]

Returns a list of the provider keys for available providers which handle the specified layer type.

Added in version 3.26.

Parameters:

type (Qgis.LayerType)

Return type:

Set[str]

pyramidResamplingMethods(self, providerKey: str | None) List[Tuple[str, str]]

Returns list of raster pyramid resampling methods

Added in version 3.10.

Parameters:

providerKey (Optional[str])

Return type:

List[Tuple[str, str]]

querySublayers(self, uri: str | None, flags: Qgis.SublayerQueryFlags | Qgis.SublayerQueryFlag = Qgis.SublayerQueryFlags(), feedback: QgsFeedback | None = None) List[QgsProviderSublayerDetails]

Queries the specified uri and returns a list of any valid sublayers found in the dataset which can be handled by any registered data provider.

This method iteratively queries each registered data provider and returns the complete collated list of all valid sublayers found in the dataset which can be opened by the data providers.

The optional flags argument can be used to control the behavior of the query.

The optional feedback argument can be used to provide cancellation support for long-running queries.

Added in version 3.22.

Parameters:
Return type:

List[QgsProviderSublayerDetails]

registerGuis(self, widget: QWidget | None)[source]

Deprecated since version 3.10.

Does nothing - use QgsGui.providerGuiRegistry().

Parameters:

widget (Optional[QWidget])

registerProvider(self, providerMetadata: QgsProviderMetadata | None) bool[source]

register a new vector data provider from its providerMetadata

Return type:

bool

Returns:

True on success, False if a provider with the same key was already registered

Note

ownership of the QgsProviderMetadata instance is transferred to the registry

Added in version 3.2.

Parameters:

providerMetadata (Optional[QgsProviderMetadata])

registerUnusableUriHandler(self, handler: QgsProviderRegistry.UnusableUriHandlerInterface | None) bool[source]

Registers an unusable URI handler, used to handle unusable URIs which aren’t handled by any registered providers, and construct user-friendly warnings as to why the URI is unusable.

Return type:

bool

Returns:

True on success

Note

ownership of the UnusableUriHandlerInterface instance is transferred to the registry

Added in version 3.18.1.

Parameters:

handler (Optional[QgsProviderRegistry.UnusableUriHandlerInterface])

relativeToAbsoluteUri(self, providerKey: str | None, uri: str | None, context: QgsReadWriteContext) str[source]

Converts relative path(s) to absolute path(s) in the given provider-specific URI. and returns modified URI according to the context object’s configuration. This is commonly used when reading project files. If a provider does not work with paths, unmodified URI will be returned.

Return type:

str

Returns:

modified URI with absolute path(s)

Note

this function may not be supported by all providers. The default implementation uses QgsPathResolver.readPath() on the whole URI.

Added in version 3.30.

Parameters:
saveLayerMetadata(self, providerKey: str | None, uri: str | None, metadata: QgsLayerMetadata)[source]

Saves metadata to the layer corresponding to the specified uri.

Parameters:
  • providerKey (Optional[str]) – identifier of the provider

  • uri (Optional[str]) – uri of layer to store metadata for

  • metadata (QgsLayerMetadata) -> (bool) – layer metadata

Returns:

  • True if the metadata was successfully saved.

  • errorMessage: descriptive string of error if encountered

Raises:

QgsNotSupportedException – if the provider does not support saving layer metadata for the specified uri.

Added in version 3.20.

saveStyle(self, providerKey: str | None, uri: str | None, qmlStyle: str | None, sldStyle: str | None, styleName: str | None, styleDescription: str | None, uiFileContent: str | None, useAsDefault: bool, errCause: str | None) bool[source]

Saves a layer style to provider

Added in version 3.10.

Parameters:
  • providerKey (Optional[str])

  • uri (Optional[str])

  • qmlStyle (Optional[str])

  • sldStyle (Optional[str])

  • styleName (Optional[str])

  • styleDescription (Optional[str])

  • uiFileContent (Optional[str])

  • useAsDefault (bool)

  • errCause (Optional[str])

Return type:

bool

setLibraryDirectory(self, path: QDir)[source]

Sets library directory where to search for plugins

Parameters:

path (QDir)

shouldDeferUriForOtherProviders(self, uri: str | None, providerKey: str | None) bool[source]

Returns True if the provider with matching providerKey should defer handling of the specified uri to another provider.

This method tests whether any providers are listed as the preferred provider for uri (see preferredProvidersForUri()), and if so tests whether the specified provider is included in that preferred providers list. Returns True only if the specified provider is calculated as one of the preferred providers for the URI.

In the case that there is no registered preferred provider for the URI then False will be returned, and the provider must use another metric to determine whether it should handle the URI.

Added in version 3.18.

Parameters:
  • uri (Optional[str])

  • providerKey (Optional[str])

Return type:

bool

styleExists(self, providerKey: str | None, uri: str | None, styleId: str | None)[source]

Returns True if a layer style with the specified styleId exists in the provider defined by providerKey and uri.

Parameters:
  • providerKey (Optional[str]) – provider key

  • uri (Optional[str]) – provider URI

  • styleId (Optional[str]) -> (bool) – style ID to test for

Returns:

  • True if the layer style already exists

  • errorCause: a descriptive error message, if an error occurs while checking if the style exists

See also

getStyleById()

Added in version 3.24.

uriIsBlocklisted(self, uri: str | None) bool[source]

Returns True if the specified uri is known by any registered provider to be something which should be blocklisted from the QGIS interface, e.g. an internal detail only.

Specifically, this method can be utilized by the browser panel to hide noisy internal details for URIs which are known to be sidecar files only, such as “.aux.xml” files or “.shp.xml” files, or the “ept-build.json” files which sit alongside Entwine “ept.json” point cloud sources.

This method tests whether any of the registered providers return True for the their QgsProviderMetadata.uriIsBlocklisted() implementation for the specified URI.

Added in version 3.18.

Parameters:

uri (Optional[str])

Return type:

bool