Skip to main content

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.

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.18.0.tar.gz (171.1 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.18.0-py3-none-any.whl (250.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bas_metadata_library-0.18.0.tar.gz
  • Upload date:
  • Size: 171.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","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.18.0.tar.gz
Algorithm Hash digest
SHA256 8d293ed05fd80af21184571b5c1a5b92bb11f2a321fbd57fd192f4aa540adaf2
MD5 dff78123976180a7a9130de8acd6a679
BLAKE2b-256 f0aeb170eff100fa543b4c885a83a361a7d017d51e448d480cb2ee24bdb7aac1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bas_metadata_library-0.18.0-py3-none-any.whl
  • Upload date:
  • Size: 250.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","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.18.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9ae911c790f60513dfdb6dc346f96e221c61d8448fcd02cb52c955db4820da3
MD5 92202e82b30c049e666ffbe9a07161bf
BLAKE2b-256 1e614d5fa7ab146e7cd8e2d64fafc304212b9ec8da87e78d6e245b669676eeeb

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