Class: QgsDataSourceUri

class qgis.core.QgsDataSourceUri

Bases: sip.wrapper

Class for storing the component parts of a RDBMS data source URI (e.g. a Postgres data source).

This structure stores the database connection information, including host, database, user name, password, schema, password, and SQL where clause.

QgsDataSourceUri()

QgsDataSourceUri(uri: str) Constructor for QgsDataSourceUri which parses an input uri string.

QgsDataSourceUri(QgsDataSourceUri)

Methods

authConfigId

Returns any associated authentication configuration ID stored in the URI.

clearSchema

Clears the schema stored in the URI.

connectionInfo

Returns the connection part of the URI.

database

Returns the database name stored in the URI.

decodeSslMode

Decodes SSL mode string into enum value.

disableSelectAtId

Set to True to disable selection by feature ID.

driver

Returns the driver name stored in the URI

encodeSslMode

Encodes SSL mode enum value into a string.

encodedUri

Returns the complete encoded URI as a byte array.

geometryColumn

Returns the name of the geometry column stored in the URI, if set.

hasParam

Returns True if a parameter with the specified key exists.

host

Returns the host name stored in the URI.

httpHeader

Returns the http header value according to key

httpHeaders

Returns http headers

keyColumn

Returns the name of the (primary) key column for the referenced table.

param

Returns a generic parameter value corresponding to the specified key.

parameterKeys

Returns parameter keys used in the uri: specialized ones ("table", "schema", etc.) or generic parameters.

params

Returns multiple generic parameter values corresponding to the specified key.

password

Returns the password stored in the URI.

port

Returns the port stored in the URI.

quotedTablename

Returns the URI's table name, escaped and quoted.

removeParam

Removes a generic parameter by key.

removePassword

Removes the password element from a URI.

schema

Returns the schema stored in the URI.

selectAtIdDisabled

Returns whether the selection by feature ID is disabled.

service

Returns the service name associated with the URI.

setAuthConfigId

Sets the authentication configuration ID for the URI.

setConnection

Sets all connection related members at once.

setDataSource

Sets all data source related members at once.

setDatabase

Sets the URI database name.

setDriver

Sets the driver name stored in the URI.

setEncodedUri

Sets the complete encoded uri from a string value.

setGeometryColumn

Sets geometry column name to geometryColumn

setHttpHeaders

Sets headers to headers

setKeyColumn

Sets the name of the (primary) key column.

setParam

Sets a generic parameter value on the URI.

setParamList

Sets a generic parameter list value on the URI.

setPassword

Sets the password for the URI.

setSchema

Sets the scheme for the URI.

setSql

Sets the sql filter for the URI.

setSrid

Sets the spatial reference ID associated with the URI.

setTable

Sets table to table

setUseEstimatedMetadata

Sets whether estimated metadata should be used for the connection.

setUsername

Sets the username for the URI.

setWkbType

Sets the WKB type associated with the URI.

sql

Returns the SQL filter stored in the URI, if set.

srid

Returns the spatial reference ID associated with the URI.

sslMode

Returns the SSL mode associated with the URI.

table

Returns the table name stored in the URI.

uri

Returns the complete URI as a string.

useEstimatedMetadata

Returns True if estimated metadata should be used for the connection.

username

Returns the username stored in the URI.

wkbType

Returns the WKB type associated with the URI.

Attributes

SslAllow

SslDisable

SslPrefer

SslRequire

SslVerifyCa

SslVerifyFull

staticMetaObject

SslAllow = 2
SslDisable = 1
class SslMode

Bases: int

baseClass

alias of QgsDataSourceUri

SslPrefer = 0
SslRequire = 3
SslVerifyCa = 4
SslVerifyFull = 5
authConfigId(self) str

Returns any associated authentication configuration ID stored in the URI.

Return type:

str

clearSchema(self)

Clears the schema stored in the URI.

connectionInfo(self, expandAuthConfig: bool = True) str

