Skip to main content

SWORDv3 Common Object Library

Project description

SWORDv3 Common Library

Build Status codecov

This library provides a set of resources which can be used by any SWORD Python implementation, both client and server-side.

It consists of:

  • A set of model objects that can represent the key document types used by SWORDv3 (sword3common.models)
  • A set of constants that are used throughout the specification, such as URIs (sword3common.constants)
  • A set of exceptions which a client or server may be required to raise or handle (sword3common.exceptions)
  • Some common test fixtures and document examples which can be used for testing clients and servers (sword3common.test.fixtures)

Example usage

Create model objects via their APIs

import json
from sword3common import (
    Metadata, 
    ByReference, 
    MetadataAndByReference, 
    )

# create a metadata record containing simple DC, full DCMI terms, and a custom field
metadata = Metadata()
metadata.add_dc_field("creator", "Richard")
metadata.add_dcterms_field("rights", "CC0")
metadata.add_field("custom", "value")

# Create a ByReference object with a single file
br = ByReference()
br.add_file("http://example.com/file.pdf",
            "file.pdf",
            "application/pdf",
            True)

# Combine them both into a MetadataAndByReference object:
mdbr = MetadataAndByReference(metadata, br)

# To access the data and serialise them for delivery:
payload = json.dumps(mdbr.data)

Read them from raw data:

import json
from sword3common import (
    Metadata, 
    ByReference 
    )

metadata_raw = "..."        # JSON string of metadata
br_raw = "..."              # JSON string of by reference data

# read them both into their objects
metadata = Metadata(json.loads(metadata_raw))
br = ByReference(json.loads(br_raw))

# read the values back out
assert metadata.get_dc_field("creator") == "Richard"
assert metadata.get_dcterms_field("rights") == "CC0"
assert metadata.get_field("custom") == "value"

Notes on limitations

NOTE that all the objects in the library have only the features that were required to deliver the reference implementation, so there are not full object APIs for every interaction that you may wish to use. This library will need to be expanded in time to be a fully featured common library.

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

sword3common-0.0.1.tar.gz (21.5 kB view details)

Uploaded Source

File details

Details for the file sword3common-0.0.1.tar.gz.

File metadata

  • Download URL: sword3common-0.0.1.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.3

File hashes

Hashes for sword3common-0.0.1.tar.gz
Algorithm Hash digest
SHA256 ced02376404c5f29a99c1a7855e09628e38d89ba564e0178de2474a190ce8b19
MD5 6f0f17f606544fb9c791f1c4b98748b6
BLAKE2b-256 360b92ef5d93a47e69b50da31e12926b5e3e94ed945875dfc73c315b3868e6a1

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