Skip to main content

Python library for generating metadata records

Project description

BAS Metadata Library

Python library for generating metadata records.

Overview

The BAS Metadata Library is an underpinning library for other tools and applications to generate discovery and administrative level metadata records (describing products, services and other resources, and their management).

This library is intended to avoid duplicating complex and verbose encode/decoding logic across projects and ensure interoperability between and within systems.

The library supports a lossless, two-way, conversion between a Configuration Object (a python dict representing the fields/structure of a record for a standard) into its formal representation (typically an XML document)

The library also supports validating record configurations (via JSON Schemas) and formal representations (typically via XML XSDs).

[!NOTE] This project is focused on needs within the British Antarctic Survey. It has been open-sourced in case parts are of interest to others. Some resources, indicated with a '🛡' or '🔒' symbol, can only be accessed by BAS staff or project members respectively. Contact the Project Maintainer to request access.

Supported standards

Standard Implementation Status Library Namespace Introduced In Retired In
ISO 19115:2003 ISO 19139:2007 Supported bas_metadata_library.standards.iso_19115_0_v1 #46 🛡️ -
ISO 19115-2:2009 ISO 19139-2:2012 Supported bas_metadata_library.standards.iso_19115_2_v1 #50 🛡️ -
IEC 61174:2015 IEC 61174:2015 Retired - #139 🛡️ #266 🛡️
IEC PAS 61174:2021 IEC PAS 61174:2021 Retired - #139 🛡️ #266 🛡️

[!NOTE] From v0.11.0 of this library, the ISO 19115:2003 standard revision is referred to as ISO-19115-0 (iso_19115_0). Prior to this version, it was (incorrectly) referred to as ISO-19115-1 (iso_19115_1).

To avoid confusion, when the ISO 19115-1:2014 standard is implemented, it will be referred to as ISO-19115-3 (iso_19115_3).

Supported profiles

Standard Profile Introduced In Status
ISO 19115 MAGIC Discovery Metadata V1 #250 Stable
ISO 19115 MAGIC Discovery Metadata V2 #250 Experimental
ISO 19115 MAGIC Administration Metadata V1 #250 Experimental

Supported configuration versions

Standard Profile Configuration Version Status Notes
IEC 61174:2015 - v1 Retired No longer supported
IEC PAS 61174:2021 - v1 Retired No longer supported
ISO 19115:2003 - v1 Retired Replaced by v2, no longer supported
ISO 19115:2003 - v2 Retired Replaced by v3, no longer supported
ISO 19115:2003 - v3 Retired Replaced by v4, no longer supported
ISO 19115:2003 - v4 Stable Currently supported version
ISO 19115-2:2009 - v1 Retired Replaced by v2, no longer supported
ISO 19115-2:2009 - v2 Retired Replaced by v3, no longer supported
ISO 19115-2:2009 - v3 Retired Replaced by v4, no longer supported
ISO 19115-2:2009 - v4 Stable Currently supported version
ISO 19115-2:2009 MAGIC Discovery Metadata V1 v1 Stable Currently supported version
ISO 19115-2:2009 MAGIC Discovery Metadata V2 v1 Experimental Next supported version
MAGIC Administration Metadata V1 (Content) - v1 Experimental Next supported version
ISO 19115-2:2009 MAGIC Administration Metadata V1 (Encoding) v1 Experimental Next supported version

Supported standards coverage

This library is limited to the standards, and subset of elements within these standards, needed for tools and use-cases within the British Antarctic Survey (BAS) and the NERC Polar Data Centre (UK PDC).

[!TIP] Additions enabling this library to support other use-cases are welcome as contributions, providing they do not add significant complexity or maintenance.

Standard Coverage Coverage Summary
ISO 19115:2003 Good All mandatory elements are supported with a good number of commonly used additional elements
ISO 19115-2:2009 Minimal No elements from this extension are supported, with the exception of the root element

[!NOTE] ISO 19115 extensions (i.e. gmd:metadataExtensionInfo elements) are not supported.

Installation

Installed from PyPi:

$ pip install bas-metadata-library

[!TIP] On Windows, it's recommended to use UV to use a Python version covered by pre-built lxml wheels to avoid building packages from source.

Installation dependencies

This package depends on these OS level libraries for XML encoding and decoding:

  • libxml2
  • libxslt