Returns the connection part of the URI.

Parameters:

expandAuthConfig (bool = True) –

Return type:

str

database(self) str

Returns the database name stored in the URI.

Return type:

str

decodeSslMode(sslMode: str) QgsDataSourceUri.SslMode

Decodes SSL mode string into enum value. If the string is not recognized, SslPrefer is returned.

New in version 3.2.

Parameters:

sslMode (str) –

Return type:

QgsDataSourceUri.SslMode

disableSelectAtId(self, flag: bool)

Set to True to disable selection by feature ID.

Parameters:

flag (bool) –

driver(self) str

Returns the driver name stored in the URI

New in version 2.16.

Return type:

str

encodeSslMode(sslMode: QgsDataSourceUri.SslMode) str

Encodes SSL mode enum value into a string.

New in version 3.2.

Parameters:

sslMode (QgsDataSourceUri.SslMode) –

Return type:

str

encodedUri(self) QByteArray

Returns the complete encoded URI as a byte array.

Return type:

QByteArray

geometryColumn(self) str

Returns the name of the geometry column stored in the URI, if set.

Return type:

str

hasParam(self, key: str) bool

Returns True if a parameter with the specified key exists.

Parameters:

key (str) –

Return type:

bool

host(self) str

Returns the host name stored in the URI.

Return type:

str

httpHeader(self, key: str) str

Returns the http header value according to key

New in version 3.26.

Parameters:

key (str) –

Return type:

str

httpHeaders(self) QgsHttpHeaders

Returns http headers

New in version 3.26.

Return type:

QgsHttpHeaders

keyColumn(self) str

Returns the name of the (primary) key column for the referenced table.

Return type:

str

param(self, key: str) str

Returns a generic parameter value corresponding to the specified key.

Parameters:

key (str) –

Return type:

str

parameterKeys(self) Set[str]

Returns parameter keys used in the uri: specialized ones (“table”, “schema”, etc.) or generic parameters.

New in version 3.26.

Return type:

Set[str]

params(self, key: str) List[str]

Returns multiple generic parameter values corresponding to the specified key.

Parameters:

key (str) –

Return type:

List[str]

password(self) str

Returns the password stored in the URI.

Return type:

str

port(self) str

Returns the port stored in the URI.

Return type:

str

quotedTablename(self) str

Returns the URI’s table name, escaped and quoted.

Return type:

str

removeParam(self, key: str) int

Removes a generic parameter by key.

Note

Calling this method removes all the occurrences of key, and returns the number of parameters removed.

Parameters:

key (str) –

Return type:

int

removePassword(aUri: str) str

Removes the password element from a URI.

Parameters:

aUri (str) –

Return type:

str

schema(self) str

Returns the schema stored in the URI.

Return type:

str

selectAtIdDisabled(self) bool

Returns whether the selection by feature ID is disabled.

Return type:

bool

service(self) str

Returns the service name associated with the URI.

Return type:

str

setAuthConfigId(self, authcfg: str)

Sets the authentication configuration ID for the URI.

Parameters:

authcfg (str) –

setConnection(self, aHost: str, aPort: str, aDatabase: str, aUsername: str, aPassword: str, sslmode: QgsDataSourceUri.SslMode = QgsDataSourceUri.SslPrefer, authConfigId: str = '')

Sets all connection related members at once.

setConnection(self, aService: str, aDatabase: str, aUsername: str, aPassword: str, sslmode: QgsDataSourceUri.SslMode = QgsDataSourceUri.SslPrefer, authConfigId: str = ‘’) Sets all connection related members at once (for a service case).

Parameters:
  • aHost (str) –

  • aPort (str) –

  • aDatabase (str) –

  • aUsername (str) –

  • aPassword (str) –

  • sslmode (QgsDataSourceUri.SslMode = QgsDataSourceUri.SslPrefer) –

  • authConfigId (str = '') –

