If you don't know about it, you might find https://pypi.python.org/pypi/NZMATH useful; it's BSD-licensed pure python number theory code.