PyLD 2.0.3__tar.gz → 2.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {PyLD-2.0.3 → PyLD-2.0.4}/CHANGELOG.md +6 -0
- PyLD-2.0.4/MANIFEST.in +1 -0
- PyLD-2.0.4/PKG-INFO +276 -0
- {PyLD-2.0.3 → PyLD-2.0.4}/README.rst +1 -1
- PyLD-2.0.4/README.txt +246 -0
- PyLD-2.0.4/lib/PyLD.egg-info/PKG-INFO +276 -0
- PyLD-2.0.4/lib/PyLD.egg-info/SOURCES.txt +22 -0
- PyLD-2.0.4/lib/PyLD.egg-info/dependency_links.txt +1 -0
- PyLD-2.0.4/lib/PyLD.egg-info/requires.txt +15 -0
- PyLD-2.0.4/lib/PyLD.egg-info/top_level.txt +2 -0
- {PyLD-2.0.3 → PyLD-2.0.4}/lib/pyld/__about__.py +2 -2
- {PyLD-2.0.3 → PyLD-2.0.4}/lib/pyld/context_resolver.py +1 -1
- {PyLD-2.0.3 → PyLD-2.0.4}/lib/pyld/jsonld.py +2 -2
- PyLD-2.0.4/setup.cfg +4 -0
- PyLD-2.0.3/PKG-INFO +0 -265
- PyLD-2.0.3/README.txt +0 -1
- {PyLD-2.0.3 → PyLD-2.0.4}/LICENSE +0 -0
- {PyLD-2.0.3 → PyLD-2.0.4}/lib/c14n/Canonicalize.py +0 -0
- {PyLD-2.0.3 → PyLD-2.0.4}/lib/c14n/NumberToJson.py +0 -0
- {PyLD-2.0.3 → PyLD-2.0.4}/lib/c14n/__init__.py +0 -0
- {PyLD-2.0.3 → PyLD-2.0.4}/lib/pyld/__init__.py +0 -0
- {PyLD-2.0.3 → PyLD-2.0.4}/lib/pyld/documentloader/__init__.py +0 -0
- {PyLD-2.0.3 → PyLD-2.0.4}/lib/pyld/documentloader/aiohttp.py +0 -0
- {PyLD-2.0.3 → PyLD-2.0.4}/lib/pyld/documentloader/requests.py +0 -0
- {PyLD-2.0.3 → PyLD-2.0.4}/lib/pyld/resolved_context.py +0 -0
- {PyLD-2.0.3 → PyLD-2.0.4}/setup.py +0 -0
PyLD-2.0.4/MANIFEST.in
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include README.rst README.txt LICENSE CHANGELOG.md
|
PyLD-2.0.4/PKG-INFO
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: PyLD
|
|
3
|
+
Version: 2.0.4
|
|
4
|
+
Summary: Python implementation of the JSON-LD API
|
|
5
|
+
Home-page: https://github.com/digitalbazaar/pyld
|
|
6
|
+
Author: Digital Bazaar
|
|
7
|
+
Author-email: support@digitalbazaar.com
|
|
8
|
+
License: BSD 3-Clause license
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Environment :: Web Environment
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python
|
|
16
|
+
Classifier: Topic :: Internet
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: cachetools
|
|
20
|
+
Requires-Dist: frozendict
|
|
21
|
+
Requires-Dist: lxml
|
|
22
|
+
Provides-Extra: requests
|
|
23
|
+
Requires-Dist: requests; extra == "requests"
|
|
24
|
+
Provides-Extra: aiohttp
|
|
25
|
+
Requires-Dist: aiohttp; extra == "aiohttp"
|
|
26
|
+
Provides-Extra: cachetools
|
|
27
|
+
Requires-Dist: cachetools; extra == "cachetools"
|
|
28
|
+
Provides-Extra: frozendict
|
|
29
|
+
Requires-Dist: frozendict; extra == "frozendict"
|
|
30
|
+
|
|
31
|
+
PyLD
|
|
32
|
+
====
|
|
33
|
+
|
|
34
|
+
.. image:: https://travis-ci.org/digitalbazaar/pyld.png?branch=master
|
|
35
|
+
:target: https://travis-ci.org/digitalbazaar/pyld
|
|
36
|
+
:alt: Build Status
|
|
37
|
+
|
|
38
|
+
Introduction
|
|
39
|
+
------------
|
|
40
|
+
|
|
41
|
+
This library is an implementation of the JSON-LD_ specification in Python_.
|
|
42
|
+
|
|
43
|
+
JSON, as specified in RFC7159_, is a simple language for representing
|
|
44
|
+
objects on the Web. Linked Data is a way of describing content across
|
|
45
|
+
different documents or Web sites. Web resources are described using
|
|
46
|
+
IRIs, and typically are dereferencable entities that may be used to find
|
|
47
|
+
more information, creating a "Web of Knowledge". JSON-LD_ is intended
|
|
48
|
+
to be a simple publishing method for expressing not only Linked Data in
|
|
49
|
+
JSON, but for adding semantics to existing JSON.
|
|
50
|
+
|
|
51
|
+
JSON-LD is designed as a light-weight syntax that can be used to express
|
|
52
|
+
Linked Data. It is primarily intended to be a way to express Linked Data
|
|
53
|
+
in JavaScript and other Web-based programming environments. It is also
|
|
54
|
+
useful when building interoperable Web Services and when storing Linked
|
|
55
|
+
Data in JSON-based document storage engines. It is practical and
|
|
56
|
+
designed to be as simple as possible, utilizing the large number of JSON
|
|
57
|
+
parsers and existing code that is in use today. It is designed to be
|
|
58
|
+
able to express key-value pairs, RDF data, RDFa_ data,
|
|
59
|
+
Microformats_ data, and Microdata_. That is, it supports every
|
|
60
|
+
major Web-based structured data model in use today.
|
|
61
|
+
|
|
62
|
+
The syntax does not require many applications to change their JSON, but
|
|
63
|
+
easily add meaning by adding context in a way that is either in-band or
|
|
64
|
+
out-of-band. The syntax is designed to not disturb already deployed
|
|
65
|
+
systems running on JSON, but provide a smooth migration path from JSON
|
|
66
|
+
to JSON with added semantics. Finally, the format is intended to be fast
|
|
67
|
+
to parse, fast to generate, stream-based and document-based processing
|
|
68
|
+
compatible, and require a very small memory footprint in order to operate.
|
|
69
|
+
|
|
70
|
+
Conformance
|
|
71
|
+
-----------
|
|
72
|
+
|
|
73
|
+
This library aims to conform with the following:
|
|
74
|
+
|
|
75
|
+
- `JSON-LD 1.1 <JSON-LD WG 1.1_>`_,
|
|
76
|
+
W3C Candidate Recommendation,
|
|
77
|
+
2019-12-12 or `newer <JSON-LD WG latest_>`_
|
|
78
|
+
- `JSON-LD 1.1 Processing Algorithms and API <JSON-LD WG 1.1 API_>`_,
|
|
79
|
+
W3C Candidate Recommendation,
|
|
80
|
+
2019-12-12 or `newer <JSON-LD WG API latest_>`_
|
|
81
|
+
- `JSON-LD 1.1 Framing <JSON-LD WG 1.1 Framing_>`_,
|
|
82
|
+
W3C Candidate Recommendation,
|
|
83
|
+
2019-12-12 or `newer <JSON-LD WG Framing latest_>`_
|
|
84
|
+
- Working Group `test suite <WG test suite_>`_
|
|
85
|
+
|
|
86
|
+
The `test runner`_ is often updated to note or skip newer tests that are not
|
|
87
|
+
yet supported.
|
|
88
|
+
|
|
89
|
+
Requirements
|
|
90
|
+
------------
|
|
91
|
+
|
|
92
|
+
- Python_ (3.6 or later)
|
|
93
|
+
- Requests_ (optional)
|
|
94
|
+
- aiohttp_ (optional, Python 3.5 or later)
|
|
95
|
+
|
|
96
|
+
Installation
|
|
97
|
+
------------
|
|
98
|
+
|
|
99
|
+
PyLD can be installed with a pip_ `package <https://pypi.org/project/PyLD/>`_
|
|
100
|
+
|
|
101
|
+
.. code-block:: bash
|
|
102
|
+
|
|
103
|
+
pip install PyLD
|
|
104
|
+
|
|
105
|
+
Defining a dependency on pyld will not pull in Requests_ or aiohttp_. If you
|
|
106
|
+
need one of these for a `Document Loader`_ then either depend on the desired
|
|
107
|
+
external library directly or define the requirement as ``PyLD[requests]`` or
|
|
108
|
+
``PyLD[aiohttp]``.
|
|
109
|
+
|
|
110
|
+
Quick Examples
|
|
111
|
+
--------------
|
|
112
|
+
|
|
113
|
+
.. code-block:: Python
|
|
114
|
+
|
|
115
|
+
from pyld import jsonld
|
|
116
|
+
import json
|
|
117
|
+
|
|
118
|
+
doc = {
|
|
119
|
+
"http://schema.org/name": "Manu Sporny",
|
|
120
|
+
"http://schema.org/url": {"@id": "http://manu.sporny.org/"},
|
|
121
|
+
"http://schema.org/image": {"@id": "http://manu.sporny.org/images/manu.png"}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
context = {
|
|
125
|
+
"name": "http://schema.org/name",
|
|
126
|
+
"homepage": {"@id": "http://schema.org/url", "@type": "@id"},
|
|
127
|
+
"image": {"@id": "http://schema.org/image", "@type": "@id"}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
# compact a document according to a particular context
|
|
131
|
+
# see: https://json-ld.org/spec/latest/json-ld/#compacted-document-form
|
|
132
|
+
compacted = jsonld.compact(doc, context)
|
|
133
|
+
|
|
134
|
+
print(json.dumps(compacted, indent=2))
|
|
135
|
+
# Output:
|
|
136
|
+
# {
|
|
137
|
+
# "@context": {...},
|
|
138
|
+
# "image": "http://manu.sporny.org/images/manu.png",
|
|
139
|
+
# "homepage": "http://manu.sporny.org/",
|
|
140
|
+
# "name": "Manu Sporny"
|
|
141
|
+
# }
|
|
142
|
+
|
|
143
|
+
# compact using URLs
|
|
144
|
+
jsonld.compact('http://example.org/doc', 'http://example.org/context')
|
|
145
|
+
|
|
146
|
+
# expand a document, removing its context
|
|
147
|
+
# see: https://json-ld.org/spec/latest/json-ld/#expanded-document-form
|
|
148
|
+
expanded = jsonld.expand(compacted)
|
|
149
|
+
|
|
150
|
+
print(json.dumps(expanded, indent=2))
|
|
151
|
+
# Output:
|
|
152
|
+
# [{
|
|
153
|
+
# "http://schema.org/image": [{"@id": "http://manu.sporny.org/images/manu.png"}],
|
|
154
|
+
# "http://schema.org/name": [{"@value": "Manu Sporny"}],
|
|
155
|
+
# "http://schema.org/url": [{"@id": "http://manu.sporny.org/"}]
|
|
156
|
+
# }]
|
|
157
|
+
|
|
158
|
+
# expand using URLs
|
|
159
|
+
jsonld.expand('http://example.org/doc')
|
|
160
|
+
|
|
161
|
+
# flatten a document
|
|
162
|
+
# see: https://json-ld.org/spec/latest/json-ld/#flattened-document-form
|
|
163
|
+
flattened = jsonld.flatten(doc)
|
|
164
|
+
# all deep-level trees flattened to the top-level
|
|
165
|
+
|
|
166
|
+
# frame a document
|
|
167
|
+
# see: https://json-ld.org/spec/latest/json-ld-framing/#introduction
|
|
168
|
+
framed = jsonld.frame(doc, frame)
|
|
169
|
+
# document transformed into a particular tree structure per the given frame
|
|
170
|
+
|
|
171
|
+
# normalize a document using the RDF Dataset Normalization Algorithm
|
|
172
|
+
# (URDNA2015), see: https://www.w3.org/TR/rdf-canon/
|
|
173
|
+
normalized = jsonld.normalize(
|
|
174
|
+
doc, {'algorithm': 'URDNA2015', 'format': 'application/n-quads'})
|
|
175
|
+
# normalized is a string that is a canonical representation of the document
|
|
176
|
+
# that can be used for hashing, comparison, etc.
|
|
177
|
+
|
|
178
|
+
Document Loader
|
|
179
|
+
---------------
|
|
180
|
+
|
|
181
|
+
The default document loader for PyLD uses Requests_. In a production
|
|
182
|
+
environment you may want to setup a custom loader that, at a minimum, sets a
|
|
183
|
+
timeout value. You can also force requests to use https, set client certs,
|
|
184
|
+
disable verification, or set other Requests_ parameters.
|
|
185
|
+
|
|
186
|
+
.. code-block:: Python
|
|
187
|
+
|
|
188
|
+
jsonld.set_document_loader(jsonld.requests_document_loader(timeout=...))
|
|
189
|
+
|
|
190
|
+
An asynchronous document loader using aiohttp_ is also available. Please note
|
|
191
|
+
that this document loader limits asynchronicity to fetching documents only.
|
|
192
|
+
The processing loops remain synchronous.
|
|
193
|
+
|
|
194
|
+
.. code-block:: Python
|
|
195
|
+
|
|
196
|
+
jsonld.set_document_loader(jsonld.aiohttp_document_loader(timeout=...))
|
|
197
|
+
|
|
198
|
+
When no document loader is specified, the default loader is set to Requests_.
|
|
199
|
+
If Requests_ is not available, the loader is set to aiohttp_. The fallback
|
|
200
|
+
document loader is a dummy document loader that raises an exception on every
|
|
201
|
+
invocation.
|
|
202
|
+
|
|
203
|
+
Commercial Support
|
|
204
|
+
------------------
|
|
205
|
+
|
|
206
|
+
Commercial support for this library is available upon request from
|
|
207
|
+
`Digital Bazaar`_: support@digitalbazaar.com.
|
|
208
|
+
|
|
209
|
+
Source
|
|
210
|
+
------
|
|
211
|
+
|
|
212
|
+
The source code for the Python implementation of the JSON-LD API
|
|
213
|
+
is available at:
|
|
214
|
+
|
|
215
|
+
https://github.com/digitalbazaar/pyld
|
|
216
|
+
|
|
217
|
+
Tests
|
|
218
|
+
-----
|
|
219
|
+
|
|
220
|
+
This library includes a sample testing utility which may be used to verify
|
|
221
|
+
that changes to the processor maintain the correct output.
|
|
222
|
+
|
|
223
|
+
To run the sample tests you will need to get the test suite files by cloning
|
|
224
|
+
the ``json-ld-api``, ``json-ld-framing``, and ``normalization`` repositories
|
|
225
|
+
hosted on GitHub:
|
|
226
|
+
|
|
227
|
+
- https://github.com/w3c/json-ld-api
|
|
228
|
+
- https://github.com/w3c/json-ld-framing
|
|
229
|
+
- https://github.com/json-ld/normalization
|
|
230
|
+
|
|
231
|
+
If the suites repositories are available as sibling directories of the PyLD
|
|
232
|
+
source directory, then all the tests can be run with the following:
|
|
233
|
+
|
|
234
|
+
.. code-block:: bash
|
|
235
|
+
|
|
236
|
+
python tests/runtests.py
|
|
237
|
+
|
|
238
|
+
If you want to test individual manifest ``.jsonld`` files or directories
|
|
239
|
+
containing a ``manifest.jsonld``, then you can supply these files or
|
|
240
|
+
directories as arguments:
|
|
241
|
+
|
|
242
|
+
.. code-block:: bash
|
|
243
|
+
|
|
244
|
+
python tests/runtests.py TEST_PATH [TEST_PATH...]
|
|
245
|
+
|
|
246
|
+
The test runner supports different document loaders by setting ``-l requests``
|
|
247
|
+
or ``-l aiohttp``. The default document loader is set to Requests_.
|
|
248
|
+
|
|
249
|
+
An EARL report can be generated using the ``-e`` or ``--earl`` option.
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
.. _Digital Bazaar: https://digitalbazaar.com/
|
|
253
|
+
|
|
254
|
+
.. _JSON-LD WG 1.1 API: https://www.w3.org/TR/json-ld11-api/
|
|
255
|
+
.. _JSON-LD WG 1.1 Framing: https://www.w3.org/TR/json-ld11-framing/
|
|
256
|
+
.. _JSON-LD WG 1.1: https://www.w3.org/TR/json-ld11/
|
|
257
|
+
|
|
258
|
+
.. _JSON-LD WG API latest: https://w3c.github.io/json-ld-api/
|
|
259
|
+
.. _JSON-LD WG Framing latest: https://w3c.github.io/json-ld-framing/
|
|
260
|
+
.. _JSON-LD WG latest: https://w3c.github.io/json-ld-syntax/
|
|
261
|
+
|
|
262
|
+
.. _JSON-LD Benchmarks: https://json-ld.org/benchmarks/
|
|
263
|
+
.. _JSON-LD WG: https://www.w3.org/2018/json-ld-wg/
|
|
264
|
+
.. _JSON-LD: https://json-ld.org/
|
|
265
|
+
.. _Microdata: http://www.w3.org/TR/microdata/
|
|
266
|
+
.. _Microformats: http://microformats.org/
|
|
267
|
+
.. _Python: https://www.python.org/
|
|
268
|
+
.. _Requests: http://docs.python-requests.org/
|
|
269
|
+
.. _aiohttp: https://aiohttp.readthedocs.io/
|
|
270
|
+
.. _RDFa: http://www.w3.org/TR/rdfa-core/
|
|
271
|
+
.. _RFC7159: http://tools.ietf.org/html/rfc7159
|
|
272
|
+
.. _WG test suite: https://github.com/w3c/json-ld-api/tree/master/tests
|
|
273
|
+
.. _errata: http://www.w3.org/2014/json-ld-errata
|
|
274
|
+
.. _pip: http://www.pip-installer.org/
|
|
275
|
+
.. _test runner: https://github.com/digitalbazaar/pyld/blob/master/tests/runtests.py
|
|
276
|
+
.. _test suite: https://github.com/json-ld/json-ld.org/tree/master/test-suite
|
|
@@ -139,7 +139,7 @@ Quick Examples
|
|
|
139
139
|
# document transformed into a particular tree structure per the given frame
|
|
140
140
|
|
|
141
141
|
# normalize a document using the RDF Dataset Normalization Algorithm
|
|
142
|
-
# (URDNA2015), see: https://
|
|
142
|
+
# (URDNA2015), see: https://www.w3.org/TR/rdf-canon/
|
|
143
143
|
normalized = jsonld.normalize(
|
|
144
144
|
doc, {'algorithm': 'URDNA2015', 'format': 'application/n-quads'})
|
|
145
145
|
# normalized is a string that is a canonical representation of the document
|
PyLD-2.0.4/README.txt
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
PyLD
|
|
2
|
+
====
|
|
3
|
+
|
|
4
|
+
.. image:: https://travis-ci.org/digitalbazaar/pyld.png?branch=master
|
|
5
|
+
:target: https://travis-ci.org/digitalbazaar/pyld
|
|
6
|
+
:alt: Build Status
|
|
7
|
+
|
|
8
|
+
Introduction
|
|
9
|
+
------------
|
|
10
|
+
|
|
11
|
+
This library is an implementation of the JSON-LD_ specification in Python_.
|
|
12
|
+
|
|
13
|
+
JSON, as specified in RFC7159_, is a simple language for representing
|
|
14
|
+
objects on the Web. Linked Data is a way of describing content across
|
|
15
|
+
different documents or Web sites. Web resources are described using
|
|
16
|
+
IRIs, and typically are dereferencable entities that may be used to find
|
|
17
|
+
more information, creating a "Web of Knowledge". JSON-LD_ is intended
|
|
18
|
+
to be a simple publishing method for expressing not only Linked Data in
|
|
19
|
+
JSON, but for adding semantics to existing JSON.
|
|
20
|
+
|
|
21
|
+
JSON-LD is designed as a light-weight syntax that can be used to express
|
|
22
|
+
Linked Data. It is primarily intended to be a way to express Linked Data
|
|
23
|
+
in JavaScript and other Web-based programming environments. It is also
|
|
24
|
+
useful when building interoperable Web Services and when storing Linked
|
|
25
|
+
Data in JSON-based document storage engines. It is practical and
|
|
26
|
+
designed to be as simple as possible, utilizing the large number of JSON
|
|
27
|
+
parsers and existing code that is in use today. It is designed to be
|
|
28
|
+
able to express key-value pairs, RDF data, RDFa_ data,
|
|
29
|
+
Microformats_ data, and Microdata_. That is, it supports every
|
|
30
|
+
major Web-based structured data model in use today.
|
|
31
|
+
|
|
32
|
+
The syntax does not require many applications to change their JSON, but
|
|
33
|
+
easily add meaning by adding context in a way that is either in-band or
|
|
34
|
+
out-of-band. The syntax is designed to not disturb already deployed
|
|
35
|
+
systems running on JSON, but provide a smooth migration path from JSON
|
|
36
|
+
to JSON with added semantics. Finally, the format is intended to be fast
|
|
37
|
+
to parse, fast to generate, stream-based and document-based processing
|
|
38
|
+
compatible, and require a very small memory footprint in order to operate.
|
|
39
|
+
|
|
40
|
+
Conformance
|
|
41
|
+
-----------
|
|
42
|
+
|
|
43
|
+
This library aims to conform with the following:
|
|
44
|
+
|
|
45
|
+
- `JSON-LD 1.1 <JSON-LD WG 1.1_>`_,
|
|
46
|
+
W3C Candidate Recommendation,
|
|
47
|
+
2019-12-12 or `newer <JSON-LD WG latest_>`_
|
|
48
|
+
- `JSON-LD 1.1 Processing Algorithms and API <JSON-LD WG 1.1 API_>`_,
|
|
49
|
+
W3C Candidate Recommendation,
|
|
50
|
+
2019-12-12 or `newer <JSON-LD WG API latest_>`_
|
|
51
|
+
- `JSON-LD 1.1 Framing <JSON-LD WG 1.1 Framing_>`_,
|
|
52
|
+
W3C Candidate Recommendation,
|
|
53
|
+
2019-12-12 or `newer <JSON-LD WG Framing latest_>`_
|
|
54
|
+
- Working Group `test suite <WG test suite_>`_
|
|
55
|
+
|
|
56
|
+
The `test runner`_ is often updated to note or skip newer tests that are not
|
|
57
|
+
yet supported.
|
|
58
|
+
|
|
59
|
+
Requirements
|
|
60
|
+
------------
|
|
61
|
+
|
|
62
|
+
- Python_ (3.6 or later)
|
|
63
|
+
- Requests_ (optional)
|
|
64
|
+
- aiohttp_ (optional, Python 3.5 or later)
|
|
65
|
+
|
|
66
|
+
Installation
|
|
67
|
+
------------
|
|
68
|
+
|
|
69
|
+
PyLD can be installed with a pip_ `package <https://pypi.org/project/PyLD/>`_
|
|
70
|
+
|
|
71
|
+
.. code-block:: bash
|
|
72
|
+
|
|
73
|
+
pip install PyLD
|
|
74
|
+
|
|
75
|
+
Defining a dependency on pyld will not pull in Requests_ or aiohttp_. If you
|
|
76
|
+
need one of these for a `Document Loader`_ then either depend on the desired
|
|
77
|
+
external library directly or define the requirement as ``PyLD[requests]`` or
|
|
78
|
+
``PyLD[aiohttp]``.
|
|
79
|
+
|
|
80
|
+
Quick Examples
|
|
81
|
+
--------------
|
|
82
|
+
|
|
83
|
+
.. code-block:: Python
|
|
84
|
+
|
|
85
|
+
from pyld import jsonld
|
|
86
|
+
import json
|
|
87
|
+
|
|
88
|
+
doc = {
|
|
89
|
+
"http://schema.org/name": "Manu Sporny",
|
|
90
|
+
"http://schema.org/url": {"@id": "http://manu.sporny.org/"},
|
|
91
|
+
"http://schema.org/image": {"@id": "http://manu.sporny.org/images/manu.png"}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
context = {
|
|
95
|
+
"name": "http://schema.org/name",
|
|
96
|
+
"homepage": {"@id": "http://schema.org/url", "@type": "@id"},
|
|
97
|
+
"image": {"@id": "http://schema.org/image", "@type": "@id"}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
# compact a document according to a particular context
|
|
101
|
+
# see: https://json-ld.org/spec/latest/json-ld/#compacted-document-form
|
|
102
|
+
compacted = jsonld.compact(doc, context)
|
|
103
|
+
|
|
104
|
+
print(json.dumps(compacted, indent=2))
|
|
105
|
+
# Output:
|
|
106
|
+
# {
|
|
107
|
+
# "@context": {...},
|
|
108
|
+
# "image": "http://manu.sporny.org/images/manu.png",
|
|
109
|
+
# "homepage": "http://manu.sporny.org/",
|
|
110
|
+
# "name": "Manu Sporny"
|
|
111
|
+
# }
|
|
112
|
+
|
|
113
|
+
# compact using URLs
|
|
114
|
+
jsonld.compact('http://example.org/doc', 'http://example.org/context')
|
|
115
|
+
|
|
116
|
+
# expand a document, removing its context
|
|
117
|
+
# see: https://json-ld.org/spec/latest/json-ld/#expanded-document-form
|
|
118
|
+
expanded = jsonld.expand(compacted)
|
|
119
|
+
|
|
120
|
+
print(json.dumps(expanded, indent=2))
|
|
121
|
+
# Output:
|
|
122
|
+
# [{
|
|
123
|
+
# "http://schema.org/image": [{"@id": "http://manu.sporny.org/images/manu.png"}],
|
|
124
|
+
# "http://schema.org/name": [{"@value": "Manu Sporny"}],
|
|
125
|
+
# "http://schema.org/url": [{"@id": "http://manu.sporny.org/"}]
|
|
126
|
+
# }]
|
|
127
|
+
|
|
128
|
+
# expand using URLs
|
|
129
|
+
jsonld.expand('http://example.org/doc')
|
|
130
|
+
|
|
131
|
+
# flatten a document
|
|
132
|
+
# see: https://json-ld.org/spec/latest/json-ld/#flattened-document-form
|
|
133
|
+
flattened = jsonld.flatten(doc)
|
|
134
|
+
# all deep-level trees flattened to the top-level
|
|
135
|
+
|
|
136
|
+
# frame a document
|
|
137
|
+
# see: https://json-ld.org/spec/latest/json-ld-framing/#introduction
|
|
138
|
+
framed = jsonld.frame(doc, frame)
|
|
139
|
+
# document transformed into a particular tree structure per the given frame
|
|
140
|
+
|
|
141
|
+
# normalize a document using the RDF Dataset Normalization Algorithm
|
|
142
|
+
# (URDNA2015), see: https://www.w3.org/TR/rdf-canon/
|
|
143
|
+
normalized = jsonld.normalize(
|
|
144
|
+
doc, {'algorithm': 'URDNA2015', 'format': 'application/n-quads'})
|
|
145
|
+
# normalized is a string that is a canonical representation of the document
|
|
146
|
+
# that can be used for hashing, comparison, etc.
|
|
147
|
+
|
|
148
|
+
Document Loader
|
|
149
|
+
---------------
|
|
150
|
+
|
|
151
|
+
The default document loader for PyLD uses Requests_. In a production
|
|
152
|
+
environment you may want to setup a custom loader that, at a minimum, sets a
|
|
153
|
+
timeout value. You can also force requests to use https, set client certs,
|
|
154
|
+
disable verification, or set other Requests_ parameters.
|
|
155
|
+
|
|
156
|
+
.. code-block:: Python
|
|
157
|
+
|
|
158
|
+
jsonld.set_document_loader(jsonld.requests_document_loader(timeout=...))
|
|
159
|
+
|
|
160
|
+
An asynchronous document loader using aiohttp_ is also available. Please note
|
|
161
|
+
that this document loader limits asynchronicity to fetching documents only.
|
|
162
|
+
The processing loops remain synchronous.
|
|
163
|
+
|
|
164
|
+
.. code-block:: Python
|
|
165
|
+
|
|
166
|
+
jsonld.set_document_loader(jsonld.aiohttp_document_loader(timeout=...))
|
|
167
|
+
|
|
168
|
+
When no document loader is specified, the default loader is set to Requests_.
|
|
169
|
+
If Requests_ is not available, the loader is set to aiohttp_. The fallback
|
|
170
|
+
document loader is a dummy document loader that raises an exception on every
|
|
171
|
+
invocation.
|
|
172
|
+
|
|
173
|
+
Commercial Support
|
|
174
|
+
------------------
|
|
175
|
+
|
|
176
|
+
Commercial support for this library is available upon request from
|
|
177
|
+
`Digital Bazaar`_: support@digitalbazaar.com.
|
|
178
|
+
|
|
179
|
+
Source
|
|
180
|
+
------
|
|
181
|
+
|
|
182
|
+
The source code for the Python implementation of the JSON-LD API
|
|
183
|
+
is available at:
|
|
184
|
+
|
|
185
|
+
https://github.com/digitalbazaar/pyld
|
|
186
|
+
|
|
187
|
+
Tests
|
|
188
|
+
-----
|
|
189
|
+
|
|
190
|
+
This library includes a sample testing utility which may be used to verify
|
|
191
|
+
that changes to the processor maintain the correct output.
|
|
192
|
+
|
|
193
|
+
To run the sample tests you will need to get the test suite files by cloning
|
|
194
|
+
the ``json-ld-api``, ``json-ld-framing``, and ``normalization`` repositories
|
|
195
|
+
hosted on GitHub:
|
|
196
|
+
|
|
197
|
+
- https://github.com/w3c/json-ld-api
|
|
198
|
+
- https://github.com/w3c/json-ld-framing
|
|
199
|
+
- https://github.com/json-ld/normalization
|
|
200
|
+
|
|
201
|
+
If the suites repositories are available as sibling directories of the PyLD
|
|
202
|
+
source directory, then all the tests can be run with the following:
|
|
203
|
+
|
|
204
|
+
.. code-block:: bash
|
|
205
|
+
|
|
206
|
+
python tests/runtests.py
|
|
207
|
+
|
|
208
|
+
If you want to test individual manifest ``.jsonld`` files or directories
|
|
209
|
+
containing a ``manifest.jsonld``, then you can supply these files or
|
|
210
|
+
directories as arguments:
|
|
211
|
+
|
|
212
|
+
.. code-block:: bash
|
|
213
|
+
|
|
214
|
+
python tests/runtests.py TEST_PATH [TEST_PATH...]
|
|
215
|
+
|
|
216
|
+
The test runner supports different document loaders by setting ``-l requests``
|
|
217
|
+
or ``-l aiohttp``. The default document loader is set to Requests_.
|
|
218
|
+
|
|
219
|
+
An EARL report can be generated using the ``-e`` or ``--earl`` option.
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
.. _Digital Bazaar: https://digitalbazaar.com/
|
|
223
|
+
|
|
224
|
+
.. _JSON-LD WG 1.1 API: https://www.w3.org/TR/json-ld11-api/
|
|
225
|
+
.. _JSON-LD WG 1.1 Framing: https://www.w3.org/TR/json-ld11-framing/
|
|
226
|
+
.. _JSON-LD WG 1.1: https://www.w3.org/TR/json-ld11/
|
|
227
|
+
|
|
228
|
+
.. _JSON-LD WG API latest: https://w3c.github.io/json-ld-api/
|
|
229
|
+
.. _JSON-LD WG Framing latest: https://w3c.github.io/json-ld-framing/
|
|
230
|
+
.. _JSON-LD WG latest: https://w3c.github.io/json-ld-syntax/
|
|
231
|
+
|
|
232
|
+
.. _JSON-LD Benchmarks: https://json-ld.org/benchmarks/
|
|
233
|
+
.. _JSON-LD WG: https://www.w3.org/2018/json-ld-wg/
|
|
234
|
+
.. _JSON-LD: https://json-ld.org/
|
|
235
|
+
.. _Microdata: http://www.w3.org/TR/microdata/
|
|
236
|
+
.. _Microformats: http://microformats.org/
|
|
237
|
+
.. _Python: https://www.python.org/
|
|
238
|
+
.. _Requests: http://docs.python-requests.org/
|
|
239
|
+
.. _aiohttp: https://aiohttp.readthedocs.io/
|
|
240
|
+
.. _RDFa: http://www.w3.org/TR/rdfa-core/
|
|
241
|
+
.. _RFC7159: http://tools.ietf.org/html/rfc7159
|
|
242
|
+
.. _WG test suite: https://github.com/w3c/json-ld-api/tree/master/tests
|
|
243
|
+
.. _errata: http://www.w3.org/2014/json-ld-errata
|
|
244
|
+
.. _pip: http://www.pip-installer.org/
|
|
245
|
+
.. _test runner: https://github.com/digitalbazaar/pyld/blob/master/tests/runtests.py
|
|
246
|
+
.. _test suite: https://github.com/json-ld/json-ld.org/tree/master/test-suite
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: PyLD
|
|
3
|
+
Version: 2.0.4
|
|
4
|
+
Summary: Python implementation of the JSON-LD API
|
|
5
|
+
Home-page: https://github.com/digitalbazaar/pyld
|
|
6
|
+
Author: Digital Bazaar
|
|
7
|
+
Author-email: support@digitalbazaar.com
|
|
8
|
+
License: BSD 3-Clause license
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Environment :: Web Environment
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python
|
|
16
|
+
Classifier: Topic :: Internet
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: cachetools
|
|
20
|
+
Requires-Dist: frozendict
|
|
21
|
+
Requires-Dist: lxml
|
|
22
|
+
Provides-Extra: requests
|
|
23
|
+
Requires-Dist: requests; extra == "requests"
|
|
24
|
+
Provides-Extra: aiohttp
|
|
25
|
+
Requires-Dist: aiohttp; extra == "aiohttp"
|
|
26
|
+
Provides-Extra: cachetools
|
|
27
|
+
Requires-Dist: cachetools; extra == "cachetools"
|
|
28
|
+
Provides-Extra: frozendict
|
|
29
|
+
Requires-Dist: frozendict; extra == "frozendict"
|
|
30
|
+
|
|
31
|
+
PyLD
|
|
32
|
+
====
|
|
33
|
+
|
|
34
|
+
.. image:: https://travis-ci.org/digitalbazaar/pyld.png?branch=master
|
|
35
|
+
:target: https://travis-ci.org/digitalbazaar/pyld
|
|
36
|
+
:alt: Build Status
|
|
37
|
+
|
|
38
|
+
Introduction
|
|
39
|
+
------------
|
|
40
|
+
|
|
41
|
+
This library is an implementation of the JSON-LD_ specification in Python_.
|
|
42
|
+
|
|
43
|
+
JSON, as specified in RFC7159_, is a simple language for representing
|
|
44
|
+
objects on the Web. Linked Data is a way of describing content across
|
|
45
|
+
different documents or Web sites. Web resources are described using
|
|
46
|
+
IRIs, and typically are dereferencable entities that may be used to find
|
|
47
|
+
more information, creating a "Web of Knowledge". JSON-LD_ is intended
|
|
48
|
+
to be a simple publishing method for expressing not only Linked Data in
|
|
49
|
+
JSON, but for adding semantics to existing JSON.
|
|
50
|
+
|
|
51
|
+
JSON-LD is designed as a light-weight syntax that can be used to express
|
|
52
|
+
Linked Data. It is primarily intended to be a way to express Linked Data
|
|
53
|
+
in JavaScript and other Web-based programming environments. It is also
|
|
54
|
+
useful when building interoperable Web Services and when storing Linked
|
|
55
|
+
Data in JSON-based document storage engines. It is practical and
|
|
56
|
+
designed to be as simple as possible, utilizing the large number of JSON
|
|
57
|
+
parsers and existing code that is in use today. It is designed to be
|
|
58
|
+
able to express key-value pairs, RDF data, RDFa_ data,
|
|
59
|
+
Microformats_ data, and Microdata_. That is, it supports every
|
|
60
|
+
major Web-based structured data model in use today.
|
|
61
|
+
|
|
62
|
+
The syntax does not require many applications to change their JSON, but
|
|
63
|
+
easily add meaning by adding context in a way that is either in-band or
|
|
64
|
+
out-of-band. The syntax is designed to not disturb already deployed
|
|
65
|
+
systems running on JSON, but provide a smooth migration path from JSON
|
|
66
|
+
to JSON with added semantics. Finally, the format is intended to be fast
|
|
67
|
+
to parse, fast to generate, stream-based and document-based processing
|
|
68
|
+
compatible, and require a very small memory footprint in order to operate.
|
|
69
|
+
|
|
70
|
+
Conformance
|
|
71
|
+
-----------
|
|
72
|
+
|
|
73
|
+
This library aims to conform with the following:
|
|
74
|
+
|
|
75
|
+
- `JSON-LD 1.1 <JSON-LD WG 1.1_>`_,
|
|
76
|
+
W3C Candidate Recommendation,
|
|
77
|
+
2019-12-12 or `newer <JSON-LD WG latest_>`_
|
|
78
|
+
- `JSON-LD 1.1 Processing Algorithms and API <JSON-LD WG 1.1 API_>`_,
|
|
79
|
+
W3C Candidate Recommendation,
|
|
80
|
+
2019-12-12 or `newer <JSON-LD WG API latest_>`_
|
|
81
|
+
- `JSON-LD 1.1 Framing <JSON-LD WG 1.1 Framing_>`_,
|
|
82
|
+
W3C Candidate Recommendation,
|
|
83
|
+
2019-12-12 or `newer <JSON-LD WG Framing latest_>`_
|
|
84
|
+
- Working Group `test suite <WG test suite_>`_
|
|
85
|
+
|
|
86
|
+
The `test runner`_ is often updated to note or skip newer tests that are not
|
|
87
|
+
yet supported.
|
|
88
|
+
|
|
89
|
+
Requirements
|
|
90
|
+
------------
|
|
91
|
+
|
|
92
|
+
- Python_ (3.6 or later)
|
|
93
|
+
- Requests_ (optional)
|
|
94
|
+
- aiohttp_ (optional, Python 3.5 or later)
|
|
95
|
+
|
|
96
|
+
Installation
|
|
97
|
+
------------
|
|
98
|
+
|
|
99
|
+
PyLD can be installed with a pip_ `package <https://pypi.org/project/PyLD/>`_
|
|
100
|
+
|
|
101
|
+
.. code-block:: bash
|
|
102
|
+
|
|
103
|
+
pip install PyLD
|
|
104
|
+
|
|
105
|
+
Defining a dependency on pyld will not pull in Requests_ or aiohttp_. If you
|
|
106
|
+
need one of these for a `Document Loader`_ then either depend on the desired
|
|
107
|
+
external library directly or define the requirement as ``PyLD[requests]`` or
|
|
108
|
+
``PyLD[aiohttp]``.
|
|
109
|
+
|
|
110
|
+
Quick Examples
|
|
111
|
+
--------------
|
|
112
|
+
|
|
113
|
+
.. code-block:: Python
|
|
114
|
+
|
|
115
|
+
from pyld import jsonld
|
|
116
|
+
import json
|
|
117
|
+
|
|
118
|
+
doc = {
|
|
119
|
+
"http://schema.org/name": "Manu Sporny",
|
|
120
|
+
"http://schema.org/url": {"@id": "http://manu.sporny.org/"},
|
|
121
|
+
"http://schema.org/image": {"@id": "http://manu.sporny.org/images/manu.png"}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
context = {
|
|
125
|
+
"name": "http://schema.org/name",
|
|
126
|
+
"homepage": {"@id": "http://schema.org/url", "@type": "@id"},
|
|
127
|
+
"image": {"@id": "http://schema.org/image", "@type": "@id"}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
# compact a document according to a particular context
|
|
131
|
+
# see: https://json-ld.org/spec/latest/json-ld/#compacted-document-form
|
|
132
|
+
compacted = jsonld.compact(doc, context)
|
|
133
|
+
|
|
134
|
+
print(json.dumps(compacted, indent=2))
|
|
135
|
+
# Output:
|
|
136
|
+
# {
|
|
137
|
+
# "@context": {...},
|
|
138
|
+
# "image": "http://manu.sporny.org/images/manu.png",
|
|
139
|
+
# "homepage": "http://manu.sporny.org/",
|
|
140
|
+
# "name": "Manu Sporny"
|
|
141
|
+
# }
|
|
142
|
+
|
|
143
|
+
# compact using URLs
|
|
144
|
+
jsonld.compact('http://example.org/doc', 'http://example.org/context')
|
|
145
|
+
|
|
146
|
+
# expand a document, removing its context
|
|
147
|
+
# see: https://json-ld.org/spec/latest/json-ld/#expanded-document-form
|
|
148
|
+
expanded = jsonld.expand(compacted)
|
|
149
|
+
|
|
150
|
+
print(json.dumps(expanded, indent=2))
|
|
151
|
+
# Output:
|
|
152
|
+
# [{
|
|
153
|
+
# "http://schema.org/image": [{"@id": "http://manu.sporny.org/images/manu.png"}],
|
|
154
|
+
# "http://schema.org/name": [{"@value": "Manu Sporny"}],
|
|
155
|
+
# "http://schema.org/url": [{"@id": "http://manu.sporny.org/"}]
|
|
156
|
+
# }]
|
|
157
|
+
|
|
158
|
+
# expand using URLs
|
|
159
|
+
jsonld.expand('http://example.org/doc')
|
|
160
|
+
|
|
161
|
+
# flatten a document
|
|
162
|
+
# see: https://json-ld.org/spec/latest/json-ld/#flattened-document-form
|
|
163
|
+
flattened = jsonld.flatten(doc)
|
|
164
|
+
# all deep-level trees flattened to the top-level
|
|
165
|
+
|
|
166
|
+
# frame a document
|
|
167
|
+
# see: https://json-ld.org/spec/latest/json-ld-framing/#introduction
|
|
168
|
+
framed = jsonld.frame(doc, frame)
|
|
169
|
+
# document transformed into a particular tree structure per the given frame
|
|
170
|
+
|
|
171
|
+
# normalize a document using the RDF Dataset Normalization Algorithm
|
|
172
|
+
# (URDNA2015), see: https://www.w3.org/TR/rdf-canon/
|
|
173
|
+
normalized = jsonld.normalize(
|
|
174
|
+
doc, {'algorithm': 'URDNA2015', 'format': 'application/n-quads'})
|
|
175
|
+
# normalized is a string that is a canonical representation of the document
|
|
176
|
+
# that can be used for hashing, comparison, etc.
|
|
177
|
+
|
|
178
|
+
Document Loader
|
|
179
|
+
---------------
|
|
180
|
+
|
|
181
|
+
The default document loader for PyLD uses Requests_. In a production
|
|
182
|
+
environment you may want to setup a custom loader that, at a minimum, sets a
|
|
183
|
+
timeout value. You can also force requests to use https, set client certs,
|
|
184
|
+
disable verification, or set other Requests_ parameters.
|
|
185
|
+
|
|
186
|
+
.. code-block:: Python
|
|
187
|
+
|
|
188
|
+
jsonld.set_document_loader(jsonld.requests_document_loader(timeout=...))
|
|
189
|
+
|
|
190
|
+
An asynchronous document loader using aiohttp_ is also available. Please note
|
|
191
|
+
that this document loader limits asynchronicity to fetching documents only.
|
|
192
|
+
The processing loops remain synchronous.
|
|
193
|
+
|
|
194
|
+
.. code-block:: Python
|
|
195
|
+
|
|
196
|
+
jsonld.set_document_loader(jsonld.aiohttp_document_loader(timeout=...))
|
|
197
|
+
|
|
198
|
+
When no document loader is specified, the default loader is set to Requests_.
|
|
199
|
+
If Requests_ is not available, the loader is set to aiohttp_. The fallback
|
|
200
|
+
document loader is a dummy document loader that raises an exception on every
|
|
201
|
+
invocation.
|
|
202
|
+
|
|
203
|
+
Commercial Support
|
|
204
|
+
------------------
|
|
205
|
+
|
|
206
|
+
Commercial support for this library is available upon request from
|
|
207
|
+
`Digital Bazaar`_: support@digitalbazaar.com.
|
|
208
|
+
|
|
209
|
+
Source
|
|
210
|
+
------
|
|
211
|
+
|
|
212
|
+
The source code for the Python implementation of the JSON-LD API
|
|
213
|
+
is available at:
|
|
214
|
+
|
|
215
|
+
https://github.com/digitalbazaar/pyld
|
|
216
|
+
|
|
217
|
+
Tests
|
|
218
|
+
-----
|
|
219
|
+
|
|
220
|
+
This library includes a sample testing utility which may be used to verify
|
|
221
|
+
that changes to the processor maintain the correct output.
|
|
222
|
+
|
|
223
|
+
To run the sample tests you will need to get the test suite files by cloning
|
|
224
|
+
the ``json-ld-api``, ``json-ld-framing``, and ``normalization`` repositories
|
|
225
|
+
hosted on GitHub:
|
|
226
|
+
|
|
227
|
+
- https://github.com/w3c/json-ld-api
|
|
228
|
+
- https://github.com/w3c/json-ld-framing
|
|
229
|
+
- https://github.com/json-ld/normalization
|
|
230
|
+
|
|
231
|
+
If the suites repositories are available as sibling directories of the PyLD
|
|
232
|
+
source directory, then all the tests can be run with the following:
|
|
233
|
+
|
|
234
|
+
.. code-block:: bash
|
|
235
|
+
|
|
236
|
+
python tests/runtests.py
|
|
237
|
+
|
|
238
|
+
If you want to test individual manifest ``.jsonld`` files or directories
|
|
239
|
+
containing a ``manifest.jsonld``, then you can supply these files or
|
|
240
|
+
directories as arguments:
|
|
241
|
+
|
|
242
|
+
.. code-block:: bash
|
|
243
|
+
|
|
244
|
+
python tests/runtests.py TEST_PATH [TEST_PATH...]
|
|
245
|
+
|
|
246
|
+
The test runner supports different document loaders by setting ``-l requests``
|
|
247
|
+
or ``-l aiohttp``. The default document loader is set to Requests_.
|
|
248
|
+
|
|
249
|
+
An EARL report can be generated using the ``-e`` or ``--earl`` option.
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
.. _Digital Bazaar: https://digitalbazaar.com/
|
|
253
|
+
|
|
254
|
+
.. _JSON-LD WG 1.1 API: https://www.w3.org/TR/json-ld11-api/
|
|
255
|
+
.. _JSON-LD WG 1.1 Framing: https://www.w3.org/TR/json-ld11-framing/
|
|
256
|
+
.. _JSON-LD WG 1.1: https://www.w3.org/TR/json-ld11/
|
|
257
|
+
|
|
258
|
+
.. _JSON-LD WG API latest: https://w3c.github.io/json-ld-api/
|
|
259
|
+
.. _JSON-LD WG Framing latest: https://w3c.github.io/json-ld-framing/
|
|
260
|
+
.. _JSON-LD WG latest: https://w3c.github.io/json-ld-syntax/
|
|
261
|
+
|
|
262
|
+
.. _JSON-LD Benchmarks: https://json-ld.org/benchmarks/
|
|
263
|
+
.. _JSON-LD WG: https://www.w3.org/2018/json-ld-wg/
|
|
264
|
+
.. _JSON-LD: https://json-ld.org/
|
|
265
|
+
.. _Microdata: http://www.w3.org/TR/microdata/
|
|
266
|
+
.. _Microformats: http://microformats.org/
|
|
267
|
+
.. _Python: https://www.python.org/
|
|
268
|
+
.. _Requests: http://docs.python-requests.org/
|
|
269
|
+
.. _aiohttp: https://aiohttp.readthedocs.io/
|
|
270
|
+
.. _RDFa: http://www.w3.org/TR/rdfa-core/
|
|
271
|
+
.. _RFC7159: http://tools.ietf.org/html/rfc7159
|
|
272
|
+
.. _WG test suite: https://github.com/w3c/json-ld-api/tree/master/tests
|
|
273
|
+
.. _errata: http://www.w3.org/2014/json-ld-errata
|
|
274
|
+
.. _pip: http://www.pip-installer.org/
|
|
275
|
+
.. _test runner: https://github.com/digitalbazaar/pyld/blob/master/tests/runtests.py
|
|
276
|
+
.. _test suite: https://github.com/json-ld/json-ld.org/tree/master/test-suite
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
CHANGELOG.md
|
|
2
|
+
LICENSE
|
|
3
|
+
MANIFEST.in
|
|
4
|
+
README.rst
|
|
5
|
+
README.txt
|
|
6
|
+
setup.py
|
|
7
|
+
lib/PyLD.egg-info/PKG-INFO
|
|
8
|
+
lib/PyLD.egg-info/SOURCES.txt
|
|
9
|
+
lib/PyLD.egg-info/dependency_links.txt
|
|
10
|
+
lib/PyLD.egg-info/requires.txt
|
|
11
|
+
lib/PyLD.egg-info/top_level.txt
|
|
12
|
+
lib/c14n/Canonicalize.py
|
|
13
|
+
lib/c14n/NumberToJson.py
|
|
14
|
+
lib/c14n/__init__.py
|
|
15
|
+
lib/pyld/__about__.py
|
|
16
|
+
lib/pyld/__init__.py
|
|
17
|
+
lib/pyld/context_resolver.py
|
|
18
|
+
lib/pyld/jsonld.py
|
|
19
|
+
lib/pyld/resolved_context.py
|
|
20
|
+
lib/pyld/documentloader/__init__.py
|
|
21
|
+
lib/pyld/documentloader/aiohttp.py
|
|
22
|
+
lib/pyld/documentloader/requests.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -4,6 +4,6 @@ __all__ = [
|
|
|
4
4
|
'__copyright__', '__license__', '__version__'
|
|
5
5
|
]
|
|
6
6
|
|
|
7
|
-
__copyright__ = 'Copyright (c) 2011-
|
|
7
|
+
__copyright__ = 'Copyright (c) 2011-2024 Digital Bazaar, Inc.'
|
|
8
8
|
__license__ = 'New BSD license'
|
|
9
|
-
__version__ = '2.0.
|
|
9
|
+
__version__ = '2.0.4'
|
|
@@ -63,7 +63,7 @@ class ContextResolver:
|
|
|
63
63
|
all_resolved.extend(resolved)
|
|
64
64
|
else:
|
|
65
65
|
all_resolved.append(resolved)
|
|
66
|
-
elif
|
|
66
|
+
elif ctx is None or ctx is False:
|
|
67
67
|
all_resolved.append(ResolvedContext(False))
|
|
68
68
|
elif not isinstance(ctx, dict) and not isinstance(ctx, frozendict):
|
|
69
69
|
raise jsonld.JsonLdError(
|
|
@@ -2320,7 +2320,7 @@ class JsonLdProcessor(object):
|
|
|
2320
2320
|
for type_ in sorted(types):
|
|
2321
2321
|
ctx = JsonLdProcessor.get_context_value(
|
|
2322
2322
|
type_scoped_ctx, type_, '@context')
|
|
2323
|
-
if ctx is not None:
|
|
2323
|
+
if ctx is not None and ctx is not False:
|
|
2324
2324
|
active_ctx = self._process_context(
|
|
2325
2325
|
active_ctx, ctx, options, propagate=False)
|
|
2326
2326
|
|
|
@@ -3070,7 +3070,7 @@ class JsonLdProcessor(object):
|
|
|
3070
3070
|
active_ctx['_uuid'] = str(uuid.uuid1())
|
|
3071
3071
|
|
|
3072
3072
|
# reset to initial context
|
|
3073
|
-
if
|
|
3073
|
+
if ctx is None or ctx is False:
|
|
3074
3074
|
if (not override_protected and
|
|
3075
3075
|
any(v.get('protected') for v in rval['mappings'].values())):
|
|
3076
3076
|
raise JsonLdError(
|
PyLD-2.0.4/setup.cfg
ADDED
PyLD-2.0.3/PKG-INFO
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 1.1
|
|
2
|
-
Name: PyLD
|
|
3
|
-
Version: 2.0.3
|
|
4
|
-
Summary: Python implementation of the JSON-LD API
|
|
5
|
-
Home-page: https://github.com/digitalbazaar/pyld
|
|
6
|
-
Author: Digital Bazaar
|
|
7
|
-
Author-email: support@digitalbazaar.com
|
|
8
|
-
License: BSD 3-Clause license
|
|
9
|
-
Description: PyLD
|
|
10
|
-
====
|
|
11
|
-
|
|
12
|
-
.. image:: https://travis-ci.org/digitalbazaar/pyld.png?branch=master
|
|
13
|
-
:target: https://travis-ci.org/digitalbazaar/pyld
|
|
14
|
-
:alt: Build Status
|
|
15
|
-
|
|
16
|
-
Introduction
|
|
17
|
-
------------
|
|
18
|
-
|
|
19
|
-
This library is an implementation of the JSON-LD_ specification in Python_.
|
|
20
|
-
|
|
21
|
-
JSON, as specified in RFC7159_, is a simple language for representing
|
|
22
|
-
objects on the Web. Linked Data is a way of describing content across
|
|
23
|
-
different documents or Web sites. Web resources are described using
|
|
24
|
-
IRIs, and typically are dereferencable entities that may be used to find
|
|
25
|
-
more information, creating a "Web of Knowledge". JSON-LD_ is intended
|
|
26
|
-
to be a simple publishing method for expressing not only Linked Data in
|
|
27
|
-
JSON, but for adding semantics to existing JSON.
|
|
28
|
-
|
|
29
|
-
JSON-LD is designed as a light-weight syntax that can be used to express
|
|
30
|
-
Linked Data. It is primarily intended to be a way to express Linked Data
|
|
31
|
-
in JavaScript and other Web-based programming environments. It is also
|
|
32
|
-
useful when building interoperable Web Services and when storing Linked
|
|
33
|
-
Data in JSON-based document storage engines. It is practical and
|
|
34
|
-
designed to be as simple as possible, utilizing the large number of JSON
|
|
35
|
-
parsers and existing code that is in use today. It is designed to be
|
|
36
|
-
able to express key-value pairs, RDF data, RDFa_ data,
|
|
37
|
-
Microformats_ data, and Microdata_. That is, it supports every
|
|
38
|
-
major Web-based structured data model in use today.
|
|
39
|
-
|
|
40
|
-
The syntax does not require many applications to change their JSON, but
|
|
41
|
-
easily add meaning by adding context in a way that is either in-band or
|
|
42
|
-
out-of-band. The syntax is designed to not disturb already deployed
|
|
43
|
-
systems running on JSON, but provide a smooth migration path from JSON
|
|
44
|
-
to JSON with added semantics. Finally, the format is intended to be fast
|
|
45
|
-
to parse, fast to generate, stream-based and document-based processing
|
|
46
|
-
compatible, and require a very small memory footprint in order to operate.
|
|
47
|
-
|
|
48
|
-
Conformance
|
|
49
|
-
-----------
|
|
50
|
-
|
|
51
|
-
This library aims to conform with the following:
|
|
52
|
-
|
|
53
|
-
- `JSON-LD 1.1 <JSON-LD WG 1.1_>`_,
|
|
54
|
-
W3C Candidate Recommendation,
|
|
55
|
-
2019-12-12 or `newer <JSON-LD WG latest_>`_
|
|
56
|
-
- `JSON-LD 1.1 Processing Algorithms and API <JSON-LD WG 1.1 API_>`_,
|
|
57
|
-
W3C Candidate Recommendation,
|
|
58
|
-
2019-12-12 or `newer <JSON-LD WG API latest_>`_
|
|
59
|
-
- `JSON-LD 1.1 Framing <JSON-LD WG 1.1 Framing_>`_,
|
|
60
|
-
W3C Candidate Recommendation,
|
|
61
|
-
2019-12-12 or `newer <JSON-LD WG Framing latest_>`_
|
|
62
|
-
- Working Group `test suite <WG test suite_>`_
|
|
63
|
-
|
|
64
|
-
The `test runner`_ is often updated to note or skip newer tests that are not
|
|
65
|
-
yet supported.
|
|
66
|
-
|
|
67
|
-
Requirements
|
|
68
|
-
------------
|
|
69
|
-
|
|
70
|
-
- Python_ (3.6 or later)
|
|
71
|
-
- Requests_ (optional)
|
|
72
|
-
- aiohttp_ (optional, Python 3.5 or later)
|
|
73
|
-
|
|
74
|
-
Installation
|
|
75
|
-
------------
|
|
76
|
-
|
|
77
|
-
PyLD can be installed with a pip_ `package <https://pypi.org/project/PyLD/>`_
|
|
78
|
-
|
|
79
|
-
.. code-block:: bash
|
|
80
|
-
|
|
81
|
-
pip install PyLD
|
|
82
|
-
|
|
83
|
-
Defining a dependency on pyld will not pull in Requests_ or aiohttp_. If you
|
|
84
|
-
need one of these for a `Document Loader`_ then either depend on the desired
|
|
85
|
-
external library directly or define the requirement as ``PyLD[requests]`` or
|
|
86
|
-
``PyLD[aiohttp]``.
|
|
87
|
-
|
|
88
|
-
Quick Examples
|
|
89
|
-
--------------
|
|
90
|
-
|
|
91
|
-
.. code-block:: Python
|
|
92
|
-
|
|
93
|
-
from pyld import jsonld
|
|
94
|
-
import json
|
|
95
|
-
|
|
96
|
-
doc = {
|
|
97
|
-
"http://schema.org/name": "Manu Sporny",
|
|
98
|
-
"http://schema.org/url": {"@id": "http://manu.sporny.org/"},
|
|
99
|
-
"http://schema.org/image": {"@id": "http://manu.sporny.org/images/manu.png"}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
context = {
|
|
103
|
-
"name": "http://schema.org/name",
|
|
104
|
-
"homepage": {"@id": "http://schema.org/url", "@type": "@id"},
|
|
105
|
-
"image": {"@id": "http://schema.org/image", "@type": "@id"}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
# compact a document according to a particular context
|
|
109
|
-
# see: https://json-ld.org/spec/latest/json-ld/#compacted-document-form
|
|
110
|
-
compacted = jsonld.compact(doc, context)
|
|
111
|
-
|
|
112
|
-
print(json.dumps(compacted, indent=2))
|
|
113
|
-
# Output:
|
|
114
|
-
# {
|
|
115
|
-
# "@context": {...},
|
|
116
|
-
# "image": "http://manu.sporny.org/images/manu.png",
|
|
117
|
-
# "homepage": "http://manu.sporny.org/",
|
|
118
|
-
# "name": "Manu Sporny"
|
|
119
|
-
# }
|
|
120
|
-
|
|
121
|
-
# compact using URLs
|
|
122
|
-
jsonld.compact('http://example.org/doc', 'http://example.org/context')
|
|
123
|
-
|
|
124
|
-
# expand a document, removing its context
|
|
125
|
-
# see: https://json-ld.org/spec/latest/json-ld/#expanded-document-form
|
|
126
|
-
expanded = jsonld.expand(compacted)
|
|
127
|
-
|
|
128
|
-
print(json.dumps(expanded, indent=2))
|
|
129
|
-
# Output:
|
|
130
|
-
# [{
|
|
131
|
-
# "http://schema.org/image": [{"@id": "http://manu.sporny.org/images/manu.png"}],
|
|
132
|
-
# "http://schema.org/name": [{"@value": "Manu Sporny"}],
|
|
133
|
-
# "http://schema.org/url": [{"@id": "http://manu.sporny.org/"}]
|
|
134
|
-
# }]
|
|
135
|
-
|
|
136
|
-
# expand using URLs
|
|
137
|
-
jsonld.expand('http://example.org/doc')
|
|
138
|
-
|
|
139
|
-
# flatten a document
|
|
140
|
-
# see: https://json-ld.org/spec/latest/json-ld/#flattened-document-form
|
|
141
|
-
flattened = jsonld.flatten(doc)
|
|
142
|
-
# all deep-level trees flattened to the top-level
|
|
143
|
-
|
|
144
|
-
# frame a document
|
|
145
|
-
# see: https://json-ld.org/spec/latest/json-ld-framing/#introduction
|
|
146
|
-
framed = jsonld.frame(doc, frame)
|
|
147
|
-
# document transformed into a particular tree structure per the given frame
|
|
148
|
-
|
|
149
|
-
# normalize a document using the RDF Dataset Normalization Algorithm
|
|
150
|
-
# (URDNA2015), see: https://json-ld.github.io/normalization/spec/
|
|
151
|
-
normalized = jsonld.normalize(
|
|
152
|
-
doc, {'algorithm': 'URDNA2015', 'format': 'application/n-quads'})
|
|
153
|
-
# normalized is a string that is a canonical representation of the document
|
|
154
|
-
# that can be used for hashing, comparison, etc.
|
|
155
|
-
|
|
156
|
-
Document Loader
|
|
157
|
-
---------------
|
|
158
|
-
|
|
159
|
-
The default document loader for PyLD uses Requests_. In a production
|
|
160
|
-
environment you may want to setup a custom loader that, at a minimum, sets a
|
|
161
|
-
timeout value. You can also force requests to use https, set client certs,
|
|
162
|
-
disable verification, or set other Requests_ parameters.
|
|
163
|
-
|
|
164
|
-
.. code-block:: Python
|
|
165
|
-
|
|
166
|
-
jsonld.set_document_loader(jsonld.requests_document_loader(timeout=...))
|
|
167
|
-
|
|
168
|
-
An asynchronous document loader using aiohttp_ is also available. Please note
|
|
169
|
-
that this document loader limits asynchronicity to fetching documents only.
|
|
170
|
-
The processing loops remain synchronous.
|
|
171
|
-
|
|
172
|
-
.. code-block:: Python
|
|
173
|
-
|
|
174
|
-
jsonld.set_document_loader(jsonld.aiohttp_document_loader(timeout=...))
|
|
175
|
-
|
|
176
|
-
When no document loader is specified, the default loader is set to Requests_.
|
|
177
|
-
If Requests_ is not available, the loader is set to aiohttp_. The fallback
|
|
178
|
-
document loader is a dummy document loader that raises an exception on every
|
|
179
|
-
invocation.
|
|
180
|
-
|
|
181
|
-
Commercial Support
|
|
182
|
-
------------------
|
|
183
|
-
|
|
184
|
-
Commercial support for this library is available upon request from
|
|
185
|
-
`Digital Bazaar`_: support@digitalbazaar.com.
|
|
186
|
-
|
|
187
|
-
Source
|
|
188
|
-
------
|
|
189
|
-
|
|
190
|
-
The source code for the Python implementation of the JSON-LD API
|
|
191
|
-
is available at:
|
|
192
|
-
|
|
193
|
-
https://github.com/digitalbazaar/pyld
|
|
194
|
-
|
|
195
|
-
Tests
|
|
196
|
-
-----
|
|
197
|
-
|
|
198
|
-
This library includes a sample testing utility which may be used to verify
|
|
199
|
-
that changes to the processor maintain the correct output.
|
|
200
|
-
|
|
201
|
-
To run the sample tests you will need to get the test suite files by cloning
|
|
202
|
-
the ``json-ld-api``, ``json-ld-framing``, and ``normalization`` repositories
|
|
203
|
-
hosted on GitHub:
|
|
204
|
-
|
|
205
|
-
- https://github.com/w3c/json-ld-api
|
|
206
|
-
- https://github.com/w3c/json-ld-framing
|
|
207
|
-
- https://github.com/json-ld/normalization
|
|
208
|
-
|
|
209
|
-
If the suites repositories are available as sibling directories of the PyLD
|
|
210
|
-
source directory, then all the tests can be run with the following:
|
|
211
|
-
|
|
212
|
-
.. code-block:: bash
|
|
213
|
-
|
|
214
|
-
python tests/runtests.py
|
|
215
|
-
|
|
216
|
-
If you want to test individual manifest ``.jsonld`` files or directories
|
|
217
|
-
containing a ``manifest.jsonld``, then you can supply these files or
|
|
218
|
-
directories as arguments:
|
|
219
|
-
|
|
220
|
-
.. code-block:: bash
|
|
221
|
-
|
|
222
|
-
python tests/runtests.py TEST_PATH [TEST_PATH...]
|
|
223
|
-
|
|
224
|
-
The test runner supports different document loaders by setting ``-l requests``
|
|
225
|
-
or ``-l aiohttp``. The default document loader is set to Requests_.
|
|
226
|
-
|
|
227
|
-
An EARL report can be generated using the ``-e`` or ``--earl`` option.
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
.. _Digital Bazaar: https://digitalbazaar.com/
|
|
231
|
-
|
|
232
|
-
.. _JSON-LD WG 1.1 API: https://www.w3.org/TR/json-ld11-api/
|
|
233
|
-
.. _JSON-LD WG 1.1 Framing: https://www.w3.org/TR/json-ld11-framing/
|
|
234
|
-
.. _JSON-LD WG 1.1: https://www.w3.org/TR/json-ld11/
|
|
235
|
-
|
|
236
|
-
.. _JSON-LD WG API latest: https://w3c.github.io/json-ld-api/
|
|
237
|
-
.. _JSON-LD WG Framing latest: https://w3c.github.io/json-ld-framing/
|
|
238
|
-
.. _JSON-LD WG latest: https://w3c.github.io/json-ld-syntax/
|
|
239
|
-
|
|
240
|
-
.. _JSON-LD Benchmarks: https://json-ld.org/benchmarks/
|
|
241
|
-
.. _JSON-LD WG: https://www.w3.org/2018/json-ld-wg/
|
|
242
|
-
.. _JSON-LD: https://json-ld.org/
|
|
243
|
-
.. _Microdata: http://www.w3.org/TR/microdata/
|
|
244
|
-
.. _Microformats: http://microformats.org/
|
|
245
|
-
.. _Python: https://www.python.org/
|
|
246
|
-
.. _Requests: http://docs.python-requests.org/
|
|
247
|
-
.. _aiohttp: https://aiohttp.readthedocs.io/
|
|
248
|
-
.. _RDFa: http://www.w3.org/TR/rdfa-core/
|
|
249
|
-
.. _RFC7159: http://tools.ietf.org/html/rfc7159
|
|
250
|
-
.. _WG test suite: https://github.com/w3c/json-ld-api/tree/master/tests
|
|
251
|
-
.. _errata: http://www.w3.org/2014/json-ld-errata
|
|
252
|
-
.. _pip: http://www.pip-installer.org/
|
|
253
|
-
.. _test runner: https://github.com/digitalbazaar/pyld/blob/master/tests/runtests.py
|
|
254
|
-
.. _test suite: https://github.com/json-ld/json-ld.org/tree/master/test-suite
|
|
255
|
-
|
|
256
|
-
Platform: UNKNOWN
|
|
257
|
-
Classifier: Development Status :: 4 - Beta
|
|
258
|
-
Classifier: Environment :: Console
|
|
259
|
-
Classifier: Environment :: Web Environment
|
|
260
|
-
Classifier: Intended Audience :: Developers
|
|
261
|
-
Classifier: License :: OSI Approved :: BSD License
|
|
262
|
-
Classifier: Operating System :: OS Independent
|
|
263
|
-
Classifier: Programming Language :: Python
|
|
264
|
-
Classifier: Topic :: Internet
|
|
265
|
-
Classifier: Topic :: Software Development :: Libraries
|
PyLD-2.0.3/README.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
README.rst
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|