PyLD 2.0.2__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.
@@ -1,9 +1,20 @@
1
1
  # pyld ChangeLog
2
2
 
3
+ ## 2.0.4 - 2024-02-16
4
+
5
+ ### Fixed
6
+ - Use explicit `None` or `False` for context checks. Fixes an issue while
7
+ framing with an empty context.
8
+
9
+ ## 2.0.3 - 2020-08-06
10
+
11
+ ### Fixed
12
+ - Fix deprecation warnings due to invalid escape sequences.
13
+
3
14
  ## 2.0.2 - 2020-04-20
4
15
 
5
16
  ### Fixed
6
- * Fix inverse context cache indexing to use the uuid field.
17
+ - Fix inverse context cache indexing to use the uuid field.
7
18
 
8
19
  ## 2.0.1 - 2020-04-15
9
20
 
@@ -20,116 +31,116 @@
20
31
  spec and some of the defaults changed.
21
32
 
22
33
  ### Changed
23
- * **BREAKING**: Versions of Python before 3.6 are no longer supported.
24
- * Update conformance docs.
25
- * Add all keywords and update options.
26
- * Default `processingMode` to `json-ld-1.1`.
27
- * Implement logic for marking tests as pending, so that it will fail if a
34
+ - **BREAKING**: Versions of Python before 3.6 are no longer supported.
35
+ - Update conformance docs.
36
+ - Add all keywords and update options.
37
+ - Default `processingMode` to `json-ld-1.1`.
38
+ - Implement logic for marking tests as pending, so that it will fail if a
28
39
  pending test passes.
29
- * Consolidate `documentLoader` option and defaults into a `load_document` method
40
+ - Consolidate `documentLoader` option and defaults into a `load_document` method
30
41
  to also handle JSON (eventually HTML) parsing.
