A library for Monte Carlo simulations on square and cubic lattices