The QGIS expression engine is able to do this using the
QgsFeatureRequest.setFilterExpression( unicode ) method (Since QGIS 2.2)
request = QgsFeatureRequest().setFilterExpression( u'"Counties" = \'Norwich\'' )
it = l.getFeatures( request )
Starting with QGIS 2.10 it is even possible that filtering in such a way will give you some extra performance over other types of filtering (like python implementations).
Basically this applies if the following three conditions are met:
You are using a layer with the postgis provider At the moment (2.16) many more than just postgis provider implement this (spatialite, ogr, oracle...).
- Your expression is not overly complicated (things like
NOT NULL ... are supported)
- You have enabled this feature in Settings > Options > Data Sources > Data Source Handling > Execute expression on postgres server-side
- The performance benefit is optimal with appropriate indexes on the database tables
With QGIS 3.0 it is even possible to simply do
features = l.getFeatures('"Counties" = \'Norwicth\'')