This package depends on these OS level binaries for XML validation:

  • xmllint

These libraries may already be installed, or require additional OS packages:

Operating System Required Packages
Linux (Alpine) libxslt-dev, libxml2-utils
Linux (Debian) libxml2-utils

Usage

[!TIP] See Usage documentation for further usage examples, including setting and loading administration metadata.

Encode an ISO 19115 metadata record

To generate an ISO 19115 metadata record from a Python record configuration and return it as an XML document:

from datetime import date

from bas_metadata_library.standards.iso_19115_2 import MetadataRecordConfigV4, MetadataRecord

# define a minimalish record configuration
minimalish_config = {
    "$schema": "https://metadata-resources.data.bas.ac.uk/bas-metadata-generator-configuration-schemas/v2/iso-19115-1-v4.json",
    "hierarchy_level": "product",
    "metadata": {
        "contacts": [{"organisation": {"name": "Mapping and Geographic Information Centre, British Antarctic Survey"}, "role": ["pointOfContact"]}],
        "date_stamp": date(2018, 10, 18),
    },
    "identification": {
        "title": {"value": "Test Record"},
        "dates": {"creation": {"date": date(2018, 1, 1), "date_precision": "year"}},
        "abstract": "Test Record for ISO 19115 metadata standard (no profile) with minimal (but not minimal) fields.",
        "character_set": "utf8",
        "language": "eng",
        "extents": [
            {
                "identifier": "bounding",
                "geographic": {
                    "bounding_box": {
                        "west_longitude": -45.61521,
                        "east_longitude": -27.04976,
                        "south_latitude": -68.1511,
                        "north_latitude": -54.30761,
                    }
                },
            },
        ],
    },
}

# encode metadata library specific Python config into a standards compliant XML document
config = MetadataRecordConfigV4(**minimal_config)
record = MetadataRecord(configuration=config)
document = record.generate_xml_document()

# output document
print(document.decode())

[!TIP] See HTML Entities for guidance on using accents and symbols in configurations.

See Date Precision for guidance on using partial (year or year-month) dates.

Decode an ISO 19115 metadata record

from pathlib import Path

from bas_metadata_library.standards.iso_19115_2 import MetadataRecord

# load XML document from a file
with Path(f"record.xml").open() as document_file:
    document = document_file.read()

# decode document into an metadata library specific Python config
record = MetadataRecord(record=document)
configuration = record.make_config()
config = configuration.config

# output config
print(config)

Implementation

See Implementation documentation.

Setup

See Setup documentation.

Development

See Development documentation.

Releases

See the Release Workflow for creating a new release.

Project maintainer

Mapping and Geographic Information Centre (MAGIC), British Antarctic Survey (BAS).

Project lead: @felnne.

Data protection

A Data Protection Impact Assessment (DPIA) does not apply to this project.

License

Copyright (c) 2019-2026 UK Research and Innovation (UKRI), British Antarctic Survey (BAS).

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bas_metadata_library-0.17.0.tar.gz (168.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bas_metadata_library-0.17.0-py3-none-any.whl (250.2 kB view details)

Uploaded Python 3

File details

Details for the file bas_metadata_library-0.17.0.tar.gz.

File metadata

  • Download URL: bas_metadata_library-0.17.0.tar.gz
  • Upload date:
  • Size: 168.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for bas_metadata_library-0.17.0.tar.gz
Algorithm Hash digest
SHA256 c0b4466a550066d95a8fc1444d73bc8dc7a5b5d0aa52cc5305c05eb8c8a8ebf2
MD5 171928d80c6a33ec9b27949dc7abc3e4
BLAKE2b-256 43516adc733e5d5c718f1edfa63ef965668ba8f4f1fd9c3bc1f29d59058700ec

See more details on using hashes here.

File details

Details for the file bas_metadata_library-0.17.0-py3-none-any.whl.

File metadata

  • Download URL: bas_metadata_library-0.17.0-py3-none-any.whl
  • Upload date:
  • Size: 250.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for bas_metadata_library-0.17.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f0ba82c543ac17ab972292575ff35c59ff43e9220e59216d8b798cc923a7a8ad
MD5 716b85eb52b24fa1414341d6af8967b8
BLAKE2b-256 bd07a887f99e80241afef43e62eb493eb809307a2a3744baa9cd5b56f4516061

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page