Package: pymods
pymodspymods is utility module for working with the Library of Congress’s MODS
XML standard: Metadata Description Schema (MODS). It is a utility
wrapper for the lxml module specific to deserializing data out of
MODSXML into python data types.If you need a module to serialize data into MODSXML, see the otherpymods by Matt Cordial.InstallingRecommended:pip install pymodsUsingBasicsXML is parsed using the MODSReader class:mods_records =pymods.MODSReader('some_file.xml')Individual records are stored as an iterator of the MODSRecord object:In[5]:forrecordinmods_records:....:print(record)....:<Element{http://www.loc.gov/mods/v3}modsat0x47a69f8><Element{http://www.loc.gov/mods/v3}modsat0x47fd908><Element{http://www.loc.gov/mods/v3}modsat0x47fda48>MODSReader will work withmods:modsCollectiondocuments, outputs
from OAI-PMH feeds, or individual MODSXML documents withmods:modsas the root element.pymods.MODSRecordThe MODSReader class parses eachmods:modselement into a
pymods.MODSRecord object. pymods.MODSRecord is a custom wrapper class
for the lxml.ElementBase class. All children of pymods.Record inherit
the lxml._Element and lxml.ElementBase methods.In[6]:record=next(pymods.MODSReader('example.xml'))In[7]:print(record.nsmap){'dcterms':'http://purl.org/dc/terms/','xsi':'http://www.w3.org/2001/XMLSchema-instance',None:'http://www.loc.gov/mods/v3','flvc':'info:flvc/manifest/v1','xlink':'http://www.w3.org/1999/xlink','mods':'http://www.loc.gov/mods/v3'}In[8]:forchildinrecord.iterdescendants():....:print(child.tag){http://www.loc.gov/mods/v3}identifier{http://www.loc.gov/mods/v3}extension{info:flvc/manifest/v1}flvc{info:flvc/manifest/v1}owningInstitution{info:flvc/manifest/v1}submittingInstitution{http://www.loc.gov/mods/v3}titleInfo{http://www.loc.gov/mods/v3}title{http://www.loc.gov/mods/v3}name{http://www.loc.gov/mods/v3}namePart{http://www.loc.gov/mods/v3}role{http://www.loc.gov/mods/v3}roleTerm{http://www.loc.gov/mods/v3}roleTerm{http://www.loc.gov/mods/v3}typeOfResource{http://www.loc.gov/mods/v3}genre...MethodsAll functions return data either as a string, list, list of named
tuples. See theAPI documentationor appropriate docstring for details.>>>record.genre?Type:propertyStringform:<propertyobjectat0x0000000004812C78>Docstring:Accessesmods:genreelement.:return:AlistcontainingGenreelementswithterm,authority,authorityURI,andvalueURIattributes.ExamplesImportingfrompymodsimportMODSReader,MODSRecordParsing a fileIn[10]:mods=MODSReader('example.xml')In[11]:forrecordinmods:....:print(record.dates)....:[Date(text='1966-12-08',type='{http://www.loc.gov/mods/v3}dateCreated')]None[Date(text='1987-02',type='{http://www.loc.gov/mods/v3}dateIssued')]Simple tasksGenerating a title listIn[14]:forrecordinmods:....:print(record.titles)....:['Fire Line System']['$93,668.90. One Mill Tax Apportioned by Various Ways Proposed']['Broward NOW News: National Organization for Women, February 1987']Creating a subject listIn[17]:forrecordinmods:....:forsubjectinrecord.subjects:....:print(subject.text)....:ConcerthallsArchitectureArchitecturaldrawingsStructuralsystemsStructuralsystemsdrawingsStructuraldrawingsSafetyequipmentConstructionMechanicsStructuraloptimizationArchitecturaldesignFireprevention--SafetymeasuresTaxesTaxpayersTaxcollectionOrganizationsFeminismSexdiscriminationagainstwomenWomen's rightsEqualrightsamendmentsWomen--SocietiesandclubsNationalOrganizationforWomenMore complex tasksCreating a list of subject URI’s only for LCSH subjectsIn[18]:forrecordinmods:....:forsubjectinrecord.subjects:....:if'lcsh'==subject.authority:....:print(subject.uri)....:http://id.loc.gov/authorities/subjects/sh85082767http://id.loc.gov/authorities/subjects/sh88004614http://id.loc.gov/authorities/subjects/sh85132810http://id.loc.gov/authorities/subjects/sh85147343Get URLs for objects using a No Copyright US rightsstatement.org URIIn[23]:forrecordinmods:....:forrights_eleminrecord.rights....:ifrights_elem.uri=='http://rightsstatements.org/vocab/NoC-US/1.0/':....:print(record.purl)....:http://purl.flvc.org/fsu/fd/FSU_MSS0204_B01_F10_09http://purl.flvc.org/fsu/fd/FSU_MSS2008003_B18_F01_004