Expand description
§MRRC: MARC Rust Crate
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 mrrcRust:
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
| Format | Read | Write |
|---|---|---|
| ISO 2709 | Yes | Yes |
| JSON | Yes | Yes |
| MARCJSON | Yes | Yes |
| MARCXML | Yes | Yes |
| CSV | - | Yes |
| Dublin Core | - | Yes |
| MODS | Yes | Yes |
| BIBFRAME | Yes | Yes |
§Platforms
Pre-built Python wheels are available for:
| Platform | Architectures |
|---|---|
| Linux | x86_64, aarch64, i686 |
| macOS | x86_64 (Intel), arm64 (Apple Silicon) |
| Windows | x64 |
§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:
- Real-world data testing — Validate against large-scale MARC datasets from LOC, Internet Archive, and other sources to discover edge cases
- Code review — Thorough review of the codebase, particularly the Rust core and
PyO3bindings - Performance analysis — Profile with production workloads, optimize bottlenecks, and update benchmark documentation
§License
MIT
§Links
§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 streamswriter— Writing MARC records to binary formatformats— Format traits and ISO 2709 supportbibframe— BIBFRAME linked data conversionboundary_scanner— Record boundary detection for parallel processingleader— MARC record leader (24-byte header)json— JSON serialization/deserializationmarcjson— MARCJSON format (standard JSON-LD format for MARC)marcxml— MARCXML serialization/deserializationcsv— CSV (Comma-Separated Values) export formatdublin_core— Dublin Core metadata serializationmods— MODS (Metadata Object Description Schema) bidirectional conversionencoding— 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.