do it is to use the elementtree iterparse(function here is an example of iteratively processing nodes in the previous filefrom xml etree elementtree import iterparse iparse iterparse("music xml"['start','end']find the top-level music element for eventelem in iparseif event ='startand elem tag ='music'musicnode elem break get all albums albums (elem for eventelem in iparse if event ='endand elem tag ='album'for album in albumsdo some kind of processing musicnode remove(albumthrow away the album when done the key to using iterparse(effectively is to get rid of data that you're no longer using the last statement musicnode remove(albumis throwing away each element after we are done processing it (by removing it from its parentif you monitor the memory footprint of the previous programyou will find that it stays low even if the input file is massive notes the elementtree module is by far the easiest and most flexible way of handling simple xml documents in python howeverit does not provide lot of bells and whistles for examplethere is no support for validationnor does it provide any apparent way to handle complex aspects of xml documents such as dtds for these thingsyou'll need to install third-party packages one such packagelxml etree (at the popular libxml and libxslt libraries and provides full support for xpathxsltand other features the elementtree module itself is third-party package maintained by fredrik lundh at versions that are more modern than what is included in the standard library and which offer additional features xml sax the xml sax module provides support for parsing xml documents using the sax api parse(filehandler [error_handler]parses an xml documentfile file is either the name of file or an open file object handler is content handler object error_handler is an optional sax errorhandler object that is described further in the online documentation parsestring(stringhandler [error_handler]the same as parse(but parses xml data contained in string instead lib fl ff