FWIW you could have done this in far fewer lines of python using a code generator like Cython or Pyrex.<p>that said, learning the intricacies of an extension - and all of the stuff you have to do under the hood like registering handlers, reference counting, cleanup, etc - is a valuable experience.<p>but once you got that done i just recommend you use code generators. it's also a lot easier to maintain.