setDataSource(self, aSchema: str, aTable: str, aGeometryColumn: str, aSql: str = '', aKeyColumn: str = '')

Sets all data source related members at once.

The aSql argument represents a subset filter string to be applied to the source, and should take the form of a SQL “where” clause (e.g. “VALUE > 5”, “CAT IN (1,2,3)”).

Parameters:
  • aSchema (str) –

  • aTable (str) –

  • aGeometryColumn (str) –

  • aSql (str = '') –

  • aKeyColumn (str = '') –

setDatabase(self, database: str)

Sets the URI database name.

Parameters:

database (str) –

setDriver(self, driver: str)

Sets the driver name stored in the URI.

New in version 2.16.

Parameters:

driver (str) –

setEncodedUri(self, uri: str)

Sets the complete encoded uri from a string value.

Parameters:

uri (str) –

setGeometryColumn(self, geometryColumn: str)

Sets geometry column name to geometryColumn

New in version 3.10.

Parameters:

geometryColumn (str) –

setHttpHeaders(self, headers: QgsHttpHeaders)

Sets headers to headers

New in version 3.26.

Parameters:

headers (QgsHttpHeaders) –

setKeyColumn(self, column: str)

Sets the name of the (primary) key column.

Parameters:

column (str) –

setParam(self, key: str, value: str)

Sets a generic parameter value on the URI.

Note

If a parameter with the specified key already exists, another is inserted and the existing value is left unchanged.

Parameters:
  • key (str) –

  • value (str) –

setParamList(self, key: str, value: Iterable[str])

Sets a generic parameter list value on the URI.

Note

available in Python as setParamList

Parameters:
  • key (str) –

  • value (Iterable[str]) –

setPassword(self, password: str)

Sets the password for the URI.

Parameters:

password (str) –

setSchema(self, schema: str)

Sets the scheme for the URI.

New in version 2.12.

Parameters:

schema (str) –

setSql(self, sql: str)

Sets the sql filter for the URI.

The sql represents a subset filter string to be applied to the source, and should take the form of a SQL “where” clause (e.g. “VALUE > 5”, “CAT IN (1,2,3)”).

See also

sql()

Parameters:

sql (str) –

setSrid(self, srid: str)

Sets the spatial reference ID associated with the URI.

Parameters:

srid (str) –

setTable(self, table: str)

Sets table to table

New in version 3.10.

Parameters:

table (str) –

setUseEstimatedMetadata(self, flag: bool)

Sets whether estimated metadata should be used for the connection.

Parameters:

flag (bool) –

setUsername(self, username: str)

Sets the username for the URI.

Parameters:

username (str) –

setWkbType(self, type: QgsWkbTypes.Type)

Sets the WKB type associated with the URI.

Parameters:

type (QgsWkbTypes.Type) –

sql(self) str

Returns the SQL filter stored in the URI, if set.

This represents a subset filter string to be applied to the source, and takes the form of a SQL “where” clause (e.g. “VALUE > 5”, “CAT IN (1,2,3)”).

See also

setSql()

Return type:

str

srid(self) str

Returns the spatial reference ID associated with the URI.

Return type:

str

sslMode(self) QgsDataSourceUri.SslMode

Returns the SSL mode associated with the URI.

Return type:

QgsDataSourceUri.SslMode

staticMetaObject = <PyQt5.QtCore.QMetaObject object>
table(self) str

Returns the table name stored in the URI.

Return type:

str

uri(self, expandAuthConfig: bool = True) str

Returns the complete URI as a string.

Parameters:

expandAuthConfig (bool = True) –

Return type:

str

useEstimatedMetadata(self) bool

Returns True if estimated metadata should be used for the connection.

Return type:

bool

username(self) str

Returns the username stored in the URI.

Return type:

str

wkbType(self) QgsWkbTypes.Type

Returns the WKB type associated with the URI.

Return type:

QgsWkbTypes.Type