Python 3 support

This PR adds Python 3 support alongside Python 2 support, in a single codebase.