How to compute the centroid of a mesh without using Blender's built-in functions?

I do not want to use Blender’s built-in functions for computing centroids as explained here as it seems that they do not give me the kind of centroid I expect to get. I want to compute a new centroid for my meshes given the following description. First, I want to compute the centers of faces (triangle) of a mesh centroid of a mesh. Then I need to compute the faces area. The new centroid is the average of the mesh faces’ centers, weighted by their area. How can I do this using Blender’s Python API?

I think geometry data for mesh objects is stored as a collection of lists or something similar, so you could iterate through them with a for loop. There’s some example code in this question:

The area centroid is:

Xc = sum(areax)/sum(area)
Yc = sum(area
y)/sum(area)…etc

x is the distance along x from origin to centroid of area.