Skip to main content

mets_to_edm

mets_to_edm is a Python library for converting METS/MODS XML records into Europeana Data Model (EDM) records. It can be used both as a library and from the command line and has a basic Mapping that should work well for most cases. But the library also provides a flexible mapping layer to override certain parts.

Features

  • Converts METS/MODS XML to EDM using edmlib
  • Easily extensible: override mapping methods to customize output
  • CLI and Python API

Installation

Install via Poetry (recommended):

poetry install

Or with pip (if you have all dependencies):

pip install .

Usage

As a Python Library

from mets_to_edm import MetsToEdmMapper
from lxml import etree

# Parse your METS/MODS XML file
xml_tree = etree.parse("example.xml")

# Convert to an EDM record
edmlib_record = MetsToEdmMapper.process_record(xml_tree)

# Serialize to EDM XML
edm_xml = edmlib_record.serialize()
print(edm_xml)

From the Command Line

python -m mets_to_edm example.xml "Provider Name" [--data-provider "Data Provider"]
  • "Provider Name": the institution name to be filled in as edm:provider (the aggregator providing the data to europeana)
  • "Data Provider": the institution name to be filled in as edm:dataProvider (the Organisation where the data originates from). Optional as it will otherwise be extracted from the amdSec using XPath "mets:rightsMD/mets:mdWrap/mets:xmlData/dv:rights/dv:owner"

Customizing the Mapping

To change how specific fields are mapped, subclass MetsToEdmMapper and override the relevant class methods. For example, you can override any method such as:

  • get_titles
  • get_descriptions
  • get_publishers
  • get_types
  • get_languages
  • ...and more (see mets_to_edm/mapper.py for all available hooks)

Example: Overriding the Data Provider

class MyMapper(MetsToEdmMapper):
	@classmethod
	def get_data_provider(cls, dmd_sec, amd_sec, default=None):
		return "My Custom Data Provider"

# Usage:
# edmlib_record = MyMapper.process_record(tree)

Example: Including all URLs for IIIF Resources

By default, only the first image URL is included if an IIIF manifest is present. To include all URLs, you can override the relevant mapping method or adjust the only_first_image_if_iiif_manifest parameter.

class MyMapper(MetsToEdmMapper):
    @classmethod
    def get_webresource_urls(
        cls,
        amd_sec,
        physical_div,
        logical_div,
        file_sec,
        context_objects,
        dmd_sec,
        only_first_image_if_iiif_manifest=True,
    ):
        return super().get_webresource_urls(
            amd_sec,
            physical_div,
            logical_div,
            file_sec,
            context_objects,
            dmd_sec,
            only_first_image_if_iiif_manifest=False,
        )

# Usage:
# edmlib_record = MyMapper.process_record(tree)

For more examples have a look at the examples directory.

Further Information

  • See the source code in mets_to_edm/mapper.py for all overridable methods and mapping logic.
  • For questions or contributions, open an issue or pull request.

Metadata

Release files for mets-to-edm 0.2.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mets-to-edm 0.2.10
File Size Uploaded
mets_to_edm-0.2.10.tar.gz 12.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mets-to-edm 0.2.10
File Interpreter ABI Platform
mets_to_edm-0.2.10-py3-none-any.whl Python 3 none any Details

Total release size: 24.0 kB

Release files / mets_to_edm-0.2.10.tar.gz

Download URL mets_to_edm-0.2.10.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
171a702571f318ec39c69aaecf8fc193c8b8d43b55078d043469d7ac0bdb0237
BLAKE2b-256 checksum
How to use checksums
8698e1f6ef0ae006faf54d50ab3c0f5d735e0236cdda6cfa3d4edc11ae03c61c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.0 CPython/3.12.9 Linux/6.17.0-1022-azure

Release files / mets_to_edm-0.2.10-py3-none-any.whl

Download URL mets_to_edm-0.2.10-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac653b0d565f16b9e1bc17b178625745fefbe3f9825475fcec3a741c2c01eb41
BLAKE2b-256 checksum
How to use checksums
e9f3b4f7e7a2dc80b48342ca8cf6f8f5b4a74d547ac45ceae454aa7329e965d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.0 CPython/3.12.9 Linux/6.17.0-1022-azure

Release history Release notifications | RSS feed

0.2.11

2 release files

This release

0.2.10 This release

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page