Python library for generating metadata records.
The BAS Metadata Library is an underpinning library for other tools and applications to generate discovery level metadata records (describing products, services and other resources). It is intended to avoid duplicating complex and verbose encode/decoding logic across projects.
It 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) to support processing and manipulation of information between and within systems.
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.
| 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).
| Standard | Profile | Introduced In |
|---|---|---|
| ISO 19115 | MAGIC Discovery Metadata V1 | #250 |
| ISO 19115 | MAGIC Discovery Metadata V2 | #250 |
| 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 |
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.
This package can be installed using Pip from PyPi:
$ pip install bas-metadata-library
Tip
To install on Windows, it's recommended to use UV to use a Python version covered by
pre-built lxml wheels, avoiding the complexity of building packages from source.
This package depends on these OS level libraries for XML encoding and decoding:
libxml2libxslt
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 |
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 configuration into a formal 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.
from bas_metadata_library.standards.iso_19115_2 import MetadataRecord
# load a formal document
with open(f"record.xml") as document_file:
document = document_file.read()
# decode formal document into an informal Python config
record = MetadataRecord(record=document)
configuration = record.make_config()
config = configuration.config
# output config
print(config)See Usage documentation for further usage examples.
See Implementation documentation.
See Setup documentation.
See Development documentation.
See the Release Workflow for creating a new release.
Mapping and Geographic Information Centre (MAGIC), British Antarctic Survey (BAS).
Project lead: @felnne.
A Data Protection Impact Assessment (DPIA) does not apply to this project.
Copyright (c) 2019-2025 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.