Skip to main content

ManGO metadata schemas on iRODS

Project description

Apply ManGO metadata schemas in Python

Small application to apply metadata from a metadata schema using iRODS PRC.

Requirements

  • python-irodsclient
  • validators

Installation

You can install the package and its dependencies with pip:

pip install mango-mdschema

Usage

# authentication to iRODS
import os, os.path
from irods.session import iRODSSession
from mango_mdschema import Schema

env_file = os.getenv('IRODS_ENVIRONMENT_FILE', os.path.expanduser('~/.irods/irods_environment.json'))

# load a schema from file
my_schema = Schema('/path/to/schema') # this also validates it as a schema
with iRODSSession(irods_env_file=env_file) as session:
    obj = session.data_objects.get('path/to/my/object')
    my_metadata = {
        'text' : 'Some text',
        'a_date' : '2023-04-26',
        'author' : {
            'name' : 'Mariana',
            'email' : 'mariana.montes@kuleuven.be'
        }
    }
    my_schema.apply(obj, my_metadata)

The apply function will first validate the provided metadata dictionary before applying it on the iRODS object. See the tutorial for more details.

To only validate your metadata, without applying it, you can use the validate

function of the schema.

try:
    validated = my_schema.validate(metadata)
except (ConversionError, ValidationError) as err:
    print("Oops my metadata was not valid: {err}")

You can check the fields in a schema with:

print(my_schema)

The list of required fields and default values is found as the required_fields attribute. You can also check all the characteristics of a specific field such as 'name' with:

my_schema.print_requirements('name') # same as print(my_schema.fields['name'])

You can test the list of AVUs that would be sent by providing a given metadata dictonary like so:

avus = my_schema.to_avus(metadata)

The schema class can also read the metadata from ManGO and return it as nested dictionary with all values converted to their Python representation ( i.e. integer fields result in int values, datetime fields in datetime objects, etc.).

with iRODSSession(irods_env_file=env_file) as session:
    obj = session.data_objects.get('path/to/my/object')
    my_metadata = my_schema.extract(obj)

Check the tutorial notebook for more details.

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

mango-mdschema-1.0.2.tar.gz (23.8 kB view details)

Uploaded Source

Built Distribution

mango_mdschema-1.0.2-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file mango-mdschema-1.0.2.tar.gz.

File metadata

  • Download URL: mango-mdschema-1.0.2.tar.gz
  • Upload date:
  • Size: 23.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for mango-mdschema-1.0.2.tar.gz
Algorithm Hash digest
SHA256 9f05b9130e3966e7c09ac07f4014cd639873aae1af9d5082d7f1b0048d4dbc1d
MD5 825286b1fe59f1584cdb12d54e1ca5b9
BLAKE2b-256 8b39ce7a21ea61affa74a58330e2af6c30c5f8428d6111726ed6463a62e059ba

See more details on using hashes here.

File details

Details for the file mango_mdschema-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for mango_mdschema-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3250998134bb7ed176e02fa2762882d0a62bc0ef12fb9ec8eac315c149bc0bd8
MD5 70f851017904aec501f6a1d4fdd26da6
BLAKE2b-256 e4e54cd98805de3a795491a0b49aa9e76af30bbecc2476ae26266208144288b2

See more details on using hashes here.

Supported by

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