You may want to include reference to the unregister method when cleaning up. // For all your user defined functions if QgsExpression.isFunctionName("$<name>"): QgsExpression.unregisterFunction("$<name>")