Skip to main content

Library for parsing IMS-LOM xml records.

Project description

Build Status PyPI pyversions PyPI version

PyLom

This is a Python library for reading and writing IMS-LOM files. Almost all fields are supported, but only one language will be supported for language-specific langstring elements. The reader supports common vCard field extraction with vobject.

Reader Usage

Basically, import the class and tell it to parse a lom file. The parsed data will be available in the lom attribute dict. By default, it reads the en language, but another can be set on init. To start parsing, initialize the class and use one of two public methods, parsePath or parseString.

basic example

from pylom.reader import LomReader

lomreader = LomReader()
lomreader.parsePath("test/records/ims-complete.xml")

print(lomreader.lom["title"])
# Bloodbath of B-R5RB

fieldset example

from pylom.reader import LomReader

lomreader = LomReader()
lomreader.parsePath("test/records/ims-complete.xml", ["title","location"])

# Only the title and location field results are available in the lom dict

Writer Usage

The writer class is used by providing it with a dictionary with all the values you want in your record. Like the reader class the instance can be called with a language argument for all the langstring elements. After parsing, the lom record is available in the lom attribute.

basic example

from pylom.writer import LomWriter

lomwriter = LomWriter()
lomwriter.parseDict({"title": "Bloodbath of B-R5RB"})
print(lomwriter.lom)

custom vocabularies

By default, all vocabulary sources are set to LOMv1.0, but they can be changed by setting the vocabulary_sources after creating the instance.

from pylom.writer import LomWriter

lomwriter = LomWriter()
lomwriter.vocabulary_sources.update( { "aggregationlevel": "my-source" } )
lomwriter.parseDict({"aggregationlevel": "2"})
print(lomwriter.lom)

input values

For easy implementation, many of the values can be provided as needed. For instance, any basic element or langstring element can be provided as string or as a list of strings.

Vocabulary elements can be provided as a single string or a list of strings, using the class default vocabulary source, or as a single dictionary, with separate source and value values.

More detailed examples can be inferred from the test_writer_elements test cases.

from pylom.writer import LomWriter

lomwriter = LomWriter()
lomdict = {
    "title": "Bloodbath of B-R5RB",
    "keyword": ["Eve Online", "Halloween War"],
    "aggregationlevel": {"source": "my-source", "value": "2" },
    "context": ["school", "higher education"] }

lomwriter.parseDict(lomdict)
print(lomwriter.lom)

Dependencies

To Do

Reader

  • implement all LOM fields
  • support IEEE binding
  • cleanup options, trim, unique, etc
  • application profile validation
  • value validation

Writer

  • vocabulary, provide list of source/value dicts
  • more LOM-spec aware validation, for instance, prevent multiple title fields

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

pylom-1.6.3.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

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

pylom-1.6.3-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file pylom-1.6.3.tar.gz.

File metadata

  • Download URL: pylom-1.6.3.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.8

File hashes

Hashes for pylom-1.6.3.tar.gz
Algorithm Hash digest
SHA256 f6724b2b4a6dfd28479e5038865824536af779fb66c071b14ba029b5ea45a8de
MD5 085a4f3c8b1708e73637e1f97d581a89
BLAKE2b-256 121537a73c6ff9bd6a772cdd997cd839e525451dca0d214b34a116f734ccfe2e

See more details on using hashes here.

File details

Details for the file pylom-1.6.3-py3-none-any.whl.

File metadata

  • Download URL: pylom-1.6.3-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.8

File hashes

Hashes for pylom-1.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7cb623960623ff3af215bdb4efe3b3941c55028a4e857120b1b563eb6965dd8e
MD5 6ae73588a9322547d94e7333ce8455e1
BLAKE2b-256 f44d9c89bfce1d7f3c1424df89497ce170f6b39e7cf4e7c54c3bac543a8bc95c

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