Giter Club home page Giter Club logo

pypremis's Introduction

pypremis

Whats New?

  • First official release coming soon...

Introduction

Pypremis is a project which aims to make the PREMISv3 metadata standard easily accessible via python library code. This project aims to correctly implement PREMIS metadata creation and reading, mandating full compliance to the PREMIS specification and data dictionary

Usage Examples

Read an existing PREMIS xml record

>>> from pypremis.lib import PremisRecord
>>> example_record = PremisRecord(frompath='testObject.xml')
>>> example_object = example_record.get_object_list()[0]
>>> print(example_object.get_objectIdentifier(0))
<premis:objectIdentifier><premis:objectIdentifierType>object_identifier_type</premis:objectIdentifierType><premis:objectIdentifierValue>object_identifier_value</premis:objectIdentifierValue></premis:objectIdentifier>
>>> example_object_identifier = example_object.get_objectIdentifier(0)
>>> print(example_object_identifier.get_objectIdentifierValue())
object_identifier_value
>>>

Create a PREMIS record from scratch

>>> from pypremis.lib import PremisRecord
>>> from pypremis.nodes import *
>>> object_identifier = ObjectIdentifier('object id type example value', 'object id value example value')
>>> format_designation = FormatDesignation(formatName='format name example value')
>>> format = Format(formatDesignation=format_designation)
>>> object_characteristics = ObjectCharacteristics(format=format)
>>> o = Object(object_identifier, "file", object_characteristics)
>>> print(o)
<premis:object xsi:type="premis:file"><premis:objectIdentifier><premis:objectIdentifierType>object id type example value</premis:objectIdentifierType><premis:objectIdentifierValue>object id value example value</premis:objectIdentifierValue></premis:objectIdentifier><premis:objectCharacteristics><premis:format><premis:formatDesignation><premis:formatName>format name example value</premis:formatName></premis:formatDesignation></premis:format></premis:objectCharacteristics></premis:object>
>>> example_record = PremisRecord(objects=[o])
>>> example_record.write_to_file('example_record.xml')
>>> exit()
$ cat example_record.xml | xmllint -format -
<?xml version="1.0" encoding="utf-8"?>
<premis:premis xmlns:premis="http://www.loc.gov/premis/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0">
  <premis:object xsi:type="premis:file">
    <premis:objectIdentifier>
      <premis:objectIdentifierType>object id type example value</premis:objectIdentifierType>
      <premis:objectIdentifierValue>object id value example value</premis:objectIdentifierValue>
    </premis:objectIdentifier>
    <premis:objectCharacteristics>
      <premis:format>
        <premis:formatDesignation>
          <premis:formatName>format name example value</premis:formatName>
        </premis:formatDesignation>
      </premis:format>
    </premis:objectCharacteristics>
  </premis:object>
</premis:premis>

Manipulate and add to records easily

>>> from pypremis.lib import PremisRecord
>>> from pypremis.nodes import *
>>> example_record = PremisRecord(frompath='example_record.xml')
>>> obj = example_record.get_object_list()[0]
>>> obj.set_originalName('example_file.txt')
>>> obj.get_objectIdentifier(0).set_objectIdentifierType('not the same type as before')
>>> example_record.write_to_file('example_record_v2.xml')
>>> exit()
$ cat example_record_v2.xml | xmllint -format -
<?xml version="1.0" encoding="utf-8"?>
<premis:premis xmlns:premis="http://www.loc.gov/premis/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0">
  <premis:object xsi:type="premis:file">
    <premis:objectIdentifier>
      <premis:objectIdentifierType>not the same type as before</premis:objectIdentifierType>
      <premis:objectIdentifierValue>object id value example value</premis:objectIdentifierValue>
    </premis:objectIdentifier>
    <premis:objectCharacteristics>
      <premis:format>
        <premis:formatDesignation>
          <premis:formatName>format name example value</premis:formatName>
        </premis:formatDesignation>
      </premis:format>
    </premis:objectCharacteristics>
    <premis:originalName>example_file.txt</premis:originalName>
  </premis:object>
</premis:premis>

Author

Brian Balsamo [email protected]

pypremis's People

Stargazers

Michael Andrec avatar

Watchers

James Cloos avatar Michael Andrec avatar Brian Balsamo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.