Improved Python template to support type attribute