python: export a __getitem__ function

Additionally, introduce templates in the python exporter code