It uses the Sinkhorn-Knopp algorithm, which iteratively normalizes the rows and columns of a matrix to 1, until the matrix is doubly stochastic (Sinkhorn, Knopp 1967). It is guaranteed to converge for a non-negative square matrix $A$ if $A \neq 0$, and if $A$ has total support. Matrix $A$ has total support if every positive element of $A$ lies on a positive diagonal. And a positive diagonal of a matrix is defined as, for any permutation of $\sigma = \{1,\dots,N\}$, the sequence $\{ a_{1,\sigma(1)},\dots, a_{N,\sigma(N)} \}$ where all elements are positive (non-zero in this case).
Just pip install sinkhorn_knopp and you’re good to go. Here’s a quick demo: