I have found the answer reading the QGIS API
There areThis is the method:
void QgsDataSourceURI::setKeyColumn (QString column ) this is my example:
uri = QgsDataSourceURI() uri.setConnection('localhost', '5432', '-mydatabase-', '-myowner-', '-mypasswd-') uri.setDataSource('public', 'parcelas', 'the_geom') #public: schema, parcelas: the view, the_geom: spatial column uri.setKeyColumn('id') #name of my primary key vlayer = QgsVectorLayer(uri.uri(), '-name_of_the_layer-', 'postgres') if vlayer: print "All Ok!" QgsMapLayerRegistry.instance().addMapLayer(vlayer)