31
- * Add support for `rel=alternate` for non-JSON-LD docs.
32
- * Use `lxml.html` to load HTML and parse in `load_html`.
33
- * For HTML, the API base option can be updated from base element.
34
- * Context processing:
35
- * Support `@propagate` in context processing and propagate option.
36
- * Support for `@import`. (Some issues confusing recursion errors for invalid
42
+ - Add support for `rel=alternate` for non-JSON-LD docs.
43
+ - Use `lxml.html` to load HTML and parse in `load_html`.
44
+ - For HTML, the API base option can be updated from base element.
45
+ - Context processing:
46
+ - Support `@propagate` in context processing and propagate option.
47
+ - Support for `@import`. (Some issues confusing recursion errors for invalid
37
48
  contexts).
38
- * Make `override_protected` and `propagate` optional arguments to
49
+ - Make `override_protected` and `propagate` optional arguments to
39
50
  `_create_term_definition` and `_process_context` instead of using option
40
51
  argument.
41
- * Improve management of previous contexts.
42
- * Imported contexts must resolve to an object.
43
- * Do remote context processing from within `_process_contexts`, as logic is
52
+ - Improve management of previous contexts.
53
+ - Imported contexts must resolve to an object.
54
+ - Do remote context processing from within `_process_contexts`, as logic is
44
55
  too complicated for pre-loading. Removes `_find_context_urls` and
45
56
  `_retrieve_context_urls`.
46
- * Added a `ContextResolver` which can use a shared LRU cache for storing
57
+ - Added a `ContextResolver` which can use a shared LRU cache for storing
47
58
  externally retrieved contexts, and the result of processing them relative
48
59
  to a particular active context.
49
- * Return a `frozendict` from context processing and reduce deepcopies.
50
- * Store inverse context in an LRU cache rather than trying to modify a frozen context.
51
- * Don't set `@base` in initial context and don't resolve a relative IRI
60
+ - Return a `frozendict` from context processing and reduce deepcopies.
61
+ - Store inverse context in an LRU cache rather than trying to modify a frozen context.
62
+ - Don't set `@base` in initial context and don't resolve a relative IRI
52
63
  when setting `@base` in a context, so that the document location can
53
64
  be kept separate from the context itself.
54
- * Use static initial contexts composed of just `mappings` and `processingMode`
65
+ - Use static initial contexts composed of just `mappings` and `processingMode`
55
66
  to enhance preprocessed context cachability.
56
- * Create Term Definition:
57
- * Allow `@type` as a term under certain circumstances.
58
- * Reject and warn on keyword-like terms.
59
- * Support protected term definitions.
60
- * Look for keyword patterns and warn/return.
61
- * Look for terms that are compact IRIs that don't expand to the same thing.
62
- * Basic support for `@json` and `@none` as values of `@type`.
63
- * If `@container` includes `@type`, `@type` must be `@id` or `@vocab`.
64
- * Support `@index` and `@direction`.
65
- * Corner-case checking for `@prefix`.
66
- * Validate scoped contexts even if not used.
67
- * Support relative vocabulary IRIs.
68
- * Fix check that term has the form of an IRI.
69
- * Delay adding mapping to end of `_create_term_definition`.
70
- * If a scoped context is null, wrap it in an array so it doesn't seem to be
67
+ - Create Term Definition:
68
+ - Allow `@type` as a term under certain circumstances.
69
+ - Reject and warn on keyword-like terms.
70
+ - Support protected term definitions.
71
+ - Look for keyword patterns and warn/return.
72
+ - Look for terms that are compact IRIs that don't expand to the same thing.
73
+ - Basic support for `@json` and `@none` as values of `@type`.
74
+ - If `@container` includes `@type`, `@type` must be `@id` or `@vocab`.
75
+ - Support `@index` and `@direction`.
76
+ - Corner-case checking for `@prefix`.
77
+ - Validate scoped contexts even if not used.
78
+ - Support relative vocabulary IRIs.
79
+ - Fix check that term has the form of an IRI.
80
+ - Delay adding mapping to end of `_create_term_definition`.
81
+ - If a scoped context is null, wrap it in an array so it doesn't seem to be
71
82
  undefined.
72
- * IRI Expansion:
73
- * Find keyword patterns.
74
- * Don't treat terms starting with a colon as IRIs.
75
- * Only return a resulting IRI if it is absolute.
76
- * Fix `_is_absolute_iri` to use a reasonable regular expression and some
83
+ - IRI Expansion:
84
+ - Find keyword patterns.
85
+ - Don't treat terms starting with a colon as IRIs.
86
+ - Only return a resulting IRI if it is absolute.
87
+ - Fix `_is_absolute_iri` to use a reasonable regular expression and some
77
88
  other `_expand_iri issues`.
78
- * Fix to detecting relative IRIs.
79
- * Fix special case where relative path should not have a leading '/'
80
- * Pass in document location (through 'base' option) and use when resolving
89
+ - Fix to detecting relative IRIs.
90
+ - Fix special case where relative path should not have a leading '/'
91
+ - Pass in document location (through 'base' option) and use when resolving
81
92
  document-relative IRIs.
82
- * IRI Compaction:
83
- * Pass in document location (through 'base' option) and use when compacting
93
+ - IRI Compaction:
94
+ - Pass in document location (through 'base' option) and use when compacting
84
95
  document-relative IRIs.
85
- * Compaction:
86
- * Compact `@direction`.
87
- * Compact `@type`: `@none`.
88
- * Compact `@included`.
89
- * Honor `@container`: `@set` on `@type`.
90
- * Lists of Lists.
91
- * Improve handling of scoped contexts and propagate.
92
- * Improve map compaction, including indexed properties.
93
- * Catch Absolute IRI confused with prefix.
94
- * Expansion:
95
- * Updates to expansion algorithm.
96
- * `_expand_value` adds `@direction` from term definition.
97
- * JSON Literals.
98
- * Support `@direction` when expanding.
99
- * Support lists of lists.
100
- * Support property indexes.
101
- * Improve graph container expansion.
102
- * Order types when applying scoped contexts.
103
- * Use `type_scoped_ctx` when expanding values of `@type`.
104
- * Use propagate and `override_protected` properly when creating expansion
96
+ - Compaction:
97
+ - Compact `@direction`.
98
+ - Compact `@type`: `@none`.
99
+ - Compact `@included`.
100
+ - Honor `@container`: `@set` on `@type`.
101
+ - Lists of Lists.
102
+ - Improve handling of scoped contexts and propagate.
103
+ - Improve map compaction, including indexed properties.
104
+ - Catch Absolute IRI confused with prefix.
105
+ - Expansion:
106
+ - Updates to expansion algorithm.
107
+ - `_expand_value` adds `@direction` from term definition.
108
+ - JSON Literals.
109
+ - Support `@direction` when expanding.
110
+ - Support lists of lists.
111
+ - Support property indexes.
112
+ - Improve graph container expansion.
113
+ - Order types when applying scoped contexts.
114
+ - Use `type_scoped_ctx` when expanding values of `@type`.
115
+ - Use propagate and `override_protected` properly when creating expansion
105
116
  contexts.
106
- * Flattening:
107
- * Rewrite `_create_node_map` based on 1.1 algorithm.
108
- * Flatten `@included`.
109
- * Flatten lists of lists.
110
- * Update `merge_node_maps` for `@type`.
111
- * Framing:
112
- * Change default for `requireAll` from True to False.
113
- * Change default for 'embed' from '@last' to '@once'.
114
- * Add defaults for `omitGraph` and `pruneBlankNodeIdentifiers`
117
+ - Flattening:
118
+ - Rewrite `_create_node_map` based on 1.1 algorithm.
119
+ - Flatten `@included`.
120
+ - Flatten lists of lists.
121
+ - Update `merge_node_maps` for `@type`.
122
+ - Framing:
123
+ - Change default for `requireAll` from True to False.
124
+ - Change default for 'embed' from '@last' to '@once'.
125
+ - Add defaults for `omitGraph` and `pruneBlankNodeIdentifiers`
115
126
  based on processing mode.
116
- * Change `_remove_preserve` to `_cleanup_preserve` which happens before
127
+ - Change `_remove_preserve` to `_cleanup_preserve` which happens before
117
128
  compaction.
118
- * Add `_cleanup_null` which happens after compaction.
119
- * Update frame matching to 1.1 spec.
120
- * Support `@included`.
121
- * ToRdf:
122
- * Support for I18N direction.
123
- * Support for Lists of Lists.
124
- * Partial support for JSON canonicalization of JSON literals.
125
- * Includes local copy of JCS library, but doesn't load.
126
- * Lists of Lists.
127
- * Text Direction 'i18n-datatype'.
128
- * Testing
129
- * Switched to argparse.
130
- * **BREAKING**: Removed `-d` and `-m` test runner options in favor of just
129
+ - Add `_cleanup_null` which happens after compaction.
130
+ - Update frame matching to 1.1 spec.
131
+ - Support `@included`.
132
+ - ToRdf:
133
+ - Support for I18N direction.
134
+ - Support for Lists of Lists.
135
+ - Partial support for JSON canonicalization of JSON literals.
136
+ - Includes local copy of JCS library, but doesn't load.
137
+ - Lists of Lists.
138
+ - Text Direction 'i18n-datatype'.
139
+ - Testing
140
+ - Switched to argparse.
141
+ - **BREAKING**: Removed `-d` and `-m` test runner options in favor of just
131
142
  listing as arguments.
132
- * If no test manifests or directories are specified, default to sibling
143
+ - If no test manifests or directories are specified, default to sibling
133
144
  directories for json-ld-api, json-ld-framing, and normalization.
134
145
 
135
146
  ## 1.0.5 - 2019-05-09
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://json-ld.github.io/normalization/spec/
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