this is the code i have in web2py
def makertf():
import gluon.contrib.pyrtf as q
doc=q.Document()
section=q.Section()
doc.Sections.append(section)
section.append(500)
section.append(200)
response.headers['Content-Type']='text/rtf'
return q.dumps(doc)

