Class: QgsProviderRegistry

class qgis.core.QgsProviderRegistry

Bases: sip.wrapper

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

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.

deleteStyleById

Deletes a layer style defined by styleId

directoryDrivers

Returns a string containing the available directory drivers

fileMeshDatasetFilters

Returns mesh’s dataset file filter string

fileMeshFilters

Returns mesh file filter string

fileRasterFilters

Returns raster file filter string

fileVectorFilters

Returns vector file filter string

function

Gets pointer to provider function

getStyleById

Gets a layer style defined by styleId

instance

Means of accessing canonical single instance

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

loadStyle

Loads a layer style defined by uri

pluginList

Returns list of provider plugins found

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

pyramidResamplingMethods

Returns list of raster pyramid resampling methods

registerGuis

Deprecated since version QGIS: 3.10

registerProvider

register a new vector data provider from its providerMetadata

saveStyle

Saves a layer style to provider

setLibraryDirectory

Sets library directory where to search for plugins

Attributes

Embedded

Manager

None

Embedded = 1
Manager = 2
None = 0
class WidgetMode

Bases: int

createDb(self, providerKey: str, dbPath: str, errCause: str) → bool

Creates database by the provider on the path

New in version 3.10.

Parameters
  • providerKey (str) –

  • dbPath (str) –

  • errCause (str) –

Return type

bool

createProvider(self, providerKey: str, dataSource: str, options: QgsDataProvider.ProviderOptions = QgsDataProvider.ProviderOptions()) → QgsDataProvider

Creates a new instance of a provider.

Parameters
  • providerKey (str) – identifier of the provider

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

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

Return type

QgsDataProvider

Returns

new instance of provider or None on error

createProviderLibrary(self, providerKey: str) → QLibrary

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 QGIS: 3.10 - providers may not need to be loaded from a library

Parameters

providerKey (str) –

Return type

QLibrary

createRasterDataProvider(self, providerKey: str, uri: str, format: str, nBands: int, type: Qgis.DataType, width: int, height: int, crs: QgsCoordinateReferenceSystem, createOptions: Iterable[str] = []) → Tuple[QgsRasterDataProvider, float]

Creates new instance of raster data provider

See also

createProvider()

New in version 3.10.

Parameters
  • providerKey (str) –

  • uri (str) –

  • format (str) –

  • nBands (int) –

  • type (Qgis.DataType) –

  • width (int) –

  • height (int) –

  • crs (QgsCoordinateReferenceSystem) –

  • createOptions (Iterable[str] = []) –

Return type

Tuple[QgsRasterDataProvider, float]

createSelectionWidget(self, providerKey: str, parent: QWidget = None, fl: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags(), widgetMode: QgsProviderRegistry.WidgetMode = QgsProviderRegistry.WidgetMode.None) → QWidget

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 QGIS: 3.10 - use QgsGui.providerGuiRegistry()->createDataSourceWidget() instead

