How to obtain clusters of hierarchical heatmap when using Python?
Clustering like this is typically done with scipy. Here's the code we use in deepTools (original context here):

from scipy.cluster.hierarchy import fcluster, linkage
Z = linkage(some_matrix)  # You might want to set `method` and `metric`
groups = fcluster(Z, nGroups)  # You might want to set `criterion`


groups is then a vector containing the group assignment of the input matrix according to the clustering. As an aside, this is exactly the same as what's shown in the last link in your post, so I'm not sure how you didn't find it.

BTW, at least in python, hierarchical clustering is painfully slow with large datasets.