Skip to main content

A library to process and translate open energy metadata.

Project description

A library to work with the open energy metadata. Its main features are validation, version conversion and infer data schemas from CSV to oemetadata.

  • Free software: AGPL-3.0

Overview

docs

Documentation Status

tests

Test status Coverage Status

package

PyPI Package latest release PyPI Wheel Supported versions Supported implementations
Commits since latest release

Installation

pip install omi

Documentation

Documentation for OMI versions up to 0.2: https://omi.readthedocs.io/

Documentation for reworked OMI versions starting from 1.0 you can find in the README document. Later on we migrate the documentation to mkdocs.

Usage

You can use omi as python module and import its functionality into your codebase or use the cli capabilities. OMI provides tooling for validation of oemetdata JSON documents using JSON-Schema. It also include helpers to generate the tabular data resource definition to seep up the metadata creation and helps to select a open license by checking the license identifier against the SPDX license list.

As the oemetadata is updated from time to time we provides conversion functionality to convert metadata documents that use an earlier version of the oemetadata-specification to help users stick with the latest enhancements the latest oemetadata version offers.

Conversion

To ease the conversion of oemetadata from any outdated version to the latest version, we provide a conversion functionality. The following example shows how to convert the oemetadata from v1.6 to v2.0.

Starting form v2 we do not support conversions for patch versions. This means you can convert from v1.6 to v2.0 but not from v2.0.0 to v2.0.1. The oemetadata release procedure requires to only add breaking changes to major or minor version. Only these changes will require a conversion.

CLI - oemetadata conversion:

# Not implemented yet
omi convert -i {input/path} -o {output/path}

Module usage - In python scripts you can use the conversion:

from omi.conversion import convert_metadata

import json

# you a function like this one to read you oemetadata json file
def read_json_file(file_path: str) -> dict:
    with open(file_path, "r") as file:
        data = json.load(file)
    return data

# for example you can use the oemetdata example.json for version 1.6.0
# find it here https://github.com/OpenEnergyPlatform/oemetadata/blob/develop/metadata/v160/example.json
# make sure to provide a valid path relative to where you store the python environment
file_path = "example_v16.json"

# read the metadata document
meta = read_json_file(file_path)

# use omi to convert it to the latest release
converted = convert_metadata(meta, "OEMetadata-2.0")

# now you can store the result as json file
with open("result.json", "w", encoding="utf-8") as json_file:
json.dump(converted, json_file, ensure_ascii=False, indent=4)  # `indent=4` makes the JSON file easier to read

Validation

The validation is based on jsonschema. We release a schema with each oemetadata release, that schema can be used to validate the user metadata. The dialect currently does not support direct access on to the validation. This will be updated soon. This will create a report.json containing information to debug possible errors. The parser.validate() takes two arguments the first one is the metadata and the second optional one is the schmea. By default (if no schema is passed) the validation will try to get the matching schema for the current metadata.

CLI - oemetadata validation:

# Not implemented yet

Module usage:

import json
from omi.validation import validate_oemetadata_licenses, validate_metadata


# use a function like this one to read you oemetadata json file
def read_json_file(file_path: str) -> dict:
    with open(file_path, "r") as file:
        data = json.load(file)
    return data

# for example you can use the oemetdata example.json for version 2.0.0
# find it here https://github.com/OpenEnergyPlatform/oemetadata/blob/develop/metadata/v20/example.json
# make sure to provide a valid path relative to where you store the python environment
file_path = "example_v16.json"

# read the new input from file
meta = read_json_file(file_path)

# validate the oemetadata: This will return noting or the errors including descriptions
validate_metadata(meta)

# As we are prone to open data we use this license check to validate the license name that
# is available in the metadata document for each data resource/distribution.
validate_oemetadata_licenses(meta)

Inspection

Describing your data structure is a quite technical task. OMI offers functionality to describe your data automatically. You need to provide your data in tabular text based format for this, for example a CSV file. Using frictionless OMI guesses the data schema specification you can use this you provide required fields in an oemetadata document.

CLI - oemetadata conversion:

# Not implemented yet

Module usage:

import json

import pathlib

from omi.inspection import infer_metadata

CSV_DATA_FILE = pathlib.Path(__file__).parent / "data" / "data.csv"

# infer the data fields from CSV fuile and add to an empty metadata template
with CSV_DATA_FILE.open("r") as f:
    metadata = infer_metadata(f, "OEP")

# Save to a JSON file
with open("script/metadata/result_inspection.json", "w", encoding="utf-8") as json_file:
    json.dump(metadata, json_file, ensure_ascii=False, indent=4)  # `indent=4` makes the JSON file easier to read

Additional Fields

To be in line with the oemetadata specification we do not allow for additional properties or fields in the metadata. We want to keep the oemetadata relatively lean and readable still linking to other documents or to propose a new property to extend the oemetadata would be a possibility here.

Still some times it becomes necessary to add additional information then this would be a use case outside of the OpenEnergyPlatform specifically for your own use. You are welcome to use the oemetadata as base and add new fields we are happy to integrate them back into the oeplatform and oemetadata if they seem relevant to other users.

Development

To install additional dependencies for development:

pip install -e .[dev]

We encourage the use of pre-commit-hooks in this project. Those enforce some formatting conventions (e.g. the use of isort and black). To enable hooks:

pre-commit install

To run the all tests run:

tox

Note, to combine the coverage data from all the tox environments run:

Windows

set PYTEST_ADDOPTS=--cov-append
tox

Other

PYTEST_ADDOPTS=--cov-append tox

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

omi-1.2.0.tar.gz (106.3 kB view details)

Uploaded Source

Built Distribution

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

omi-1.2.0-py3-none-any.whl (116.2 kB view details)

Uploaded Python 3

File details

Details for the file omi-1.2.0.tar.gz.

File metadata

  • Download URL: omi-1.2.0.tar.gz
  • Upload date:
  • Size: 106.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for omi-1.2.0.tar.gz
Algorithm Hash digest
SHA256 2910c6cd0a3f68b120c70a251df166850b135e9382b6b0618c03fb94074e927d
MD5 39e155fc20f8285146b3975435de35c2
BLAKE2b-256 e9398ace02f4e09eb41e524061fa9aec130e590e2d17f982acc78cccc1c82a81

See more details on using hashes here.

File details

Details for the file omi-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: omi-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 116.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for omi-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1ff8ee97c38bd54322a47f90e086572d0791b219ac0550108c2205097fe0c551
MD5 26775930bbd4703fb686b2f51a8cdb7d
BLAKE2b-256 9ce7d4dc69e0eb564ab2e06c15d9d84b24afb8e72062fb8e3644e387a4cc5ee0

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