Parameters
  • providerKey (str) –

  • parent (QWidget = None) –

  • fl (Union[Qt.WindowFlags) –

  • widgetMode (QgsProviderRegistry.WidgetMode = QgsProviderRegistry.WidgetMode.None) –

Return type

QWidget

createTransaction(self, providerKey: str, connString: str) → QgsTransaction

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

New in version 3.10.

Parameters
  • providerKey (str) –

  • connString (str) –

Return type

QgsTransaction

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

Returns list of data item providers of the provider

Note

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

New in version 3.10.

Parameters

providerKey (str) –

Return type

List[QgsDataItemProvider]

databaseDrivers(self) → str

Returns a string containing the available database drivers

Return type

str

decodeUri(self, providerKey: str, uri: str) → Dict[str, Any]

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

Parameters
  • providerKey (str) – identifier of the provider

  • uri (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

New in version 3.4.

deleteStyleById(self, providerKey: str, uri: str, styleId: str, errCause: str) → bool

Deletes a layer style defined by styleId

New in version 3.10.

Parameters
  • providerKey (str) –

  • uri (str) –

  • styleId (str) –

  • errCause (str) –

Return type

bool

directoryDrivers(self) → str

Returns a string containing the available directory drivers

Return type

str

fileMeshDatasetFilters(self) → str

Returns mesh’s dataset file filter string

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

This walks through all data providers appending calls to their fileMeshFilters to a string, which is then returned.

New in version 3.6.

Return type

str

fileMeshFilters(self) → str

Returns mesh file filter string

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

This walks through all data providers appending calls to their fileMeshFilters to a string, which is then returned.

New in version 3.6.

Return type

str

fileRasterFilters(self) → str

Returns raster file filter string

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

This walks through all data providers appending calls to their buildSupportedRasterFileFilter to a string, which is then returned.

Note

This replaces QgsRasterLayer.buildSupportedRasterFileFilter()

Return type

str

fileVectorFilters(self) → str

Returns vector file filter string

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

This walks through all data providers appending calls to their fileVectorFilters to a string, which is then returned.

note

It’d be nice to eventually be raster/vector neutral.

Return type

str

function(self, providerKey: str, functionName: str) → sip.voidptr

Gets pointer to provider function

Parameters
  • providerKey (str) – identifier of the provider

  • functionName (str) – name of function

Return type

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 QGIS: 3.10 - any provider functionality should be accessed through QgsProviderMetadata

getStyleById(self, providerKey: str, uri: str, styleId: str, errCause: str) → str

Gets a layer style defined by styleId

New in version 3.10.

Parameters
  • providerKey (str) –

  • uri (str) –

  • styleId (str) –

  • errCause (str) –

Return type

str

instance(pluginPath: str = '') → QgsProviderRegistry

Means of accessing canonical single instance

Parameters

pluginPath (str = '') –

Return type

QgsProviderRegistry

library(self, providerKey: str) → str

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 QGIS: 3.10 - providers may not need to be loaded from a library (empty string returned)

Parameters

providerKey (str) –

Return type

str

libraryDirectory(self) → QDir

Returns the library directory where plugins are found.

Return type

QDir

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

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

New in version 3.10.

Parameters
  • providerKey (str) –

  • uri (str) –

  • ids (Iterable[str]) –

  • names (Iterable[str]) –

  • descriptions (Iterable[str]) –

  • errCause (str) –

loadStyle(self, providerKey: str, uri: str, errCause: str) → str

Loads a layer style defined by uri

New in version 3.10.

Parameters
  • providerKey (str) –

  • uri (str) –

  • errCause (str) –

Return type

str

pluginList(self, asHtml: bool = False) → str

Returns list of provider plugins found

Parameters

asHtml (bool = False) –

Return type

str

protocolDrivers(self) → str

Returns a string containing the available protocol drivers

Return type

str

providerCapabilities(self, providerKey: str) → int

Returns the provider capabilities

Parameters

providerKey (str) – identifier of the provider

New in version 2.6.

Deprecated since version QGIS: 3.10 (use instead capabilities() method of individual data item provider)

Return type

int

providerList(self) → List[str]

Returns list of available providers by their keys

Return type

List[str]

providerMetadata(self, providerKey: str) → QgsProviderMetadata

Returns metadata of the provider or None if not found

Parameters

providerKey (str) –

Return type

QgsProviderMetadata

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

Returns list of raster pyramid resampling methods

New in version 3.10.

Parameters

providerKey (str) –

Return type

List[Tuple[str, str]]

registerGuis(self, widget: QWidget)

Deprecated since version QGIS: 3.10 - does nothing - use QgsGui.providerGuiRegistry()

Parameters

widget (QWidget) –

registerProvider(self, providerMetadata: QgsProviderMetadata) → bool

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

New in version 3.2.

Parameters

providerMetadata (QgsProviderMetadata) –

saveStyle(self, providerKey: str, uri: str, qmlStyle: str, sldStyle: str, styleName: str, styleDescription: str, uiFileContent: str, useAsDefault: bool, errCause: str) → bool

Saves a layer style to provider

New in version 3.10.

Parameters
  • providerKey (str) –

  • uri (str) –

  • qmlStyle (str) –

  • sldStyle (str) –

  • styleName (str) –

  • styleDescription (str) –

  • uiFileContent (str) –

  • useAsDefault (bool) –

  • errCause (str) –

Return type

bool

setLibraryDirectory(self, path: QDir)

Sets library directory where to search for plugins

Parameters

path (QDir) –