Skip to main content

Crate mrrc

Crate mrrc 

Source
Expand description

§MRRC: MARC Rust Crate

Tests Lint Build codecov CodSpeed

A Rust library for reading, writing, and manipulating MARC bibliographic records, with Python bindings.

Note: This project was developed using agentic coding tools (amp and Claude) and uses beads for agentic issue tracking. The package has not yet had extensive practical testing by humans and should be considered experimental.

§Features

  • Reads and writes ISO 2709 (MARC21) binary format
  • Python bindings with pymarc-compatible API (minor differences documented)
  • Multiple serialization formats: JSON, MARCXML, MARCJSON, CSV, Dublin Core, MODS, BIBFRAME
  • MARC-8 and UTF-8 character encoding support
  • Benchmarked at ~4x pymarc throughput in Python, ~1M records/sec in Rust

§Installation

Python (3.10+):

pip install mrrc
# or with uv:
uv add mrrc

Rust:

cargo add mrrc

§Example

Python:

from mrrc import MARCReader

# Pass filename directly for best performance (releases GIL)
for record in MARCReader("records.mrc"):
    print(record.title())

File paths use pure Rust I/O, releasing Python’s GIL for multi-threaded workloads. See the threading guide for details.

Rust:

use mrrc::MarcReader;
use std::fs::File;

let file = File::open("records.mrc")?;
let mut reader = MarcReader::new(file);
while let Some(record) = reader.read_record()? {
    if let Some(title) = record.title() {
        println!("{}", title);
    }
}

§Documentation

§Format Support

FormatReadWrite
ISO 2709YesYes
JSONYesYes
MARCJSONYesYes
MARCXMLYesYes
CSV-Yes
Dublin Core-Yes
MODSYesYes
BIBFRAMEYesYes

Full format reference

§Platforms

Pre-built Python wheels are available for:

PlatformArchitectures
Linuxx86_64, aarch64, i686
macOSx86_64 (Intel), arm64 (Apple Silicon)
Windowsx64

§Status

Experimental. The Python API aims for pymarc compatibility but has some differences; see the migration guide. Rust APIs may change between minor versions.

§Roadmap

Version 0.7.0 is suitable for testing but remains experimental. Before a 1.0 release, we plan to complete:

  1. Real-world data testing — Validate against large-scale MARC datasets from LOC, Internet Archive, and other sources to discover edge cases
  2. Code review — Thorough review of the codebase, particularly the Rust core and PyO3 bindings
  3. Performance analysis — Profile with production workloads, optimize bottlenecks, and update benchmark documentation

§License

MIT

§MRRC: MARC Rust Crate

A high-performance Rust library for reading, writing, and manipulating MARC bibliographic records in the ISO 2709 binary format.

§Quick Start

§Reading MARC Records

use mrrc::MarcReader;
use std::fs::File;

let file = File::open("records.mrc")?;
let mut reader = MarcReader::new(file);

while let Some(record) = reader.read_record()? {
    if let Some(title) = record.title() {
        println!("Title: {}", title);
    }
}

§Creating and Writing MARC Records

use mrrc::{MarcWriter, Record, Field, Leader};

let mut record = Record::new(Leader::default());
record.add_control_field("001".to_string(), "12345".to_string());

let mut field = Field::new("245".to_string(), '1', '0');
field.add_subfield('a', "Test Title".to_string());
record.add_field(field);

let mut buffer = Vec::new();
{
    let mut writer = MarcWriter::new(&mut buffer);
    writer.write_record(&record)?;
}

§Using Helper Methods

use mrrc::{Record, Leader, Field};

let mut record = Record::new(Leader::default());

let mut field_245 = Field::new("245".to_string(), '1', '0');
field_245.add_subfield('a', "The Great Gatsby".to_string());
field_245.add_subfield('c', "F. Scott Fitzgerald".to_string());
record.add_field(field_245);

// Use convenience methods
assert_eq!(record.title(), Some("The Great Gatsby"));
assert_eq!(record.is_book(), true);

§Modules

  • record — Core MARC record structures (Record, Field, Subfield)
  • reader — Reading MARC records from binary data streams
  • writer — Writing MARC records to binary format
  • formats — Format traits and ISO 2709 support
  • bibframe — BIBFRAME linked data conversion
  • boundary_scanner — Record boundary detection for parallel processing
  • leader — MARC record leader (24-byte header)
  • json — JSON serialization/deserialization
  • marcjson — MARCJSON format (standard JSON-LD format for MARC)
  • marcxml — MARCXML serialization/deserialization
  • csv — CSV (Comma-Separated Values) export format
  • dublin_core — Dublin Core metadata serialization
  • mods — MODS (Metadata Object Description Schema) bidirectional conversion
  • encoding — Character encoding support (MARC-8 and UTF-8)
  • error — Error types and result type

