Python api library update.

Rewrite of python library.