I need to get values from non spatial table in geopackage via Python. Do You have any ideas how to get this? I'm trying get this using spatialite3 library and simple string select query but I have receive error message "there is no table_name in database" When I'm trying get this from qgis layer list I can't find appropriate way to do this. I'm trying this:

database = r'path_to_my_geopackage.gpkg'
uri = QgsDataSourceUri()

schema = ''
table = 'tablename'
geomColumn = ''

content = uri.setDataSource(schema,table,geomColumn)

1 Answer 1


You can read tables from a Geopackage using the QgsVectorLayer interface instead of the database interface. Construct a path with a layername option:

contacts = QgsVectorLayer("test.gpkg|layername=contacts","contacts","ogr")
#  True

And just to check its read the right table:

[f.name() for f in contacts.fields()]
# ['contact_id', 'first_name', 'last_name', 'email', 'phone']

Then use the usual QGIS operations on attribute tables to get the values you want. Each row is a "feature", but with no geometry.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.