§Format Support

  • ISO 2709 Binary Format — The standard MARC interchange format
  • BIBFRAME — LOC linked data format for bibliographic description
  • JSON — Generic JSON representation of records
  • MARCJSON — Standard JSON-LD format for MARC records
  • MARCXML — Standard LOC MARCXML with proper attributes and namespace
  • CSV — Tabular export format for spreadsheet applications
  • Dublin Core — Simplified metadata schema for discovery
  • MODS — Detailed metadata description schema for libraries
  • Character Encodings — MARC-8 and UTF-8 with automatic detection

Re-exports§

pub use authority_queries::AuthorityQueries;
pub use authority_reader::AuthorityMarcReader;
pub use authority_record::AuthorityRecord;
pub use authority_record::AuthorityRecordBuilder;
pub use authority_record::HeadingType;
pub use authority_record::KindOfRecord;
pub use authority_record::LevelOfEstablishment;
pub use authority_writer::AuthorityMarcWriter;
pub use bibliographic_helpers::IsbnValidator;
pub use bibliographic_helpers::PublicationInfo;
pub use encoding_validation::EncodingAnalysis;
pub use encoding_validation::EncodingValidator;
pub use error::MarcError;
pub use error::Result;
pub use field_linkage::LinkageInfo;
pub use field_query::FieldQuery;
pub use field_query::SubfieldPatternQuery;
pub use field_query::SubfieldValueQuery;
pub use field_query::TagRangeQuery;
pub use field_query_helpers::FieldQueryHelpers;
pub use format_queries::AuthoritySpecificQueries;
pub use format_queries::BibliographicQueries;
pub use format_queries::HoldingsSpecificQueries;
pub use holdings_reader::HoldingsMarcReader;
pub use holdings_record::AcquisitionStatus;
pub use holdings_record::Completeness;
pub use holdings_record::HoldingsRecord;
pub use holdings_record::HoldingsRecordBuilder;
pub use holdings_record::HoldingsType;
pub use holdings_record::MethodOfAcquisition;
pub use holdings_writer::HoldingsMarcWriter;
pub use leader::Leader;
pub use marc_record::MarcRecord;
pub use producer_consumer_pipeline::PipelineConfig;
pub use producer_consumer_pipeline::PipelineError;
pub use producer_consumer_pipeline::ProducerConsumerPipeline;
pub use reader::MarcReader;
pub use record::Field;
pub use record::FieldBuilder;
pub use record::Record;
pub use record::RecordBuilder;
pub use record::Subfield;
pub use record_builder_generic::GenericRecordBuilder;
pub use record_helpers::RecordHelpers;
pub use record_validation::RecordStructureValidator;
pub use recovery::RecoveryContext;
pub use recovery::RecoveryMode;
pub use validation::IndicatorValidator;
pub use writer::MarcWriter;

Modules§

authority_queries
Authority control helper methods and queries.
authority_reader
Reading MARC Authority records from binary streams.
authority_record
MARC Authority Record structures and utilities.
authority_writer
Writing MARC Authority records to binary format.
bibframe
BIBFRAME conversion for MARC records.
bibliographic_helpers
Bibliographic helper utilities for MARC records.
boundary_scanner
Record boundary detection using 0x1D delimiters for parallel processing.
csv
CSV serialization of MARC records.
dublin_core
Dublin Core serialization of MARC records.
encoding
Character encoding support for MARC records.
encoding_validation
Encoding detection and validation for MARC records.
error
Error types for MARC operations.
field_collection
Field collection traits for managing MARC record field collections.
field_linkage
Field linkage support for MARC 880 (Alternate Graphical Representation) fields.
field_query
Advanced field query patterns for MARC records.
field_query_helpers
Convenience helper methods for advanced field queries.
format_queries
Format-specific query traits for different MARC record types.
formats
Multi-format support with unified Reader/Writer traits.
holdings_reader
Reading MARC Holdings records from binary streams.
holdings_record
MARC Holdings Record structures and utilities.
holdings_writer
Writing MARC Holdings records to binary format.
json
JSON serialization and deserialization of MARC records.
leader
MARC record leader parsing and manipulation.
macros
Macros for code generation in MARC record types.
marc8_tables
MARC-8 character set tables and mappings.
marc_record
Core trait for all MARC record types.
marcjson
MARCJSON serialization and deserialization of MARC records.
marcxml
MARCXML serialization and deserialization of MARC records.
mods
MODS (Metadata Object Description Schema) conversion for MARC records.
producer_consumer_pipeline
Producer-Consumer Pipeline with Backpressure
rayon_parser_pool
Parallel MARC record parsing using Rayon.
reader
Reading MARC records from binary streams.
record
Core MARC record structures (Record, Field, Subfield) MARC bibliographic record structures and operations.
record_builder_generic
Generic builder for all MARC record types.
record_helpers
Helper methods for accessing common bibliographic fields.
record_validation
Validation of MARC record structure and integrity.
recovery
Recovery strategies for malformed and truncated MARC records.
validation
Indicator and field validation for MARC records.
writer
Writing MARC records to binary format.

Macros§

define_field_accessors
Macro to generate add/get accessor methods for a field collection.
filtered_field_accessor
Macro to generate filtered accessor methods for a field collection by tag.