Python implementation

@lepture Please review.