Those connections and their info are stored in a QgsSettings
-Object (which is a fancy wrapper around a standard QT QSettings object, see the docs at https://qgis.org/pyqgis/master/core/QgsSettings.html and https://doc.qt.io/qt-5/qsettings.html ).
As far as I know, there is no other way, as the QgsSettings
is the only place where the connections are stored.
edit: You may get some info using
for p in QgsApplication.dataItemProviderRegistry().providers():
print(p.name())
You can explore the QgsSettings interactively to find the correct setting string like this (lifted and adapted from this answer to a different question: https://gis.stackexchange.com/a/434438/15183 ).
s = QgsSettings()
for k in s.allKeys():
if(k.lower().find("wms")>0): # replace wms with what string you want to search for in the settings
print(k)
If you want to list all keys in a group, use
s = QgsSettings()
s.beginGroup("qgis/connections-xyz")
print(s.allKeys())
This is all done to get the correct setting name.
To get the setting value using
s.value("qgis/connections-xyz/OpenStreetMap/url")
# returns 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'
Note that the setting name you pass to value
is relative to any group your QgsSettings object might "be inside of" after you called beginGroup
.
For example, both snippets return the same string:
s1 = QgsSettings()
v1 = s1.value("qgis/connections-xyz/OpenStreetMap/url")
s2 = QgsSettings()
s2.beginGroup("qgis/connections-xyz")
v2 = s2.value("OpenStreetMap/url")
print(v1==v2) #True
To get a list of XYZ connections without their sub-values use
s = QgsSettings()
s.beginGroup("qgis/connections-xyz")
s.childGroups()
# returns ['Mapzen Global Terrain', 'OpenStreetMap'] for me
It really is not that intimidating if you play around with it for some time.