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_titlesget_descriptionsget_publishersget_typesget_languages- ...and more (see
mets_to_edm/mapper.pyfor 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.pyfor 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.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mets_to_edm-0.2.11.tar.gz | 12.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mets_to_edm-0.2.11-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.0 kB
Release files / mets_to_edm-0.2.11.tar.gz
| Download URL | mets_to_edm-0.2.11.tar.gz |
|---|---|
| Size | 12.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9ca437a561dd46afe87040a679c26d65df2c89910bddb8a7bdd2feba4b869057
|
|
BLAKE2b-256 checksum How to use checksums |
b70183c01d93b2bd94b4b7e60f64b9ea53dc1b760b18bd2d233fb77c48a292be
|
| 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.11-py3-none-any.whl
| Download URL | mets_to_edm-0.2.11-py3-none-any.whl |
|---|---|
| Size | 12.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
296ce1a61cda8558f3436290e7cb3a6d57e75f1d22698f49de24a3d92d09d62e
|
|
BLAKE2b-256 checksum How to use checksums |
cd2cb7b9f443c8849289efa09d5283b872c1e161e0e0b4ad0cf052c489a65c1b
|
| 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
|