Use streaming mode for large XML files
masterFor very large XML files, use the streaming mode to maintain a small memory footprint. You can specify an item_depth and an item_callback function that is called whenever an element at that depth is reached.
from gzip import GzipFile
import xmltodict
def handle_artist(_, artist):
print(artist['name'])
return True
# Parse a large gzipped XML file item by item
xmltodict.parse(GzipFile('discogs_artists.xml.gz'),
item_depth=2,
item_callback=handle_artist)