Add Python implementation.

Definitely not thoroughly tested.