fname = 'streamed.xml'
with open(fname, 'w') as f:
    with etree.xmlfile(f) as xf:
        attribs = {'tag': 'bagggg', 'text': 'att text', 'published': 'now'}
with xf.element('root', attribs):
    xf.write('root text\n')
for i in range(10):
    rec = etree.Element('record', id=str(i))
rec.text = 'record text data'
xf.write(rec)
Как быстро передать вывод XML из Python