premisrw API Documentation
premisrw is a library to help with parsing and creating PREMIS elements.
Conversion functions
- metsrw.plugins.premisrw.premis.data_to_premis(data, premis_version='2.2')[source]
Given tuple
datarepresenting a PREMIS entity (object, event or agent), return anlxml.etree._Elementinstance. E.g.,:>>> p = data_to_premis(( 'event', utils.PREMIS_META, ( 'event_identifier', ('event_identifier_type', 'UUID'), ('event_identifier_value', str(uuid4())) ) )) >>> etree.tostring(p, pretty_print=True).decode('utf8') '''<premis:event xmlns:premis="info:lc/xmlns/premis-v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.2" xsi:schemaLocation="info:lc/xmlns/premis-v2 http://www.loc.gov/standards/premis/v2/premis-v2-2.xsd"> <premis:eventIdentifier> <premis:eventIdentifierType>UUID</premis:eventIdentifierType> <premis:eventIdentifierValue>f4b7758f-e7b2-4155-9b56-d76965849fc1</premis:eventIdentifierValue> </premis:eventIdentifier> </premis:event>'''
PREMIS Element Types
- class metsrw.plugins.premisrw.premis.PREMISElement(**kwargs)[source]
Bases:
objectAbstract base class for PREMIS object, event and agent classes. These classes must implement
schemaanddefaultsproperties. After that, initalization can proceed either by passing adatakwarg to the class or by passing keyword arguments implicit in the element tag names ofself.schema, e.g.,:>>> premis_obj = PREMISObject(data=('object', {...}, (...))) >>> premis_obj = PREMISObject( identifier_type='UUID', identifier_value='9bf6bcf8-4d77-4623-a9fb-b703365d0ffe', ...)
Under the first construction approach, the tuple passed as
databecomes the source of truth for the PREMIS element. Under the second construction approach, the kwargs are used to construct adatatuple that becomes the source of truth. This tuple can be accessed via the.dataproperty.- property attributes
Return a dict that maps normalized XML attributes to their values, e.g., ‘xsi_schema_location’ and ‘schema_location’ would be keys for the value of the xsi:schemaLocation PREMIS XML attribute.
- property attrs_to_paths
Return a dict that maps valid getter attributes to the simplified XPaths needed to get the corresponding values from
self.data.This property analyzes
self.schemaand setsself._attrs_to_pathsto a dict that maps implicit getters like ‘agent_identifier_value’ and ‘identifier_value’ to the XPaths implicit inself.schema. In the case ofPREMISAgent, the above two getters would map to the XPath ‘agent/agent_identifier/agent_identifier_value’.PREMISAgent.schemaalso implies the getters ‘agent_identifier’ and ‘identifier’, which both map to the XPath ‘agent/agent_identifier’ and which should return a tuple (or list thereof) instead of a string.
- property data
- abstract defaults()[source]
Return a dict that maps implicit getter attributes (implicit in
self.schema) to default values or to callables that return default values. For example, seePREMISObject.defaults.
- generate_data()[source]
Generate and return a tuple to assign to
self._data, which is the source of truth of the PREMIS XML element. Expectsself._xml_element_valuesandself._xml_attribute_valuesto be dicts populated with XML element text values and XML attribute values, respectively.
- class metsrw.plugins.premisrw.premis.PREMISObject(**kwargs)[source]
Bases:
PREMISElement- property defaults
Return a dict that maps implicit getter attributes (implicit in
self.schema) to default values or to callables that return default values. For example, seePREMISObject.defaults.
- property schema
Return a tuple representing the schema of the PREMIS element. This tuple schema determines the available getters and setters (during initialization) of the subclass.
- class metsrw.plugins.premisrw.premis.PREMISEvent(**kwargs)[source]
Bases:
PREMISElement- property compression_details
Return as a 3-tuple, this PREMIS compression event’s program, version, and algorithm used to perform the compression.
- property defaults
Return a dict that maps implicit getter attributes (implicit in
self.schema) to default values or to callables that return default values. For example, seePREMISObject.defaults.
- property encryption_details
Return as a 3-tuple, this PREMIS encryption event’s program, version, and key used to perform the encryption.
- get_decompression_transform_files(offset=0)[source]
Returns a list of dicts representing
<mets:transformFile>elements withTRANSFORMTYPE="decompression"givencompression_algorithmwhich is a comma-separated string of algorithms that must be used in the order provided to decompress the package, e.g., ‘bzip2,tar’ or ‘lzma’.
- get_decryption_transform_file()[source]
Returns a dict representing a
<mets:transformFile>element withTRANSFORMTYPE="decryption".
- property parsed_event_detail
Parse and return our PREMIS eventDetail string value like:
'program="7z"; version="9.20"; algorithm="bzip2"'and return a dict like:
{'algorithm': 'bzip2', 'version': '9.20', 'program': '7z'}
- property schema
Return a tuple representing the schema of the PREMIS element. This tuple schema determines the available getters and setters (during initialization) of the subclass.
- class metsrw.plugins.premisrw.premis.PREMISAgent(**kwargs)[source]
Bases:
PREMISElement- property defaults
Return a dict that maps implicit getter attributes (implicit in
self.schema) to default values or to callables that return default values. For example, seePREMISObject.defaults.
- property schema
Return a tuple representing the schema of the PREMIS element. This tuple schema determines the available getters and setters (during initialization) of the subclass.
- class metsrw.plugins.premisrw.premis.PREMISRights(**kwargs)[source]
Bases:
PREMISElement- property defaults
Return a dict that maps implicit getter attributes (implicit in
self.schema) to default values or to callables that return default values. For example, seePREMISObject.defaults.
- property schema
Return a tuple representing the schema of the PREMIS element. This tuple schema determines the available getters and setters (during initialization) of the subclass.