This library provides classes for manipulating MARC21 formatted records. (Should work for USMARC, etc, too.)
The MARC21 file format standards can be found in the MARC Record Structure document at the Library of Congress MARC site.

This document covers version 1.0.1 October 30,2000.

Version 1.0.1

This version fixes a bug that deals with the repitition of MARC21 fields and subfields. Please be aware that fields (ie. M['450']) can be either a single instance of a MARC21DataField or a list of instances. Similarly with the contents of subfields with in a field. When writing programs that deal with arbitrary MARC21 records, use type checking.

Author and copyright
Written by Nathan Denny. This code is in the public domain. No warranty on correctness.

#--MARC files are inherently sequential. This example will open
#--a MARC file, read each record out of it, check for a pattern in the
#--title (245 subfield 'a') and write matching records to a different file.
import MARC21
import string
while R is not None:
   if string.find('halloween',R['245']['a']):
for R in matchingRecords:
   R['245']['a']='Scary ghosts and goblins'



With data=None this initializes the MARC21Record to an empty state. If data is not None, then the data is used to construct the MARC21Record.
Returns a list of fields that are present in this MARC record.



If data is None, then the MARC21DataField is constructed as a blank field. If data is supplied, then the field is constructed accordingly. This is currently used exclusively by the MARC21Record class.
Returns a list of subfields that are currently in this field.



Opens the specified file for read access.
Reads from the current position in the MARC21File and returns a MARC21Record instance based upon the data in the file. If the file is at EOF, None is returned.
Rewinds n records from the current position, or until BOF, whichever comes first.