Example:
from qgis.core import edit
with edit(layer):
f=layer.getFeatures().next()
f[0]=5
layer.updateFeature(f)
This will automatically call commitChanges() in the end. If any exception occurs, it will rollBack() all the changes.
This feature was developed by: Matthias Kuhn at OpenGIS