I know that you're looking for an answer that uses QGIS but if you're willing to use the open-source GIS Whitebox Geospatial Analysis Tools instead, then here is a complete answer that will take any shapefile, and create a new attribute field in its table that contains the number of feature parts. You simply need to open the Scripter window in Whitebox, change the script language to Groovy, and paste the following code in:
import whitebox.geospatialfiles.ShapeFile
import whitebox.geospatialfiles.shapefile.*
import whitebox.geospatialfiles.shapefile.attributes.*
def inputFileName = "/MY_DIRECTORY/MY_FILE_NAME.shp"
def shape = new ShapeFile(inputFileName)
AttributeTable table = shape.getAttributeTable()
DBFField field = new DBFField()
field.setName("NUM_PARTS")
field.setDataType(DBFField.DBFDataType.NUMERIC)
field.setFieldLength(5)
field.setDecimalCount(0)
table.addField(field)
for (int i = 0; i < shape.getNumberOfRecords(); i++) {
ShapeFileRecord record = shape.getRecord(i)
int numParts = record.getGeometry().getParts().length
recData = table.getRecord(i)
recData[recData.length - 1] = new Double(numParts)
table.updateRecord(i, recData)
}
println("I'm done")
You'll need to update the value of the inputFileName variable near the top to point it to your file. You could also use Python to achieve the same thing, but I wrote this in Groovy. If you like, I can also have the script exclude hole parts if you are working with polygons.
Here's an example of a world country map that has been rendered to show the number of parts each country's polygon feature includes: