PyLD 3.1.0__tar.gz → 3.3.0__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-3.1.0 → pyld-3.3.0}/CHANGELOG.md +36 -0
- {pyld-3.1.0/lib/PyLD.egg-info → pyld-3.3.0}/PKG-INFO +32 -2
- {pyld-3.1.0 → pyld-3.3.0}/README.md +27 -2
- {pyld-3.1.0 → pyld-3.3.0}/README.txt +27 -2
- {pyld-3.1.0 → pyld-3.3.0/lib/PyLD.egg-info}/PKG-INFO +32 -2
- {pyld-3.1.0 → pyld-3.3.0}/lib/PyLD.egg-info/SOURCES.txt +29 -2
- pyld-3.3.0/lib/PyLD.egg-info/entry_points.txt +2 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/PyLD.egg-info/requires.txt +7 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/__about__.py +1 -1
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/__init__.py +8 -0
- pyld-3.3.0/lib/pyld/cli/__init__.py +5 -0
- pyld-3.3.0/lib/pyld/cli/app.py +82 -0
- pyld-3.3.0/lib/pyld/cli/commands/__init__.py +1 -0
- pyld-3.3.0/lib/pyld/cli/commands/cache.py +14 -0
- pyld-3.3.0/lib/pyld/cli/commands/compact.py +62 -0
- pyld-3.3.0/lib/pyld/cli/commands/expand.py +42 -0
- pyld-3.3.0/lib/pyld/cli/commands/flatten.py +48 -0
- pyld-3.3.0/lib/pyld/cli/commands/frame.py +84 -0
- pyld-3.3.0/lib/pyld/cli/commands/from_rdf.py +46 -0
- pyld-3.3.0/lib/pyld/cli/commands/get.py +18 -0
- pyld-3.3.0/lib/pyld/cli/commands/to_rdf.py +51 -0
- pyld-3.3.0/lib/pyld/cli/entry.py +24 -0
- pyld-3.3.0/lib/pyld/cli/errors.py +28 -0
- pyld-3.3.0/lib/pyld/cli/input.py +132 -0
- pyld-3.3.0/lib/pyld/cli/options.py +62 -0
- pyld-3.3.0/lib/pyld/cli/output.py +25 -0
- pyld-3.3.0/lib/pyld/cli/state.py +17 -0
- pyld-3.3.0/lib/pyld/documentloader/file.py +107 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/documentloader/frozen/__init__.py +12 -9
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/documentloader/requests.py +9 -6
- pyld-3.3.0/lib/pyld/documentloader/requests_sqlite_cache.py +66 -0
- pyld-3.3.0/lib/pyld/documentloader/scheme_directed.py +53 -0
- pyld-3.3.0/lib/pyld/documentloader/type_directed.py +56 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/jsonld.py +211 -195
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/nquads.py +2 -1
- pyld-3.3.0/lib/pyld/options.py +203 -0
- {pyld-3.1.0 → pyld-3.3.0}/setup.py +11 -2
- pyld-3.3.0/tests/test_cli.py +814 -0
- {pyld-3.1.0 → pyld-3.3.0}/tests/test_document_loader.py +26 -0
- pyld-3.3.0/tests/test_file_document_loader.py +223 -0
- {pyld-3.1.0 → pyld-3.3.0}/tests/test_jsonld.py +221 -0
- pyld-3.3.0/tests/test_scheme_directed_document_loader.py +100 -0
- pyld-3.3.0/tests/test_sqlite_cache_requests_document_loader.py +161 -0
- pyld-3.3.0/tests/test_type_directed_document_loader.py +116 -0
- pyld-3.1.0/tests/test_api.py +0 -25
- {pyld-3.1.0 → pyld-3.3.0}/LICENSE +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/MANIFEST.in +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/PyLD.egg-info/dependency_links.txt +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/PyLD.egg-info/top_level.txt +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/c14n/Canonicalize.py +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/c14n/NumberToJson.py +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/c14n/__init__.py +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/canon.py +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/context_resolver.py +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/documentloader/__init__.py +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/documentloader/aiohttp.py +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/documentloader/base.py +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/documentloader/frozen/bundled/activitystreams.jsonld +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/documentloader/frozen/bundled/credentials-v1.jsonld +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/documentloader/frozen/bundled/credentials-v2.jsonld +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/documentloader/frozen/bundled/did-v1.jsonld +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/documentloader/frozen/bundled/security-ed25519-2020-v1.jsonld +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/documentloader/frozen/bundled/security-jws-2020-v1.jsonld +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/documentloader/frozen/bundled/security-v1.jsonld +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/documentloader/frozen/bundled/security-v2.jsonld +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/identifier_issuer.py +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/iri_resolver.py +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/lib/pyld/resolved_context.py +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/pyproject.toml +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/setup.cfg +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/tests/test_frozen_document_loader.py +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/tests/test_iri_resolver.py +0 -0
- {pyld-3.1.0 → pyld-3.3.0}/tests/test_manifests.py +0 -0
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# pyld ChangeLog
|
|
2
2
|
|
|
3
|
+
## 3.3.0 - 2026-09-02
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- `pyld.FileDocumentLoader`: a document loader for local `file:` URLs with optional root confinement.
|
|
7
|
+
- `pyld.SchemeDirectedDocumentLoader`: a document loader that dispatches URL
|
|
8
|
+
strings to per-scheme loaders.
|
|
9
|
+
- `pyld.TypeDirectedDocumentLoader`: a document loader that dispatches by Python
|
|
10
|
+
input type (e.g. `pathlib.Path` vs `str`).
|
|
11
|
+
- `jsonld.flatten()`, `jsonld.frame()`, and `jsonld.to_rdf()` now accept an
|
|
12
|
+
`identifierIssuer` option with an `IdentifierIssuer` instance for blank node
|
|
13
|
+
identifiers. Defaults to `IdentifierIssuer('_:b')`, which preserves the
|
|
14
|
+
previous behaviour.
|
|
15
|
+
- `pyld` command-line tool (`get`, `expand`, `compact`, `flatten`, `frame`,
|
|
16
|
+
`to-rdf`, `from-rdf`, and `cache clear`), installed via
|
|
17
|
+
`pip install "PyLD[cli]"`. Remote contexts are cached in a CLI-specific SQLite
|
|
18
|
+
file (overridable via `--cache-file` / `PYLD_CACHE_FILE`).
|
|
19
|
+
|
|
20
|
+
## 3.2.0 - 2026-08-17
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
- `*Options` TypedDict types and a `Context` type alias in `pyld.options` for JSON-LD API option dicts (typing and documentation).
|
|
24
|
+
- `pyld.SqliteCacheRequestsDocumentLoader`: a SQLite-backed HTTP cache document loader using `requests-cache`.
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
- `SqliteCacheRequestsDocumentLoader` creates the SQLite cache file on first document load, not at construction time.
|
|
28
|
+
|
|
29
|
+
### Fixed
|
|
30
|
+
- If value objects contain array values for `@type` during expansion, an error is now raised. Fixes [expand#ter54](https://w3c.github.io/json-ld-api/tests/expand-manifest.html#ter54) and [toRdf#ter54](https://w3c.github.io/json-ld-api/tests/toRdf-manifest.html#ter54).
|
|
31
|
+
- Inline contexts that try to redefine @context now raise an error. Fixes [expand#ter56](https://w3c.github.io/json-ld-api/tests/expand-manifest.html#ter56) and [toRdf#ter56](https://w3c.github.io/json-ld-api/tests/toRdf-manifest.html#ter56).
|
|
32
|
+
- When using native types, values of `xsd:boolean` and `xsd:integer` are now properly converted. Fixes [fromRdf#t0027](https://w3c.github.io/json-ld-api/tests/fromRdf-manifest.html#t0027).
|
|
33
|
+
- Numbers with 0 as fractional part now parse to an `xsd:integer` instead of `xsd:double`. Fixes [toRdf#ttn02](https://w3c.github.io/json-ld-api/tests/toRdf-manifest.html#ttn02).
|
|
34
|
+
- Zeros are now truncated for numeric values with negative exponent.
|
|
35
|
+
- Blank node prefixes are now also used in IRI expansion.
|
|
36
|
+
- Numbers with no fractions but that are >= 1e21 are now represented as xsd:double in json-ld-1.1 processing mode.
|
|
37
|
+
- In `RequestsDocumentLoader`, constructor-level headers are now removed from `**kwargs` and stored separately, avoiding duplicate `headers=` when calling `session.get`. Per-call `options["headers"]` still takes precedence.
|
|
38
|
+
|
|
3
39
|
## 3.1.0 - 2026-06-19
|
|
4
40
|
|
|
5
41
|
### Fixed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyLD
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.3.0
|
|
4
4
|
Summary: Python implementation of the JSON-LD API
|
|
5
5
|
Home-page: https://github.com/digitalbazaar/pyld
|
|
6
6
|
Author: Digital Bazaar
|
|
@@ -24,10 +24,15 @@ Provides-Extra: requests
|
|
|
24
24
|
Requires-Dist: requests; extra == "requests"
|
|
25
25
|
Provides-Extra: aiohttp
|
|
26
26
|
Requires-Dist: aiohttp; extra == "aiohttp"
|
|
27
|
+
Provides-Extra: requests-cache
|
|
28
|
+
Requires-Dist: requests-cache>=1.3; extra == "requests-cache"
|
|
27
29
|
Provides-Extra: cachetools
|
|
28
30
|
Requires-Dist: cachetools; extra == "cachetools"
|
|
29
31
|
Provides-Extra: frozendict
|
|
30
32
|
Requires-Dist: frozendict; extra == "frozendict"
|
|
33
|
+
Provides-Extra: cli
|
|
34
|
+
Requires-Dist: typer>=0.27; extra == "cli"
|
|
35
|
+
Requires-Dist: requests-cache>=1.3; extra == "cli"
|
|
31
36
|
Dynamic: author
|
|
32
37
|
Dynamic: author-email
|
|
33
38
|
Dynamic: classifier
|
|
@@ -101,12 +106,30 @@ Defining a dependency on pyld will not pull in
|
|
|
101
106
|
[Document Loader](#document-loader) then either depend on the desired external library directly
|
|
102
107
|
or define the requirement as `PyLD[requests]` or `PyLD[aiohttp]`.
|
|
103
108
|
|
|
109
|
+
## Command line
|
|
110
|
+
|
|
111
|
+
Install the optional CLI extra to get a JSON-LD 1.1 `pyld` console script:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
pip install "PyLD[cli]"
|
|
115
|
+
pyld expand document.jsonld
|
|
116
|
+
pyld compact document.jsonld context.jsonld
|
|
117
|
+
pyld frame document.jsonld frame.jsonld
|
|
118
|
+
pyld to-rdf document.jsonld
|
|
119
|
+
pyld from-rdf document.nq
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The CLI also provides `get`, `flatten`, and HTTP cache management. See the
|
|
123
|
+
[CLI documentation](https://digitalbazaar.github.io/pyld/cli/) for all commands,
|
|
124
|
+
options, and stdin support.
|
|
125
|
+
|
|
104
126
|
## Usage
|
|
105
127
|
|
|
106
128
|
Here are some quick examples to get started:
|
|
107
129
|
|
|
108
130
|
```python
|
|
109
131
|
from pyld import jsonld
|
|
132
|
+
from pyld.identifier_issuer import IdentifierIssuer
|
|
110
133
|
import json
|
|
111
134
|
|
|
112
135
|
doc = {
|
|
@@ -168,6 +191,13 @@ normalized = jsonld.normalize(
|
|
|
168
191
|
doc, {'algorithm': 'URDNA2015', 'format': 'application/n-quads'})
|
|
169
192
|
# normalized is a string that is a canonical representation of the document
|
|
170
193
|
# that can be used for hashing, comparison, etc.
|
|
194
|
+
|
|
195
|
+
# convert a document to RDF with a custom blank node issuer
|
|
196
|
+
issuer = IdentifierIssuer('_:doc')
|
|
197
|
+
rdf = jsonld.to_rdf(
|
|
198
|
+
doc,
|
|
199
|
+
{'identifierIssuer': issuer, 'format': 'application/n-quads'})
|
|
200
|
+
# flatten() and frame() accept the same identifierIssuer option
|
|
171
201
|
```
|
|
172
202
|
|
|
173
203
|
## Features & conformance
|
|
@@ -258,7 +288,7 @@ attempt to use a locally cached version of contexts (see
|
|
|
258
288
|
[§ Cache JSON-LD Contexts](https://w3c.github.io/json-ld-bp/#cache-json-ld-contexts)).
|
|
259
289
|
Refresh the bundled copies with `make download-bundled-contexts`.
|
|
260
290
|
|
|
261
|
-
### Customizing the
|
|
291
|
+
### Customizing the ContextResolver
|
|
262
292
|
|
|
263
293
|
You can customize the way contexts are loaded and cached by passing an instance
|
|
264
294
|
of `ContextResolver`. The following example implements a loader with a prefilled
|
|
@@ -59,12 +59,30 @@ Defining a dependency on pyld will not pull in
|
|
|
59
59
|
[Document Loader](#document-loader) then either depend on the desired external library directly
|
|
60
60
|
or define the requirement as `PyLD[requests]` or `PyLD[aiohttp]`.
|
|
61
61
|
|
|
62
|
+
## Command line
|
|
63
|
+
|
|
64
|
+
Install the optional CLI extra to get a JSON-LD 1.1 `pyld` console script:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install "PyLD[cli]"
|
|
68
|
+
pyld expand document.jsonld
|
|
69
|
+
pyld compact document.jsonld context.jsonld
|
|
70
|
+
pyld frame document.jsonld frame.jsonld
|
|
71
|
+
pyld to-rdf document.jsonld
|
|
72
|
+
pyld from-rdf document.nq
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The CLI also provides `get`, `flatten`, and HTTP cache management. See the
|
|
76
|
+
[CLI documentation](https://digitalbazaar.github.io/pyld/cli/) for all commands,
|
|
77
|
+
options, and stdin support.
|
|
78
|
+
|
|
62
79
|
## Usage
|
|
63
80
|
|
|
64
81
|
Here are some quick examples to get started:
|
|
65
82
|
|
|
66
83
|
```python
|
|
67
84
|
from pyld import jsonld
|
|
85
|
+
from pyld.identifier_issuer import IdentifierIssuer
|
|
68
86
|
import json
|
|
69
87
|
|
|
70
88
|
doc = {
|
|
@@ -126,6 +144,13 @@ normalized = jsonld.normalize(
|
|
|
126
144
|
doc, {'algorithm': 'URDNA2015', 'format': 'application/n-quads'})
|
|
127
145
|
# normalized is a string that is a canonical representation of the document
|
|
128
146
|
# that can be used for hashing, comparison, etc.
|
|
147
|
+
|
|
148
|
+
# convert a document to RDF with a custom blank node issuer
|
|
149
|
+
issuer = IdentifierIssuer('_:doc')
|
|
150
|
+
rdf = jsonld.to_rdf(
|
|
151
|
+
doc,
|
|
152
|
+
{'identifierIssuer': issuer, 'format': 'application/n-quads'})
|
|
153
|
+
# flatten() and frame() accept the same identifierIssuer option
|
|
129
154
|
```
|
|
130
155
|
|
|
131
156
|
## Features & conformance
|
|
@@ -216,7 +241,7 @@ attempt to use a locally cached version of contexts (see
|
|
|
216
241
|
[§ Cache JSON-LD Contexts](https://w3c.github.io/json-ld-bp/#cache-json-ld-contexts)).
|
|
217
242
|
Refresh the bundled copies with `make download-bundled-contexts`.
|
|
218
243
|
|
|
219
|
-
### Customizing the
|
|
244
|
+
### Customizing the ContextResolver
|
|
220
245
|
|
|
221
246
|
You can customize the way contexts are loaded and cached by passing an instance
|
|
222
247
|
of `ContextResolver`. The following example implements a loader with a prefilled
|
|
@@ -421,4 +446,4 @@ See [`LICENSE`](./LICENSE) file for details.
|
|
|
421
446
|
The PyLD library is maintained by [Miel Vander
|
|
422
447
|
Sande](https://github.com/mielvds), [Anatoly
|
|
423
448
|
Scherbakov](https://github.com/anatoly-scherbakov) and [Digital
|
|
424
|
-
Bazaar](https://github.com/digitalbazaar) (Original authors of `PyLD`).
|
|
449
|
+
Bazaar](https://github.com/digitalbazaar) (Original authors of `PyLD`).
|
|
@@ -59,12 +59,30 @@ Defining a dependency on pyld will not pull in
|
|
|
59
59
|
[Document Loader](#document-loader) then either depend on the desired external library directly
|
|
60
60
|
or define the requirement as `PyLD[requests]` or `PyLD[aiohttp]`.
|
|
61
61
|
|
|
62
|
+
## Command line
|
|
63
|
+
|
|
64
|
+
Install the optional CLI extra to get a JSON-LD 1.1 `pyld` console script:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install "PyLD[cli]"
|
|
68
|
+
pyld expand document.jsonld
|
|
69
|
+
pyld compact document.jsonld context.jsonld
|
|
70
|
+
pyld frame document.jsonld frame.jsonld
|
|
71
|
+
pyld to-rdf document.jsonld
|
|
72
|
+
pyld from-rdf document.nq
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The CLI also provides `get`, `flatten`, and HTTP cache management. See the
|
|
76
|
+
[CLI documentation](https://digitalbazaar.github.io/pyld/cli/) for all commands,
|
|
77
|
+
options, and stdin support.
|
|
78
|
+
|
|
62
79
|
## Usage
|
|
63
80
|
|
|
64
81
|
Here are some quick examples to get started:
|
|
65
82
|
|
|
66
83
|
```python
|
|
67
84
|
from pyld import jsonld
|
|
85
|
+
from pyld.identifier_issuer import IdentifierIssuer
|
|
68
86
|
import json
|
|
69
87
|
|
|
70
88
|
doc = {
|
|
@@ -126,6 +144,13 @@ normalized = jsonld.normalize(
|
|
|
126
144
|
doc, {'algorithm': 'URDNA2015', 'format': 'application/n-quads'})
|
|
127
145
|
# normalized is a string that is a canonical representation of the document
|
|
128
146
|
# that can be used for hashing, comparison, etc.
|
|
147
|
+
|
|
148
|
+
# convert a document to RDF with a custom blank node issuer
|
|
149
|
+
issuer = IdentifierIssuer('_:doc')
|
|
150
|
+
rdf = jsonld.to_rdf(
|
|
151
|
+
doc,
|
|
152
|
+
{'identifierIssuer': issuer, 'format': 'application/n-quads'})
|
|
153
|
+
# flatten() and frame() accept the same identifierIssuer option
|
|
129
154
|
```
|
|
130
155
|
|
|
131
156
|
## Features & conformance
|
|
@@ -216,7 +241,7 @@ attempt to use a locally cached version of contexts (see
|
|
|
216
241
|
[§ Cache JSON-LD Contexts](https://w3c.github.io/json-ld-bp/#cache-json-ld-contexts)).
|
|
217
242
|
Refresh the bundled copies with `make download-bundled-contexts`.
|
|
218
243
|
|
|
219
|
-
### Customizing the
|
|
244
|
+
### Customizing the ContextResolver
|
|
220
245
|
|
|
221
246
|
You can customize the way contexts are loaded and cached by passing an instance
|
|
222
247
|
of `ContextResolver`. The following example implements a loader with a prefilled
|
|
@@ -421,4 +446,4 @@ See [`LICENSE`](./LICENSE) file for details.
|
|
|
421
446
|
The PyLD library is maintained by [Miel Vander
|
|
422
447
|
Sande](https://github.com/mielvds), [Anatoly
|
|
423
448
|
Scherbakov](https://github.com/anatoly-scherbakov) and [Digital
|
|
424
|
-
Bazaar](https://github.com/digitalbazaar) (Original authors of `PyLD`).
|
|
449
|
+
Bazaar](https://github.com/digitalbazaar) (Original authors of `PyLD`).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyLD
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.3.0
|
|
4
4
|
Summary: Python implementation of the JSON-LD API
|
|
5
5
|
Home-page: https://github.com/digitalbazaar/pyld
|
|
6
6
|
Author: Digital Bazaar
|
|
@@ -24,10 +24,15 @@ Provides-Extra: requests
|
|
|
24
24
|
Requires-Dist: requests; extra == "requests"
|
|
25
25
|
Provides-Extra: aiohttp
|
|
26
26
|
Requires-Dist: aiohttp; extra == "aiohttp"
|
|
27
|
+
Provides-Extra: requests-cache
|
|
28
|
+
Requires-Dist: requests-cache>=1.3; extra == "requests-cache"
|
|
27
29
|
Provides-Extra: cachetools
|
|
28
30
|
Requires-Dist: cachetools; extra == "cachetools"
|
|
29
31
|
Provides-Extra: frozendict
|
|
30
32
|
Requires-Dist: frozendict; extra == "frozendict"
|
|
33
|
+
Provides-Extra: cli
|
|
34
|
+
Requires-Dist: typer>=0.27; extra == "cli"
|
|
35
|
+
Requires-Dist: requests-cache>=1.3; extra == "cli"
|
|
31
36
|
Dynamic: author
|
|
32
37
|
Dynamic: author-email
|
|
33
38
|
Dynamic: classifier
|
|
@@ -101,12 +106,30 @@ Defining a dependency on pyld will not pull in
|
|
|
101
106
|
[Document Loader](#document-loader) then either depend on the desired external library directly
|
|
102
107
|
or define the requirement as `PyLD[requests]` or `PyLD[aiohttp]`.
|
|
103
108
|
|
|
109
|
+
## Command line
|
|
110
|
+
|
|
111
|
+
Install the optional CLI extra to get a JSON-LD 1.1 `pyld` console script:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
pip install "PyLD[cli]"
|
|
115
|
+
pyld expand document.jsonld
|
|
116
|
+
pyld compact document.jsonld context.jsonld
|
|
117
|
+
pyld frame document.jsonld frame.jsonld
|
|
118
|
+
pyld to-rdf document.jsonld
|
|
119
|
+
pyld from-rdf document.nq
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The CLI also provides `get`, `flatten`, and HTTP cache management. See the
|
|
123
|
+
[CLI documentation](https://digitalbazaar.github.io/pyld/cli/) for all commands,
|
|
124
|
+
options, and stdin support.
|
|
125
|
+
|
|
104
126
|
## Usage
|
|
105
127
|
|
|
106
128
|
Here are some quick examples to get started:
|
|
107
129
|
|
|
108
130
|
```python
|
|
109
131
|
from pyld import jsonld
|
|
132
|
+
from pyld.identifier_issuer import IdentifierIssuer
|
|
110
133
|
import json
|
|
111
134
|
|
|
112
135
|
doc = {
|
|
@@ -168,6 +191,13 @@ normalized = jsonld.normalize(
|
|
|
168
191
|
doc, {'algorithm': 'URDNA2015', 'format': 'application/n-quads'})
|
|
169
192
|
# normalized is a string that is a canonical representation of the document
|
|
170
193
|
# that can be used for hashing, comparison, etc.
|
|
194
|
+
|
|
195
|
+
# convert a document to RDF with a custom blank node issuer
|
|
196
|
+
issuer = IdentifierIssuer('_:doc')
|
|
197
|
+
rdf = jsonld.to_rdf(
|
|
198
|
+
doc,
|
|
199
|
+
{'identifierIssuer': issuer, 'format': 'application/n-quads'})
|
|
200
|
+
# flatten() and frame() accept the same identifierIssuer option
|
|
171
201
|
```
|
|
172
202
|
|
|
173
203
|
## Features & conformance
|
|
@@ -258,7 +288,7 @@ attempt to use a locally cached version of contexts (see
|
|
|
258
288
|
[§ Cache JSON-LD Contexts](https://w3c.github.io/json-ld-bp/#cache-json-ld-contexts)).
|
|
259
289
|
Refresh the bundled copies with `make download-bundled-contexts`.
|
|
260
290
|
|
|
261
|
-
### Customizing the
|
|
291
|
+
### Customizing the ContextResolver
|
|
262
292
|
|
|
263
293
|
You can customize the way contexts are loaded and cached by passing an instance
|
|
264
294
|
of `ContextResolver`. The following example implements a loader with a prefilled
|
|
@@ -8,6 +8,7 @@ setup.py
|
|
|
8
8
|
lib/PyLD.egg-info/PKG-INFO
|
|
9
9
|
lib/PyLD.egg-info/SOURCES.txt
|
|
10
10
|
lib/PyLD.egg-info/dependency_links.txt
|
|
11
|
+
lib/PyLD.egg-info/entry_points.txt
|
|
11
12
|
lib/PyLD.egg-info/requires.txt
|
|
12
13
|
lib/PyLD.egg-info/top_level.txt
|
|
13
14
|
lib/c14n/Canonicalize.py
|
|
@@ -21,11 +22,33 @@ lib/pyld/identifier_issuer.py
|
|
|
21
22
|
lib/pyld/iri_resolver.py
|
|
22
23
|
lib/pyld/jsonld.py
|
|
23
24
|
lib/pyld/nquads.py
|
|
25
|
+
lib/pyld/options.py
|
|
24
26
|
lib/pyld/resolved_context.py
|
|
27
|
+
lib/pyld/cli/__init__.py
|
|
28
|
+
lib/pyld/cli/app.py
|
|
29
|
+
lib/pyld/cli/entry.py
|
|
30
|
+
lib/pyld/cli/errors.py
|
|
31
|
+
lib/pyld/cli/input.py
|
|
32
|
+
lib/pyld/cli/options.py
|
|
33
|
+
lib/pyld/cli/output.py
|
|
34
|
+
lib/pyld/cli/state.py
|
|
35
|
+
lib/pyld/cli/commands/__init__.py
|
|
36
|
+
lib/pyld/cli/commands/cache.py
|
|
37
|
+
lib/pyld/cli/commands/compact.py
|
|
38
|
+
lib/pyld/cli/commands/expand.py
|
|
39
|
+
lib/pyld/cli/commands/flatten.py
|
|
40
|
+
lib/pyld/cli/commands/frame.py
|
|
41
|
+
lib/pyld/cli/commands/from_rdf.py
|
|
42
|
+
lib/pyld/cli/commands/get.py
|
|
43
|
+
lib/pyld/cli/commands/to_rdf.py
|
|
25
44
|
lib/pyld/documentloader/__init__.py
|
|
26
45
|
lib/pyld/documentloader/aiohttp.py
|
|
27
46
|
lib/pyld/documentloader/base.py
|
|
47
|
+
lib/pyld/documentloader/file.py
|
|
28
48
|
lib/pyld/documentloader/requests.py
|
|
49
|
+
lib/pyld/documentloader/requests_sqlite_cache.py
|
|
50
|
+
lib/pyld/documentloader/scheme_directed.py
|
|
51
|
+
lib/pyld/documentloader/type_directed.py
|
|
29
52
|
lib/pyld/documentloader/frozen/__init__.py
|
|
30
53
|
lib/pyld/documentloader/frozen/bundled/activitystreams.jsonld
|
|
31
54
|
lib/pyld/documentloader/frozen/bundled/credentials-v1.jsonld
|
|
@@ -35,9 +58,13 @@ lib/pyld/documentloader/frozen/bundled/security-ed25519-2020-v1.jsonld
|
|
|
35
58
|
lib/pyld/documentloader/frozen/bundled/security-jws-2020-v1.jsonld
|
|
36
59
|
lib/pyld/documentloader/frozen/bundled/security-v1.jsonld
|
|
37
60
|
lib/pyld/documentloader/frozen/bundled/security-v2.jsonld
|
|
38
|
-
tests/
|
|
61
|
+
tests/test_cli.py
|
|
39
62
|
tests/test_document_loader.py
|
|
63
|
+
tests/test_file_document_loader.py
|
|
40
64
|
tests/test_frozen_document_loader.py
|
|
41
65
|
tests/test_iri_resolver.py
|
|
42
66
|
tests/test_jsonld.py
|
|
43
|
-
tests/test_manifests.py
|
|
67
|
+
tests/test_manifests.py
|
|
68
|
+
tests/test_scheme_directed_document_loader.py
|
|
69
|
+
tests/test_sqlite_cache_requests_document_loader.py
|
|
70
|
+
tests/test_type_directed_document_loader.py
|
|
@@ -4,16 +4,24 @@ from . import jsonld
|
|
|
4
4
|
from .context_resolver import ContextResolver
|
|
5
5
|
from .documentloader.aiohttp import AioHttpDocumentLoader
|
|
6
6
|
from .documentloader.base import DocumentLoader, RemoteDocument
|
|
7
|
+
from .documentloader.file import FileDocumentLoader
|
|
7
8
|
from .documentloader.frozen import BUNDLED_CONTEXTS, FrozenDocumentLoader
|
|
8
9
|
from .documentloader.requests import RequestsDocumentLoader
|
|
10
|
+
from .documentloader.requests_sqlite_cache import SqliteCacheRequestsDocumentLoader
|
|
11
|
+
from .documentloader.scheme_directed import SchemeDirectedDocumentLoader
|
|
12
|
+
from .documentloader.type_directed import TypeDirectedDocumentLoader
|
|
9
13
|
|
|
10
14
|
__all__ = [
|
|
11
15
|
'AioHttpDocumentLoader',
|
|
12
16
|
'BUNDLED_CONTEXTS',
|
|
17
|
+
'SchemeDirectedDocumentLoader',
|
|
18
|
+
'TypeDirectedDocumentLoader',
|
|
13
19
|
'ContextResolver',
|
|
14
20
|
'DocumentLoader',
|
|
21
|
+
'FileDocumentLoader',
|
|
15
22
|
'FrozenDocumentLoader',
|
|
16
23
|
'RequestsDocumentLoader',
|
|
17
24
|
'RemoteDocument',
|
|
25
|
+
'SqliteCacheRequestsDocumentLoader',
|
|
18
26
|
'jsonld',
|
|
19
27
|
]
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""Typer application assembly for the PyLD CLI."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Annotated
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
import typer
|
|
11
|
+
except ImportError as cause: # pragma: no cover
|
|
12
|
+
raise ImportError(
|
|
13
|
+
'The pyld command-line interface requires Typer. '
|
|
14
|
+
'Install it with: pip install "PyLD[cli]"'
|
|
15
|
+
) from cause
|
|
16
|
+
|
|
17
|
+
from typer import Option
|
|
18
|
+
|
|
19
|
+
from pyld.cli import state as cli_state
|
|
20
|
+
from pyld.cli.commands.cache import cache_clear
|
|
21
|
+
from pyld.cli.commands.compact import compact_command
|
|
22
|
+
from pyld.cli.commands.expand import expand_command
|
|
23
|
+
from pyld.cli.commands.flatten import flatten_command
|
|
24
|
+
from pyld.cli.commands.frame import frame_command
|
|
25
|
+
from pyld.cli.commands.from_rdf import from_rdf_command
|
|
26
|
+
from pyld.cli.commands.get import get_command
|
|
27
|
+
from pyld.cli.commands.to_rdf import to_rdf_command
|
|
28
|
+
from pyld.cli.errors import print_error
|
|
29
|
+
from pyld.cli.state import State
|
|
30
|
+
|
|
31
|
+
pyld = typer.Typer(
|
|
32
|
+
help='Command-line tool for JSON-LD transformations.',
|
|
33
|
+
no_args_is_help=True,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@pyld.callback()
|
|
38
|
+
def root(
|
|
39
|
+
ctx: typer.Context,
|
|
40
|
+
traceback: Annotated[
|
|
41
|
+
bool,
|
|
42
|
+
Option('--traceback', help='Show the Python traceback on errors.'),
|
|
43
|
+
] = False,
|
|
44
|
+
cache_file: Annotated[
|
|
45
|
+
Path | None,
|
|
46
|
+
Option(
|
|
47
|
+
'--cache-file',
|
|
48
|
+
envvar='PYLD_CACHE_FILE',
|
|
49
|
+
help='SQLite file for the CLI HTTP cache.',
|
|
50
|
+
),
|
|
51
|
+
] = None,
|
|
52
|
+
) -> None:
|
|
53
|
+
state = State(traceback=traceback, cache_file=cache_file)
|
|
54
|
+
ctx.obj = state
|
|
55
|
+
# ``main`` reads this after Click has torn down the context.
|
|
56
|
+
cli_state.current = state
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
pyld.command('get')(get_command)
|
|
60
|
+
pyld.command('expand')(expand_command)
|
|
61
|
+
pyld.command('compact')(compact_command)
|
|
62
|
+
pyld.command('flatten')(flatten_command)
|
|
63
|
+
pyld.command('frame')(frame_command)
|
|
64
|
+
pyld.command('to-rdf')(to_rdf_command)
|
|
65
|
+
pyld.command('from-rdf')(from_rdf_command)
|
|
66
|
+
|
|
67
|
+
cache_app = typer.Typer(help='Cache management.', no_args_is_help=True)
|
|
68
|
+
cache_app.command('clear')(cache_clear)
|
|
69
|
+
pyld.add_typer(cache_app, name='cache')
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def main(args: list[str] | None = None) -> None:
|
|
73
|
+
"""Entry point for the ``pyld`` console script."""
|
|
74
|
+
try:
|
|
75
|
+
pyld(args=args, prog_name='pyld')
|
|
76
|
+
except (SystemExit, KeyboardInterrupt):
|
|
77
|
+
raise
|
|
78
|
+
except Exception as err:
|
|
79
|
+
if cli_state.current.traceback:
|
|
80
|
+
raise
|
|
81
|
+
print_error(err, sys.argv[1:] if args is None else args)
|
|
82
|
+
raise SystemExit(1) from None
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Command implementations for the PyLD CLI."""
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""The ``pyld cache`` commands."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pyld.cli.input import configured_cache_file
|
|
6
|
+
from pyld.cli.output import console
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def cache_clear() -> None:
|
|
10
|
+
"""Clear the CLI HTTP cache."""
|
|
11
|
+
path = configured_cache_file()
|
|
12
|
+
if path.exists():
|
|
13
|
+
path.unlink()
|
|
14
|
+
console.print('Cache cleared.', style='green')
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""The ``pyld compact`` command."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Annotated
|
|
6
|
+
|
|
7
|
+
from typer import Option
|
|
8
|
+
|
|
9
|
+
from pyld import jsonld
|
|
10
|
+
from pyld.cli.input import (
|
|
11
|
+
ContextArgument,
|
|
12
|
+
Input,
|
|
13
|
+
document_value,
|
|
14
|
+
ensure_single_stdin,
|
|
15
|
+
)
|
|
16
|
+
from pyld.cli.options import (
|
|
17
|
+
Base,
|
|
18
|
+
ExpandContext,
|
|
19
|
+
ExtractAllScripts,
|
|
20
|
+
optional_options,
|
|
21
|
+
processing_options,
|
|
22
|
+
)
|
|
23
|
+
from pyld.cli.output import print_json
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def compact_command(
|
|
27
|
+
input_: Input,
|
|
28
|
+
context: ContextArgument,
|
|
29
|
+
expand_context: ExpandContext = None,
|
|
30
|
+
base: Base = None,
|
|
31
|
+
extract_all_scripts: ExtractAllScripts = None,
|
|
32
|
+
compact_arrays: Annotated[
|
|
33
|
+
bool | None,
|
|
34
|
+
Option(
|
|
35
|
+
'--compact-arrays/--no-compact-arrays',
|
|
36
|
+
help='Compact single-value arrays when appropriate.',
|
|
37
|
+
),
|
|
38
|
+
] = None,
|
|
39
|
+
graph: Annotated[
|
|
40
|
+
bool | None,
|
|
41
|
+
Option(
|
|
42
|
+
'--graph/--no-graph',
|
|
43
|
+
help='Always emit a top-level graph.',
|
|
44
|
+
),
|
|
45
|
+
] = None,
|
|
46
|
+
) -> None:
|
|
47
|
+
"""Compact a JSON-LD document using a context."""
|
|
48
|
+
ensure_single_stdin(input_, context, expand_context)
|
|
49
|
+
options = {
|
|
50
|
+
**processing_options(
|
|
51
|
+
base=base,
|
|
52
|
+
extract_all_scripts=extract_all_scripts,
|
|
53
|
+
expand_context=expand_context,
|
|
54
|
+
),
|
|
55
|
+
**optional_options(compactArrays=compact_arrays, graph=graph),
|
|
56
|
+
}
|
|
57
|
+
result = jsonld.compact(
|
|
58
|
+
document_value(input_),
|
|
59
|
+
document_value(context),
|
|
60
|
+
options=options,
|
|
61
|
+
)
|
|
62
|
+
print_json(result)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""The ``pyld expand`` command."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Annotated
|
|
6
|
+
|
|
7
|
+
from typer import Option
|
|
8
|
+
|
|
9
|
+
from pyld import jsonld
|
|
10
|
+
from pyld.cli.input import (
|
|
11
|
+
Input,
|
|
12
|
+
document_value,
|
|
13
|
+
ensure_single_stdin,
|
|
14
|
+
)
|
|
15
|
+
from pyld.cli.options import Base, ExtractAllScripts, MaybeStr, processing_options
|
|
16
|
+
from pyld.cli.output import print_json
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def expand_command(
|
|
20
|
+
input_: Input,
|
|
21
|
+
context: Annotated[
|
|
22
|
+
MaybeStr,
|
|
23
|
+
Option(
|
|
24
|
+
'--context',
|
|
25
|
+
'-c',
|
|
26
|
+
help='Context path or URL. Pass - to read JSON from standard input.',
|
|
27
|
+
),
|
|
28
|
+
] = None,
|
|
29
|
+
base: Base = None,
|
|
30
|
+
extract_all_scripts: ExtractAllScripts = None,
|
|
31
|
+
) -> None:
|
|
32
|
+
"""Expand a JSON-LD document."""
|
|
33
|
+
ensure_single_stdin(input_, context)
|
|
34
|
+
options = processing_options(
|
|
35
|
+
base=base,
|
|
36
|
+
extract_all_scripts=extract_all_scripts,
|
|
37
|
+
)
|
|
38
|
+
if context is not None:
|
|
39
|
+
options = {**options, 'expandContext': document_value(context)}
|
|
40
|
+
|
|
41
|
+
result = jsonld.expand(document_value(input_), options=options)
|
|
42
|
+
print_json(result)
|