Class: QgsDataProvider

class qgis.core.QgsDataProvider(uri: str = '', providerOptions: QgsDataProvider.ProviderOptions = QgsDataProvider.ProviderOptions())

Bases: PyQt5.QtCore.QObject

Create a new dataprovider with the specified in the uri.

Additional creation options are specified within the options value.

Abstract base class for spatial data provider implementations.

Parameters
  • uri (str = '') –

  • providerOptions

CustomData = 3000
class DataCapabilities

Bases: sip.wrapper

QgsDataProvider.DataCapabilities(Union[QgsDataProvider.DataCapabilities, QgsDataProvider.DataCapability]) QgsDataProvider.DataCapabilities(QgsDataProvider.DataCapabilities)

class DataCapability

Bases: int

Database = 4
Dir = 2
EvaluateDefaultValues = 0
File = 1
Net = 8
NoDataCapabilities = 0
class ProviderOptions

Bases: sip.wrapper

QgsDataProvider.ProviderOptions(QgsDataProvider.ProviderOptions)

transformContext
class ProviderProperty

Bases: int

SUBLAYER_SEPARATOR = '!!::!!'
appendError(self, message: QgsErrorMessage)

Add error message

Parameters

message (QgsErrorMessage) –

childEvent()
connectNotify()
crs(self) → QgsCoordinateReferenceSystem

Returns the coordinate system for the data source. If the provider isn’t capable of returning its projection then an invalid QgsCoordinateReferenceSystem will be returned.

Return type

QgsCoordinateReferenceSystem

customEvent()
dataChanged

Emitted whenever a change is made to the data provider which may have caused changes in the provider’s data OUTSIDE of QGIS.

When emitted from a QgsVectorDataProvider, any cached information such as feature ids should be invalidated.

Warning

This signal is NOT emitted when changes are made to a provider from INSIDE QGIS – e.g. when adding features to a vector layer, deleting features or modifying existing features. Instead, the specific QgsVectorLayer signals should be used to detect these operations. [signal]

dataSourceUri(self, expandAuthConfig: bool = False) → str

Gets the data source specification. This may be a path or database connection string

Parameters

expandAuthConfig (bool = False) – Whether to expand any assigned authentication configuration

Return type

str

Returns

data source specification

Note

The default authentication configuration expansion is False. This keeps credentials out of layer data source URIs and project files. Expansion should be specifically done only when needed within a provider

dataTimestamp(self) → QDateTime

Current time stamp of data source

Return type

QDateTime

description(self) → str

Returns description

Returns a terse string describing what the provider is.

note

Instead of being pure virtual, might be better to generalize this behavior and presume that none of the sub-classes are going to do anything strange with regards to their name or description?

Return type

str

disconnectNotify()
enterUpdateMode(self) → bool

Enter update mode.

This is aimed at providers that can open differently the connection to the datasource, according it to be in update mode or in read-only mode. A call to this method shall be balanced with a call to leaveUpdateMode(), if this method returns True.

Most providers will have an empty implementation for that method.

For backward compatibility, providers that implement enterUpdateMode() should still make sure to allow editing operations to work even if enterUpdateMode() is not explicitly called.

Several successive calls to enterUpdateMode() can be done. So there is a concept of stack of calls that must be handled by the provider. Only the first call to enterUpdateMode() will really turn update mode on.

Return type

bool

Returns

True in case of success (or no-op implementation), False in case of failure.

New in version 2.16.

error(self) → QgsError

Gets current status error. This error describes some principal problem for which provider cannot work and thus is not valid. It is not last error after accessing data by block(), identify() etc.

Return type

QgsError

extent(self) → QgsRectangle

Returns the extent of the layer

Return type

QgsRectangle

Returns

QgsRectangle containing the extent of the layer

fileRasterFilters(self) → str

Returns raster file filter string

Returns a string suitable for a QFileDialog of raster file formats supported by the data provider. Naturally this will be an empty string for those data providers that do not deal with plain files, such as databases and servers.

Note

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

Return type

str

fileVectorFilters(self) → str

Returns vector file filter string

Returns a string suitable for a QFileDialog of vector file formats supported by the data provider. Naturally this will be an empty string for those data providers that do not deal with plain files, such as databases and servers.

Note

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

Return type

str

fullExtentCalculated

Emitted whenever a deferred extent calculation is completed by the provider.

Layers should connect to this signal and update their cached extents whenever it is emitted. [signal]

invalidateConnections(self, connection: str)

Invalidate connections corresponding to specified name

New in version 2.16.

Parameters

connection (str) –

isSignalConnected()
isValid(self) → bool

Returns True if this is a valid layer. It is up to individual providers to determine what constitutes a valid layer.

Return type

bool

layerMetadata(self) → QgsLayerMetadata

Returns layer metadata collected from the provider’s source.

