Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (
Help us improve Python packaging - Donate today!

Utility class wrapping lxml for reading data from MODS v3.4 XML metadata into Python data types.

Project Description

pymods 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 other pymods by Matt Cordial.




XML is parsed using either the MODS or OAI class:

mods_records = MODS('some_file.xml')

oai_records = OAI('some_file.xml')

Individual records are stored at the MODS or OAI object in the record_list attribute. These records can be called individually by index number or used as an iterator.

for record in mods_records.record_list:


The MODS class parses records at each mods:mods element. It will work with mods:modsCollection documents, outputs from OAI-PMH feeds, or individual MODSXML documents with mods:mods as the root element.

When parsing only a single record, the MODS and OAI classes will still store the record in the record_list attribute. Accessing the record will still require calling the object as an iterator or by list index.


The OAI class can be used with the output from OAI-PMH feeds or repox exports. oai_dc:record elements are parsed as the record root elements in documents in the oai_dc namespace. Documents in the repox namespace are parsed using repox:record as the record root element.


All functions return data either as a string, list, or dict. See the appropriate docstrings for details.


Methods in the FSUDL class are helper functions specific to Florida State University’s DigiNole and might not apply to records from other sources.



from pymods import MODS, FSUDL, OAI

Parsing a file

>>> mods = MODS('example.xml')

>>> len(mods.record_list)

Simple tasks

Generating a title list

In [14]: for record in mods.record_list:
   ....:     print(MODS.title_constructor(record))
['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 list

In [17]: for record in mods.record\_list:
   ....: for subject in MODS.subject\_constructor(record):
   ....: print(subject)
Concert halls
Architectural drawings
Structural systems
Structural systems drawings
Structural drawings
Safety equipment
Structural optimization
Architectural design
Fire prevention--Safety measures
Tax payers
Tax collection
Sex discrimination against women
Women's rights
Equal rights amendments
Women--Societies and clubs
National Organization for Women
Release History

Release History

This version
History Node


Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting