PyLD


NamePyLD JSON
Version 1.0.3 PyPI version JSON
download
home_pagehttp://github.com/digitalbazaar/pyld
SummaryPython implementation of the JSON-LD API
upload_time2018-03-09 22:15:48
maintainer
docs_urlNone
authorDigital Bazaar
requires_python
licenseBSD 3-Clause license
keywords
VCS
bugtrack_url
requirements requests
Travis-CI
coveralls test coverage No coveralls.
            PyLD
====

.. image:: https://travis-ci.org/digitalbazaar/pyld.png?branch=master
   :target: https://travis-ci.org/digitalbazaar/pyld
   :alt: Build Status

Introduction
------------

This library is an implementation of the JSON-LD_ specification in Python_.

JSON, as specified in RFC7159_, is a simple language for representing
objects on the Web. Linked Data is a way of describing content across
different documents or Web sites. Web resources are described using
IRIs, and typically are dereferencable entities that may be used to find
more information, creating a "Web of Knowledge". JSON-LD_ is intended
to be a simple publishing method for expressing not only Linked Data in
JSON, but for adding semantics to existing JSON.

JSON-LD is designed as a light-weight syntax that can be used to express
Linked Data. It is primarily intended to be a way to express Linked Data
in JavaScript and other Web-based programming environments. It is also
useful when building interoperable Web Services and when storing Linked
Data in JSON-based document storage engines. It is practical and
designed to be as simple as possible, utilizing the large number of JSON
parsers and existing code that is in use today. It is designed to be
able to express key-value pairs, RDF data, RDFa_ data,
Microformats_ data, and Microdata_. That is, it supports every
major Web-based structured data model in use today.

The syntax does not require many applications to change their JSON, but
easily add meaning by adding context in a way that is either in-band or
out-of-band. The syntax is designed to not disturb already deployed
systems running on JSON, but provide a smooth migration path from JSON
to JSON with added semantics. Finally, the format is intended to be fast
to parse, fast to generate, stream-based and document-based processing
compatible, and require a very small memory footprint in order to operate.

Conformance
-----------

This library aims to pass the `test suite`_ and conform with the following:

- `JSON-LD 1.0`_,
  W3C Recommendation,
  2014-01-16, and any `errata`_
- `JSON-LD 1.0 Processing Algorithms and API`_,
  W3C Recommendation,
  2014-01-16, and any `errata`_
- `JSON-LD 1.1`_,
  Draft Community Group Report,
  2018-02-15 or `newer <JSON-LD latest_>`_
- `JSON-LD 1.1 Processing Algorithms and API`_,
  Draft Community Group Report,
  2018-02-15 or `newer <JSON-LD Processing Algorithms and API latest_>`_

Requirements
------------

- Python_ (2.7 or later)
- Requests_ (optional)
- aiohttp_ (optional, Python 3.5 or later)

Installation
------------

PyLD can be installed with pip_:

.. code-block:: bash

    pip install PyLD

Defining a dependency on pyld will not pull in Requests_ or aiohttp_.  If you
need one of these for a `Document Loader`_ then either depend on the desired
external library directly or define the requirement as ``PyLD[requests]`` or
``PyLD[aiohttp]``.

Quick Examples
--------------

.. code-block:: Python

    from pyld import jsonld
    import json

    doc = {
        "http://schema.org/name": "Manu Sporny",
        "http://schema.org/url": {"@id": "http://manu.sporny.org/"},
        "http://schema.org/image": {"@id": "http://manu.sporny.org/images/manu.png"}
    }

    context = {
        "name": "http://schema.org/name",
        "homepage": {"@id": "http://schema.org/url", "@type": "@id"},
        "image": {"@id": "http://schema.org/image", "@type": "@id"}
    }

    # compact a document according to a particular context
    # see: http://json-ld.org/spec/latest/json-ld/#compacted-document-form
    compacted = jsonld.compact(doc, context)

    print(json.dumps(compacted, indent=2))
    # Output:
    # {
    #   "@context": {...},
    #   "image": "http://manu.sporny.org/images/manu.png",
    #   "homepage": "http://manu.sporny.org/",
    #   "name": "Manu Sporny"
    # }

    # compact using URLs
    jsonld.compact('http://example.org/doc', 'http://example.org/context')

    # expand a document, removing its context
    # see: http://json-ld.org/spec/latest/json-ld/#expanded-document-form
    expanded = jsonld.expand(compacted)

    print(json.dumps(expanded, indent=2))
    # Output:
    # [{
    #   "http://schema.org/image": [{"@id": "http://manu.sporny.org/images/manu.png"}],
    #   "http://schema.org/name": [{"@value": "Manu Sporny"}],
    #   "http://schema.org/url": [{"@id": "http://manu.sporny.org/"}]
    # }]

    # expand using URLs
    jsonld.expand('http://example.org/doc')

    # flatten a document
    # see: http://json-ld.org/spec/latest/json-ld/#flattened-document-form
    flattened = jsonld.flatten(doc)
    # all deep-level trees flattened to the top-level

    # frame a document
    # see: http://json-ld.org/spec/latest/json-ld-framing/#introduction
    framed = jsonld.frame(doc, frame)
    # document transformed into a particular tree structure per the given frame

    # normalize a document using the RDF Dataset Normalization Algorithm
    # (URDNA2015), see: http://json-ld.github.io/normalization/spec/
    normalized = jsonld.normalize(
        doc, {'algorithm': 'URDNA2015', 'format': 'application/n-quads'})
    # normalized is a string that is a canonical representation of the document
    # that can be used for hashing, comparison, etc.

Document Loader
---------------

The default document loader for PyLD uses Requests_. In a production
environment you may want to setup a custom loader that, at a minimum, sets a
timeout value. You can also force requests to use https, set client certs,
disable verification, or set other Requests_ parameters.

.. code-block:: Python

    jsonld.set_document_loader(jsonld.requests_document_loader(timeout=...))

An asynchronous document loader using aiohttp_ is also available. Please note
that this document loader limits asynchronicity to fetching documents only.
The processing loops remain synchronous.

.. code-block:: Python

    jsonld.set_document_loader(jsonld.aiohttp_document_loader(timeout=...))

When no document loader is specified, the default loader is set to Requests_.
If Requests_ is not available, the loader is set to aiohttp_. The fallback
document loader is a dummy document loader that raises an exception on every
invocation.

Commercial Support
------------------

Commercial support for this library is available upon request from
`Digital Bazaar`_: support@digitalbazaar.com.

Source
------

The source code for the Python implementation of the JSON-LD API
is available at:

http://github.com/digitalbazaar/pyld

Tests
-----

This library includes a sample testing utility which may be used to verify
that changes to the processor maintain the correct output.

To run the sample tests you will need to get the test suite files by cloning
the ``json-ld.org`` and ``normalization`` repositories hosted on GitHub:

- https://github.com/json-ld/json-ld.org
- https://github.com/json-ld/normalization

Then run the test application using the directories containing the tests:

.. code-block:: bash

    python tests/runtests.py -d {PATH_TO_JSON_LD_ORG/test-suite}
    python tests/runtests.py -d {PATH_TO_NORMALIZATION/tests}

The test runner supports different document loaders by setting
``-l requests`` or ``-l aiohttp``. The default document loader is set
to Requests_.

.. _Digital Bazaar: http://digitalbazaar.com/
.. _JSON-LD: http://json-ld.org/
.. _JSON-LD 1.0: http://www.w3.org/TR/2014/REC-json-ld-20140116/
.. _JSON-LD 1.0 Processing Algorithms and API: http://www.w3.org/TR/2014/REC-json-ld-api-20140116/
.. _JSON-LD 1.1: https://json-ld.org/spec/ED/json-ld/20180215/
.. _JSON-LD 1.1 Processing Algorithms and API: https://json-ld.org/spec/ED/json-ld-api/20180215/
.. _JSON-LD latest: https://json-ld.org/spec/latest/json-ld/
.. _JSON-LD Processing Algorithms and API latest: https://json-ld.org/spec/latest/json-ld-api/
.. _Microdata: http://www.w3.org/TR/microdata/
.. _Microformats: http://microformats.org/
.. _Python: http://www.python.org/
.. _Requests: http://docs.python-requests.org/
.. _aiohttp: https://aiohttp.readthedocs.io/
.. _RDFa: http://www.w3.org/TR/rdfa-core/
.. _RFC7159: http://tools.ietf.org/html/rfc7159
.. _errata: http://www.w3.org/2014/json-ld-errata
.. _pip: http://www.pip-installer.org/
.. _test suite: https://github.com/json-ld/json-ld.org/tree/master/test-suite

            

Raw data

            {
    "_id": null,
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "cheesecake_code_kwalitee_id": null,
    "keywords": "",
    "upload_time": "2018-03-09 22:15:48",
    "requirements": [
        {
            "name": "requests",
            "specs": []
        }
    ],
    "author": "Digital Bazaar",
    "home_page": "http://github.com/digitalbazaar/pyld",
    "github_user": "digitalbazaar",
    "download_url": "https://pypi.python.org/packages/3d/8a/e76490b38b0fa381bd50585605676748760b1a19cdbfaa10163a2219a405/PyLD-1.0.3.tar.gz",
    "platform": "",
    "version": "1.0.3",
    "cheesecake_documentation_id": null,
    "description": "PyLD\n====\n\n.. image:: https://travis-ci.org/digitalbazaar/pyld.png?branch=master\n   :target: https://travis-ci.org/digitalbazaar/pyld\n   :alt: Build Status\n\nIntroduction\n------------\n\nThis library is an implementation of the JSON-LD_ specification in Python_.\n\nJSON, as specified in RFC7159_, is a simple language for representing\nobjects on the Web. Linked Data is a way of describing content across\ndifferent documents or Web sites. Web resources are described using\nIRIs, and typically are dereferencable entities that may be used to find\nmore information, creating a \"Web of Knowledge\". JSON-LD_ is intended\nto be a simple publishing method for expressing not only Linked Data in\nJSON, but for adding semantics to existing JSON.\n\nJSON-LD is designed as a light-weight syntax that can be used to express\nLinked Data. It is primarily intended to be a way to express Linked Data\nin JavaScript and other Web-based programming environments. It is also\nuseful when building interoperable Web Services and when storing Linked\nData in JSON-based document storage engines. It is practical and\ndesigned to be as simple as possible, utilizing the large number of JSON\nparsers and existing code that is in use today. It is designed to be\nable to express key-value pairs, RDF data, RDFa_ data,\nMicroformats_ data, and Microdata_. That is, it supports every\nmajor Web-based structured data model in use today.\n\nThe syntax does not require many applications to change their JSON, but\neasily add meaning by adding context in a way that is either in-band or\nout-of-band. The syntax is designed to not disturb already deployed\nsystems running on JSON, but provide a smooth migration path from JSON\nto JSON with added semantics. Finally, the format is intended to be fast\nto parse, fast to generate, stream-based and document-based processing\ncompatible, and require a very small memory footprint in order to operate.\n\nConformance\n-----------\n\nThis library aims to pass the `test suite`_ and conform with the following:\n\n- `JSON-LD 1.0`_,\n  W3C Recommendation,\n  2014-01-16, and any `errata`_\n- `JSON-LD 1.0 Processing Algorithms and API`_,\n  W3C Recommendation,\n  2014-01-16, and any `errata`_\n- `JSON-LD 1.1`_,\n  Draft Community Group Report,\n  2018-02-15 or `newer <JSON-LD latest_>`_\n- `JSON-LD 1.1 Processing Algorithms and API`_,\n  Draft Community Group Report,\n  2018-02-15 or `newer <JSON-LD Processing Algorithms and API latest_>`_\n\nRequirements\n------------\n\n- Python_ (2.7 or later)\n- Requests_ (optional)\n- aiohttp_ (optional, Python 3.5 or later)\n\nInstallation\n------------\n\nPyLD can be installed with pip_:\n\n.. code-block:: bash\n\n    pip install PyLD\n\nDefining a dependency on pyld will not pull in Requests_ or aiohttp_.  If you\nneed one of these for a `Document Loader`_ then either depend on the desired\nexternal library directly or define the requirement as ``PyLD[requests]`` or\n``PyLD[aiohttp]``.\n\nQuick Examples\n--------------\n\n.. code-block:: Python\n\n    from pyld import jsonld\n    import json\n\n    doc = {\n        \"http://schema.org/name\": \"Manu Sporny\",\n        \"http://schema.org/url\": {\"@id\": \"http://manu.sporny.org/\"},\n        \"http://schema.org/image\": {\"@id\": \"http://manu.sporny.org/images/manu.png\"}\n    }\n\n    context = {\n        \"name\": \"http://schema.org/name\",\n        \"homepage\": {\"@id\": \"http://schema.org/url\", \"@type\": \"@id\"},\n        \"image\": {\"@id\": \"http://schema.org/image\", \"@type\": \"@id\"}\n    }\n\n    # compact a document according to a particular context\n    # see: http://json-ld.org/spec/latest/json-ld/#compacted-document-form\n    compacted = jsonld.compact(doc, context)\n\n    print(json.dumps(compacted, indent=2))\n    # Output:\n    # {\n    #   \"@context\": {...},\n    #   \"image\": \"http://manu.sporny.org/images/manu.png\",\n    #   \"homepage\": \"http://manu.sporny.org/\",\n    #   \"name\": \"Manu Sporny\"\n    # }\n\n    # compact using URLs\n    jsonld.compact('http://example.org/doc', 'http://example.org/context')\n\n    # expand a document, removing its context\n    # see: http://json-ld.org/spec/latest/json-ld/#expanded-document-form\n    expanded = jsonld.expand(compacted)\n\n    print(json.dumps(expanded, indent=2))\n    # Output:\n    # [{\n    #   \"http://schema.org/image\": [{\"@id\": \"http://manu.sporny.org/images/manu.png\"}],\n    #   \"http://schema.org/name\": [{\"@value\": \"Manu Sporny\"}],\n    #   \"http://schema.org/url\": [{\"@id\": \"http://manu.sporny.org/\"}]\n    # }]\n\n    # expand using URLs\n    jsonld.expand('http://example.org/doc')\n\n    # flatten a document\n    # see: http://json-ld.org/spec/latest/json-ld/#flattened-document-form\n    flattened = jsonld.flatten(doc)\n    # all deep-level trees flattened to the top-level\n\n    # frame a document\n    # see: http://json-ld.org/spec/latest/json-ld-framing/#introduction\n    framed = jsonld.frame(doc, frame)\n    # document transformed into a particular tree structure per the given frame\n\n    # normalize a document using the RDF Dataset Normalization Algorithm\n    # (URDNA2015), see: http://json-ld.github.io/normalization/spec/\n    normalized = jsonld.normalize(\n        doc, {'algorithm': 'URDNA2015', 'format': 'application/n-quads'})\n    # normalized is a string that is a canonical representation of the document\n    # that can be used for hashing, comparison, etc.\n\nDocument Loader\n---------------\n\nThe default document loader for PyLD uses Requests_. In a production\nenvironment you may want to setup a custom loader that, at a minimum, sets a\ntimeout value. You can also force requests to use https, set client certs,\ndisable verification, or set other Requests_ parameters.\n\n.. code-block:: Python\n\n    jsonld.set_document_loader(jsonld.requests_document_loader(timeout=...))\n\nAn asynchronous document loader using aiohttp_ is also available. Please note\nthat this document loader limits asynchronicity to fetching documents only.\nThe processing loops remain synchronous.\n\n.. code-block:: Python\n\n    jsonld.set_document_loader(jsonld.aiohttp_document_loader(timeout=...))\n\nWhen no document loader is specified, the default loader is set to Requests_.\nIf Requests_ is not available, the loader is set to aiohttp_. The fallback\ndocument loader is a dummy document loader that raises an exception on every\ninvocation.\n\nCommercial Support\n------------------\n\nCommercial support for this library is available upon request from\n`Digital Bazaar`_: support@digitalbazaar.com.\n\nSource\n------\n\nThe source code for the Python implementation of the JSON-LD API\nis available at:\n\nhttp://github.com/digitalbazaar/pyld\n\nTests\n-----\n\nThis library includes a sample testing utility which may be used to verify\nthat changes to the processor maintain the correct output.\n\nTo run the sample tests you will need to get the test suite files by cloning\nthe ``json-ld.org`` and ``normalization`` repositories hosted on GitHub:\n\n- https://github.com/json-ld/json-ld.org\n- https://github.com/json-ld/normalization\n\nThen run the test application using the directories containing the tests:\n\n.. code-block:: bash\n\n    python tests/runtests.py -d {PATH_TO_JSON_LD_ORG/test-suite}\n    python tests/runtests.py -d {PATH_TO_NORMALIZATION/tests}\n\nThe test runner supports different document loaders by setting\n``-l requests`` or ``-l aiohttp``. The default document loader is set\nto Requests_.\n\n.. _Digital Bazaar: http://digitalbazaar.com/\n.. _JSON-LD: http://json-ld.org/\n.. _JSON-LD 1.0: http://www.w3.org/TR/2014/REC-json-ld-20140116/\n.. _JSON-LD 1.0 Processing Algorithms and API: http://www.w3.org/TR/2014/REC-json-ld-api-20140116/\n.. _JSON-LD 1.1: https://json-ld.org/spec/ED/json-ld/20180215/\n.. _JSON-LD 1.1 Processing Algorithms and API: https://json-ld.org/spec/ED/json-ld-api/20180215/\n.. _JSON-LD latest: https://json-ld.org/spec/latest/json-ld/\n.. _JSON-LD Processing Algorithms and API latest: https://json-ld.org/spec/latest/json-ld-api/\n.. _Microdata: http://www.w3.org/TR/microdata/\n.. _Microformats: http://microformats.org/\n.. _Python: http://www.python.org/\n.. _Requests: http://docs.python-requests.org/\n.. _aiohttp: https://aiohttp.readthedocs.io/\n.. _RDFa: http://www.w3.org/TR/rdfa-core/\n.. _RFC7159: http://tools.ietf.org/html/rfc7159\n.. _errata: http://www.w3.org/2014/json-ld-errata\n.. _pip: http://www.pip-installer.org/\n.. _test suite: https://github.com/json-ld/json-ld.org/tree/master/test-suite\n",
    "lcname": "pyld",
    "name": "PyLD",
    "github": true,
    "coveralls": false,
    "bugtrack_url": null,
    "license": "BSD 3-Clause license",
    "travis_ci": true,
    "github_project": "pyld",
    "summary": "Python implementation of the JSON-LD API",
    "split_keywords": [],
    "author_email": "support@digitalbazaar.com",
    "urls": [
        {
            "has_sig": false,
            "upload_time": "2018-03-09T22:15:48",
            "comment_text": "",
            "python_version": "source",
            "url": "https://pypi.python.org/packages/3d/8a/e76490b38b0fa381bd50585605676748760b1a19cdbfaa10163a2219a405/PyLD-1.0.3.tar.gz",
            "md5_digest": "3b80cce92d5202fc36b8c783ba6c9ef5",
            "downloads": 0,
            "filename": "PyLD-1.0.3.tar.gz",
            "packagetype": "sdist",
            "path": "3d/8a/e76490b38b0fa381bd50585605676748760b1a19cdbfaa10163a2219a405/PyLD-1.0.3.tar.gz",
            "size": 52576
        }
    ],
    "cheesecake_installability_id": null
}
        
Elapsed time: 0.07649s