Topological indices (TI) are algebraic invariants of molecular graphs representing the topology of a molecule, which are very valuable in quantitative structure–property relations (QSPR). Here we prove that TI are the partition functions of such molecules when the temperature of the thermal bath at which they are submerged is very high. These partition functions are obtained by describing molecular electronic properties through tight-binding Hamiltonians (TBH), where the hopping parameters are topological properties describing atom–atom interactions. We prove that the TBH proposed here are non-Hermitian diagonalizable Hamiltonians which can be replaced by symmetric ones. In this way we propose a statistical–mechanical theory for TI, which is exemplified by deriving the Randić, Zagreb, Balaban, Wiener and ABC indices. The work also illuminates how to improve QSPR models using the current theoretical framework as well as how to derive statistical–mechanical parameters of molecular graphs.