Python - Serialize Templates