Skip to main content

Hypercat.py

A minimal library for working with Hypercat 3.0 catalogues. For full details on Hypercat please see: http://www.hypercat.io/standard.html

Origin

This module is a simple repackaging of a Hypercat module original available here: https://github.com/hypercatIoT/python-tools

Use cases

Servers:

  • Create an empty Hypercat catalogue

  • Optionally, add metadata to describe it

  • Optionally, add items to the catalogue

    • an item is either another catalogue or a resource

  • Output it as JSON, either minimally or prettyprinted

  • Find a specific part of a catalogue hierarchy

Clients:

  • Load and validate a Hypercat

Example - Hypercat server

We’ll create a Hypercat catalogue with 2 items in it:

  h
 / \
h2  r

Usage:

from hypercat import hypercat

# Create a catalogue
h = hypercat.hypercat("CatalogueContainingOneCatalogueAndOneResource")

# Create a second catalogue, and add it as a child of the first
h2 = hypercat.hypercat("ChildCatalogue")
h.addItem(h2, "/child_cat")

# Create a resource, and add it as another child of the first catalogue
r = hypercat.resource("resource1", "application/vnd.hypercat.sensordata+json")
h.addItem(r, "/resource")

# Print the raw JSON of the catalogue, and then with human-friendly formatting
print h.asJSON()
print h.prettyprint()

This should output:

{
    "catalogue-metadata": [
        {
            "rel": "urn:X-hypercat:rels:isContentType",
            "val": "application/vnd.hypercat.catalogue+json"
        },
        {
            "rel": "urn:X-hypercat:rels:hasDescription:en",
            "val": "CatalogueContainingOneCatalogueAndOneResource"
        }
    ],
    "items": [
        {
            "href": "/child_cat",
            "item-metadata": [
                {
                    "rel": "urn:X-hypercat:rels:isContentType",
                    "val": "application/vnd.hypercat.catalogue+json"
                },
                {
                    "rel": "urn:X-hypercat:rels:hasDescription:en",
                    "val": "ChildCatalogue"
                }
            ]
        },
        {
            "href": "/resource",
            "item-metadata": [
                {
                    "rel": "urn:X-hypercat:rels:isContentType",
                    "val": "application/vnd.hypercat.sensordata+json"
                },
                {
                    "rel": "urn:X-hypercat:rels:hasDescription:en",
                    "val": "resource1"
                }
            ]
        }
    ]
}

Example - Hypercat Client

Usage:

from hypercat import hypercat

h = hypercat.loads(inString)  # Read-in and validate Hypercat
print "Metadata is ",h.metadata

How this module works

According to the spec, each Catalogue has a (human-readable) description and a list of metadata about it. It also contains a list of “items”, and each item has an HREF and a list of metadata about it. An item can be any kind of resource, including another catalogue.

So conceptually, catalogues can have many levels of hierarchy (i.e. a catalogue can contain a catalogue which contains a catalogue and so on). Catalogues don’t just have to be trees either, they can be graphs, contain loops etc., and clients of this module will often want to declare full catalogue structures several levels deep, i.e. build their entire hierarchy in one go.

But according to the spec only one level of catalogue can be output at a time, i.e. getting a catalogue will declare its child catalogues, but not its grand-children (to see the grand-children, you’d have to get the child catalogue)

A further complication is some asymmetry in how attributes are declared when a catalogue is the parent, vs. when it is the child

To deal with this, within this module we maintain a universal base class for every hypercat object. Then during output, we ignore grand-children, and modify attributes as necessary.

License

The software is released under an MIT license. Please see the details in LICENSE.txt.

TODO

4.3.3 Says that it is optional to use isContentType to tag each member of items[], however we treat it here as mandatory.

Metadata

Release files for hypercat.py 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hypercat.py 0.1.2
File Size Uploaded Provenance
hypercat.py-0.1.2.tar.gz 6.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for hypercat.py 0.1.2
File Interpreter ABI Platform
hypercat.py-0.1.2-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 15.3 kB

Release files / hypercat.py-0.1.2.tar.gz

Download URL hypercat.py-0.1.2.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3d1ff528b5ebf956e970edc307ac305d8cff8fd348ac6bfe50da7d31aadf5caf
BLAKE2b-256 checksum
How to use checksums
40ec877349c21d3379890f3b3a28135a74780ebe490727ff5b1298cdc8793017
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / hypercat.py-0.1.2-py2.py3-none-any.whl

Download URL hypercat.py-0.1.2-py2.py3-none-any.whl
Size 8.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
f451a87a29ceaa9dda41878b82226af6976849b20a01448adc04940479e7b68b
BLAKE2b-256 checksum
How to use checksums
7dd87e37aef325c34bc6997e0db055d9815fc4bcc89f17634ceb915aba4d029f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for hypercat.py 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page