Individual data providers must implement this method if they support collecting metadata.

New in version 3.0.

Return type

QgsLayerMetadata

leaveUpdateMode(self) → bool

Leave update mode.

This is aimed at providers that can open differently the connection to the datasource, according it to be in update mode or in read-only mode. This method shall be balanced with a successful call to enterUpdateMode().

Most providers will have an empty implementation for that method.

Several successive calls to enterUpdateMode() can be done. So there is a concept of stack of calls that must be handled by the provider. Only the last call to leaveUpdateMode() will really turn update mode off.

Return type

bool

Returns

True in case of success (or no-op implementation), False in case of failure.

New in version 2.16.

name(self) → str

Returns a provider name

Essentially just returns the provider key. Should be used to build file dialogs so that providers can be shown with their supported types. Thus if more than one provider supports a given format, the user is able to select a specific provider to open that file.

note

Instead of being pure virtual, might be better to generalize this behavior and presume that none of the sub-classes are going to do anything strange with regards to their name or description?

Return type

str

notify

Emitted when the datasource issues a notification.

See also

setListening()

New in version 3.0: [signal]

Parameters

msg (str) –

providerProperty(self, property: QgsDataProvider.ProviderProperty, defaultValue: Any = None) → Any

Gets the current value of a certain provider property. It depends on the provider which properties are supported.

New in version 2.16.

Parameters
Return type

Any

receivers()
reloadData(self)

Reloads the data from the source. Needs to be implemented by providers with data caches to synchronize with changes in the data source

sender()
senderSignalIndex()
setDataSourceUri(self, uri: str)

Set the data source specification. This may be a path or database connection string

Parameters

uri (str) – source specification

setError(self, error: QgsError)

Sets error message

Parameters

error (QgsError) –

setLayerOrder(self, layers: Iterable[str])

Reorder the list of layer names to be rendered by this provider (in order from bottom to top)

Note

layers must have been previously added.

Parameters

layers (Iterable[str]) –

setListening(self, isListening: bool)

Set whether the provider will listen to datasource notifications If set, the provider will issue notify signals.

The default implementation does nothing.

See also

notify()

New in version 3.0.

Parameters

isListening (bool) –

setProviderProperty(self, property: QgsDataProvider.ProviderProperty, value: Any)

Allows setting arbitrary properties on the provider. It depends on the provider which properties are supported.

New in version 2.16.

Parameters
setSubLayerVisibility(self, name: str, vis: bool)

Set the visibility of the given sublayer name

Parameters
  • name (str) –

  • vis (bool) –

setSubsetString(self, subset: str, updateFeatureCount: bool = True) → bool

Set the subset string used to create a subset of features in the layer. This may be a sql where clause or any other string that can be used by the data provider to create a subset. Must be implemented in the dataprovider.

Parameters
  • subset (str) –

  • updateFeatureCount (bool = True) –

Return type

bool

setUri(self, uri: QgsDataSourceUri)

Set the data source specification.

New in version 3.0.

Parameters

uri (QgsDataSourceUri) –

subLayerCount(self) → int

Returns the number of layers for the current data source

Return type

int

subLayerStyles(self) → List[str]

Sub-layer styles for each sub-layer handled by this provider, in order from bottom to top

Sub-layer styles are used to abstract the way the provider’s source can symbolise layers in some way at the server, before it serves them to the provider.

Return type

List[str]

subLayers(self) → List[str]

Sub-layers handled by this provider, in order from bottom to top

Sub-layers are used when the provider’s source can combine layers it knows about in some way before it hands them off to the provider.

See also

SUBLAYER_SEPARATOR

Return type

List[str]

sublayerSeparator() → str

String sequence used for separating components of sublayers strings.

Note

Replaces the static const SUBLAYER_SEPARATOR

See also

subLayers()

New in version 3.12.

Return type

str

subsetString(self) → str

Returns the subset definition string (typically sql) currently in use by the layer and used by the provider to limit the feature set. Must be overridden in the dataprovider, otherwise returns a null QString.

Return type

str

supportsSubsetString(self) → bool

Returns True if the provider supports setting of subset strings.

Return type

bool

timerEvent()
timestamp(self) → QDateTime

Time stamp of data source in the moment when data/metadata were loaded by provider

Return type

QDateTime

updateExtents(self)

Update the extents of the layer. Not implemented by default.

uri(self) → QgsDataSourceUri

Gets the data source specification.

New in version 3.0.

Return type

QgsDataSourceUri

writeLayerMetadata(self, metadata: QgsLayerMetadata) → bool

Writes layer metadata to the underlying provider source. Support depends on individual provider capabilities.

Returns True if metadata was successfully written to the data provider.

See also

layerMetadata()

New in version 3.0.

Parameters

metadata (QgsLayerMetadata) –

Return type

bool