PyLD 2.0.4__py3-none-any.whl
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.4.dist-info/LICENSE +44 -0
- PyLD-2.0.4.dist-info/METADATA +276 -0
- PyLD-2.0.4.dist-info/RECORD +16 -0
- PyLD-2.0.4.dist-info/WHEEL +5 -0
- PyLD-2.0.4.dist-info/top_level.txt +2 -0
- c14n/Canonicalize.py +474 -0
- c14n/NumberToJson.py +112 -0
- c14n/__init__.py +4 -0
- pyld/__about__.py +9 -0
- pyld/__init__.py +5 -0
- pyld/context_resolver.py +215 -0
- pyld/documentloader/__init__.py +0 -0
- pyld/documentloader/aiohttp.py +119 -0
- pyld/documentloader/requests.py +105 -0
- pyld/jsonld.py +6712 -0
- pyld/resolved_context.py +38 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
You may use the PyLD project under the terms of the New BSD License.
|
|
2
|
+
|
|
3
|
+
The New BSD License is recommended for most projects. It is simple and easy
|
|
4
|
+
to understand and it places almost no restrictions on what you can do with
|
|
5
|
+
the PyLD project.
|
|
6
|
+
|
|
7
|
+
You are free to use this project in commercial projects as long as the
|
|
8
|
+
copyright header is left intact.
|
|
9
|
+
|
|
10
|
+
If you are a commercial entity and use this set of libraries in your
|
|
11
|
+
commercial software then reasonable payment to Digital Bazaar, if you can
|
|
12
|
+
afford it, is not required but is expected and would be appreciated. If this
|
|
13
|
+
library saves you time, then it's saving you money. The cost of developing
|
|
14
|
+
the PyLD software was on the order of several hundred hours and tens of
|
|
15
|
+
thousands of dollars. We are attempting to strike a balance between helping
|
|
16
|
+
the development community while not being taken advantage of by lucrative
|
|
17
|
+
commercial entities for our efforts.
|
|
18
|
+
|
|
19
|
+
-------------------------------------------------------------------------------
|
|
20
|
+
New BSD License (3-clause)
|
|
21
|
+
Copyright (c) 2011, Digital Bazaar, Inc.
|
|
22
|
+
All rights reserved.
|
|
23
|
+
|
|
24
|
+
Redistribution and use in source and binary forms, with or without
|
|
25
|
+
modification, are permitted provided that the following conditions are met:
|
|
26
|
+
* Redistributions of source code must retain the above copyright
|
|
27
|
+
notice, this list of conditions and the following disclaimer.
|
|
28
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
29
|
+
notice, this list of conditions and the following disclaimer in the
|
|
30
|
+
documentation and/or other materials provided with the distribution.
|
|
31
|
+
* Neither the name of Digital Bazaar, Inc. nor the
|
|
32
|
+
names of its contributors may be used to endorse or promote products
|
|
33
|
+
derived from this software without specific prior written permission.
|
|
34
|
+
|
|
35
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
36
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
37
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
38
|
+
DISCLAIMED. IN NO EVENT SHALL DIGITAL BAZAAR BE LIABLE FOR ANY
|
|
39
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
40
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
41
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
42
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
43
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
44
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -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: aiohttp
|
|
23
|
+
Requires-Dist: aiohttp ; extra == 'aiohttp'
|
|
24
|
+
Provides-Extra: cachetools
|
|
25
|
+
Requires-Dist: cachetools ; extra == 'cachetools'
|
|
26
|
+
Provides-Extra: frozendict
|
|
27
|
+
Requires-Dist: frozendict ; extra == 'frozendict'
|
|
28
|
+
Provides-Extra: requests
|
|
29
|
+
Requires-Dist: requests ; extra == 'requests'
|
|
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,16 @@
|
|
|
1
|
+
c14n/Canonicalize.py,sha256=D4m05TfxujRWuVh0P9y2k952UjGzAVH7Usyrgu_ZrP4,17927
|
|
2
|
+
c14n/NumberToJson.py,sha256=Y8-nAP4oyc7MF05UYk0-QSpWYpRKnJbqpiaABEDOspY,3723
|
|
3
|
+
c14n/__init__.py,sha256=-_QhO3RBnQejmkbLa4Gdp7GsPPJNCbLRpYNgKOMZygI,98
|
|
4
|
+
pyld/__about__.py,sha256=XayiYRQz5DERfoZldJDW_zSvzZezGM48xTV1ZIEGab4,212
|
|
5
|
+
pyld/__init__.py,sha256=NCFzUCyAlhAU0VAJmid87lmQ3QMSVfAtxP-NMr_cVf8,160
|
|
6
|
+
pyld/context_resolver.py,sha256=uUZMiv0MotzbZvEWltD0zPZOlhS9wcQIOlEArJCAV9E,8432
|
|
7
|
+
pyld/jsonld.py,sha256=G_hZxw5rXoJ7LcaisNyzofnk-_zWu6lBNBP4XyQ6xeI,273034
|
|
8
|
+
pyld/resolved_context.py,sha256=2w5Bm0-iTbhC9o6OCeLz-XFD3-hxo7M5DgbRFq3gTZc,1135
|
|
9
|
+
pyld/documentloader/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
pyld/documentloader/aiohttp.py,sha256=3p-y78yMbvLCOA-YmpPdHB0LTXM0ujvC-SIW74ibqaM,4997
|
|
11
|
+
pyld/documentloader/requests.py,sha256=an6zmID-s-DKwRUcADWlVpZtWPXmgotGTdEpF8P8vJg,4206
|
|
12
|
+
PyLD-2.0.4.dist-info/LICENSE,sha256=ddh0Cz9BIIICNz1o61EQeVYbpIPcfJpc9crrydDj_Sg,2512
|
|
13
|
+
PyLD-2.0.4.dist-info/METADATA,sha256=eIVmMyGztZXId9oJXwlon0Wa1BVud6xcov4AFji5bVo,9966
|
|
14
|
+
PyLD-2.0.4.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
15
|
+
PyLD-2.0.4.dist-info/top_level.txt,sha256=vbcn-jVt9-QMHeiiIzwP_T8Irnk8VV1_aItu8PV7uyA,10
|
|
16
|
+
PyLD-2.0.4.dist-info/RECORD,,
|