PyLD 3.2.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.
Files changed (72) hide show
  1. {pyld-3.2.0 → pyld-3.3.0}/CHANGELOG.md +20 -0
  2. {pyld-3.2.0/lib/PyLD.egg-info → pyld-3.3.0}/PKG-INFO +29 -1
  3. {pyld-3.2.0 → pyld-3.3.0}/README.md +26 -1
  4. {pyld-3.2.0 → pyld-3.3.0}/README.txt +26 -1
  5. {pyld-3.2.0 → pyld-3.3.0/lib/PyLD.egg-info}/PKG-INFO +29 -1
  6. {pyld-3.2.0 → pyld-3.3.0}/lib/PyLD.egg-info/SOURCES.txt +26 -1
  7. pyld-3.3.0/lib/PyLD.egg-info/entry_points.txt +2 -0
  8. {pyld-3.2.0 → pyld-3.3.0}/lib/PyLD.egg-info/requires.txt +4 -0
  9. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/__about__.py +1 -1
  10. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/__init__.py +6 -0
  11. pyld-3.3.0/lib/pyld/cli/__init__.py +5 -0
  12. pyld-3.3.0/lib/pyld/cli/app.py +82 -0
  13. pyld-3.3.0/lib/pyld/cli/commands/__init__.py +1 -0
  14. pyld-3.3.0/lib/pyld/cli/commands/cache.py +14 -0
  15. pyld-3.3.0/lib/pyld/cli/commands/compact.py +62 -0
  16. pyld-3.3.0/lib/pyld/cli/commands/expand.py +42 -0
  17. pyld-3.3.0/lib/pyld/cli/commands/flatten.py +48 -0
  18. pyld-3.3.0/lib/pyld/cli/commands/frame.py +84 -0
  19. pyld-3.3.0/lib/pyld/cli/commands/from_rdf.py +46 -0
  20. pyld-3.3.0/lib/pyld/cli/commands/get.py +18 -0
  21. pyld-3.3.0/lib/pyld/cli/commands/to_rdf.py +51 -0
  22. pyld-3.3.0/lib/pyld/cli/entry.py +24 -0
  23. pyld-3.3.0/lib/pyld/cli/errors.py +28 -0
  24. pyld-3.3.0/lib/pyld/cli/input.py +132 -0
  25. pyld-3.3.0/lib/pyld/cli/options.py +62 -0
  26. pyld-3.3.0/lib/pyld/cli/output.py +25 -0
  27. pyld-3.3.0/lib/pyld/cli/state.py +17 -0
  28. pyld-3.3.0/lib/pyld/documentloader/file.py +107 -0
  29. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/documentloader/frozen/__init__.py +12 -9
  30. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/documentloader/requests_sqlite_cache.py +16 -5
  31. pyld-3.3.0/lib/pyld/documentloader/scheme_directed.py +53 -0
  32. pyld-3.3.0/lib/pyld/documentloader/type_directed.py +56 -0
  33. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/jsonld.py +20 -7
  34. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/options.py +15 -5
  35. {pyld-3.2.0 → pyld-3.3.0}/setup.py +10 -2
  36. pyld-3.3.0/tests/test_cli.py +814 -0
  37. pyld-3.3.0/tests/test_file_document_loader.py +223 -0
  38. {pyld-3.2.0 → pyld-3.3.0}/tests/test_jsonld.py +71 -0
  39. pyld-3.3.0/tests/test_scheme_directed_document_loader.py +100 -0
  40. {pyld-3.2.0 → pyld-3.3.0}/tests/test_sqlite_cache_requests_document_loader.py +49 -13
  41. pyld-3.3.0/tests/test_type_directed_document_loader.py +116 -0
  42. {pyld-3.2.0 → pyld-3.3.0}/LICENSE +0 -0
  43. {pyld-3.2.0 → pyld-3.3.0}/MANIFEST.in +0 -0
  44. {pyld-3.2.0 → pyld-3.3.0}/lib/PyLD.egg-info/dependency_links.txt +0 -0
  45. {pyld-3.2.0 → pyld-3.3.0}/lib/PyLD.egg-info/top_level.txt +0 -0
  46. {pyld-3.2.0 → pyld-3.3.0}/lib/c14n/Canonicalize.py +0 -0
  47. {pyld-3.2.0 → pyld-3.3.0}/lib/c14n/NumberToJson.py +0 -0
  48. {pyld-3.2.0 → pyld-3.3.0}/lib/c14n/__init__.py +0 -0
  49. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/canon.py +0 -0
  50. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/context_resolver.py +0 -0
  51. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/documentloader/__init__.py +0 -0
  52. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/documentloader/aiohttp.py +0 -0
  53. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/documentloader/base.py +0 -0
  54. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/documentloader/frozen/bundled/activitystreams.jsonld +0 -0
  55. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/documentloader/frozen/bundled/credentials-v1.jsonld +0 -0
  56. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/documentloader/frozen/bundled/credentials-v2.jsonld +0 -0
  57. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/documentloader/frozen/bundled/did-v1.jsonld +0 -0
  58. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/documentloader/frozen/bundled/security-ed25519-2020-v1.jsonld +0 -0
  59. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/documentloader/frozen/bundled/security-jws-2020-v1.jsonld +0 -0
  60. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/documentloader/frozen/bundled/security-v1.jsonld +0 -0
  61. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/documentloader/frozen/bundled/security-v2.jsonld +0 -0
  62. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/documentloader/requests.py +0 -0
  63. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/identifier_issuer.py +0 -0
  64. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/iri_resolver.py +0 -0
  65. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/nquads.py +0 -0
  66. {pyld-3.2.0 → pyld-3.3.0}/lib/pyld/resolved_context.py +0 -0
  67. {pyld-3.2.0 → pyld-3.3.0}/pyproject.toml +0 -0
  68. {pyld-3.2.0 → pyld-3.3.0}/setup.cfg +0 -0
  69. {pyld-3.2.0 → pyld-3.3.0}/tests/test_document_loader.py +0 -0
  70. {pyld-3.2.0 → pyld-3.3.0}/tests/test_frozen_document_loader.py +0 -0
  71. {pyld-3.2.0 → pyld-3.3.0}/tests/test_iri_resolver.py +0 -0
  72. {pyld-3.2.0 → pyld-3.3.0}/tests/test_manifests.py +0 -0
@@ -1,11 +1,31 @@
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
+
3
20
  ## 3.2.0 - 2026-08-17
4
21
 
5
22
  ### Added
6
23
  - `*Options` TypedDict types and a `Context` type alias in `pyld.options` for JSON-LD API option dicts (typing and documentation).
7
24
  - `pyld.SqliteCacheRequestsDocumentLoader`: a SQLite-backed HTTP cache document loader using `requests-cache`.
8
25
 
26
+ ### Changed
27
+ - `SqliteCacheRequestsDocumentLoader` creates the SQLite cache file on first document load, not at construction time.
28
+
9
29
  ### Fixed
10
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).
11
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).
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyLD
3
- Version: 3.2.0
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
@@ -30,6 +30,9 @@ Provides-Extra: cachetools
30
30
  Requires-Dist: cachetools; extra == "cachetools"
31
31
  Provides-Extra: frozendict
32
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"
33
36
  Dynamic: author
34
37
  Dynamic: author-email
35
38
  Dynamic: classifier
@@ -103,12 +106,30 @@ Defining a dependency on pyld will not pull in
103
106
  [Document Loader](#document-loader) then either depend on the desired external library directly
104
107
  or define the requirement as `PyLD[requests]` or `PyLD[aiohttp]`.
105
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
+
106
126
  ## Usage
107
127
 
108
128
  Here are some quick examples to get started:
109
129
 
110
130
  ```python
111
131
  from pyld import jsonld
132
+ from pyld.identifier_issuer import IdentifierIssuer
112
133
  import json
113
134
 
114
135
  doc = {
@@ -170,6 +191,13 @@ normalized = jsonld.normalize(
170
191
  doc, {'algorithm': 'URDNA2015', 'format': 'application/n-quads'})
171
192
  # normalized is a string that is a canonical representation of the document
172
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
173
201
  ```
174
202
 
175
203
  ## Features & conformance
@@ -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
@@ -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
@@ -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.2.0
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
@@ -30,6 +30,9 @@ Provides-Extra: cachetools
30
30
  Requires-Dist: cachetools; extra == "cachetools"
31
31
  Provides-Extra: frozendict
32
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"
33
36
  Dynamic: author
34
37
  Dynamic: author-email
35
38
  Dynamic: classifier
@@ -103,12 +106,30 @@ Defining a dependency on pyld will not pull in
103
106
  [Document Loader](#document-loader) then either depend on the desired external library directly
104
107
  or define the requirement as `PyLD[requests]` or `PyLD[aiohttp]`.
105
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
+
106
126
  ## Usage
107
127
 
108
128
  Here are some quick examples to get started:
109
129
 
110
130
  ```python
111
131
  from pyld import jsonld
132
+ from pyld.identifier_issuer import IdentifierIssuer
112
133
  import json
113
134
 
114
135
  doc = {
@@ -170,6 +191,13 @@ normalized = jsonld.normalize(
170
191
  doc, {'algorithm': 'URDNA2015', 'format': 'application/n-quads'})
171
192
  # normalized is a string that is a canonical representation of the document
172
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
173
201
  ```
174
202
 
175
203
  ## Features & conformance
@@ -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
@@ -23,11 +24,31 @@ lib/pyld/jsonld.py
23
24
  lib/pyld/nquads.py
24
25
  lib/pyld/options.py
25
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
26
44
  lib/pyld/documentloader/__init__.py
27
45
  lib/pyld/documentloader/aiohttp.py
28
46
  lib/pyld/documentloader/base.py
47
+ lib/pyld/documentloader/file.py
29
48
  lib/pyld/documentloader/requests.py
30
49
  lib/pyld/documentloader/requests_sqlite_cache.py
50
+ lib/pyld/documentloader/scheme_directed.py
51
+ lib/pyld/documentloader/type_directed.py
31
52
  lib/pyld/documentloader/frozen/__init__.py
32
53
  lib/pyld/documentloader/frozen/bundled/activitystreams.jsonld
33
54
  lib/pyld/documentloader/frozen/bundled/credentials-v1.jsonld
@@ -37,9 +58,13 @@ lib/pyld/documentloader/frozen/bundled/security-ed25519-2020-v1.jsonld
37
58
  lib/pyld/documentloader/frozen/bundled/security-jws-2020-v1.jsonld
38
59
  lib/pyld/documentloader/frozen/bundled/security-v1.jsonld
39
60
  lib/pyld/documentloader/frozen/bundled/security-v2.jsonld
61
+ tests/test_cli.py
40
62
  tests/test_document_loader.py
63
+ tests/test_file_document_loader.py
41
64
  tests/test_frozen_document_loader.py
42
65
  tests/test_iri_resolver.py
43
66
  tests/test_jsonld.py
44
67
  tests/test_manifests.py
45
- tests/test_sqlite_cache_requests_document_loader.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
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pyld = pyld.cli.entry:main
@@ -8,6 +8,10 @@ aiohttp
8
8
  [cachetools]
9
9
  cachetools
10
10
 
11
+ [cli]
12
+ typer>=0.27
13
+ requests-cache>=1.3
14
+
11
15
  [frozendict]
12
16
  frozendict
13
17
 
@@ -4,4 +4,4 @@ __all__ = ['__copyright__', '__license__', '__version__']
4
4
 
5
5
  __copyright__ = 'Copyright (c) 2011-2024 Digital Bazaar, Inc.'
6
6
  __license__ = 'BSD 3-Clause "New" or "Revised" License'
7
- __version__ = '3.2.0'
7
+ __version__ = '3.3.0'
@@ -4,15 +4,21 @@ 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
9
10
  from .documentloader.requests_sqlite_cache import SqliteCacheRequestsDocumentLoader
11
+ from .documentloader.scheme_directed import SchemeDirectedDocumentLoader
12
+ from .documentloader.type_directed import TypeDirectedDocumentLoader
10
13
 
11
14
  __all__ = [
12
15
  'AioHttpDocumentLoader',
13
16
  'BUNDLED_CONTEXTS',
17
+ 'SchemeDirectedDocumentLoader',
18
+ 'TypeDirectedDocumentLoader',
14
19
  'ContextResolver',
15
20
  'DocumentLoader',
21
+ 'FileDocumentLoader',
16
22
  'FrozenDocumentLoader',
17
23
  'RequestsDocumentLoader',
18
24
  'RemoteDocument',
@@ -0,0 +1,5 @@
1
+ """Command-line interface for PyLD."""
2
+
3
+ from pyld.cli.app import main, pyld
4
+
5
+ __all__ = ['main', 'pyld']
@@ -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)
@@ -0,0 +1,48 @@
1
+ """The ``pyld flatten`` 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 (
16
+ Base,
17
+ ExpandContext,
18
+ ExtractAllScripts,
19
+ MaybeStr,
20
+ processing_options,
21
+ )
22
+ from pyld.cli.output import print_json
23
+
24
+
25
+ def flatten_command(
26
+ input_: Input,
27
+ context: Annotated[
28
+ MaybeStr,
29
+ Option(
30
+ '--context',
31
+ '-c',
32
+ help='Output context path or URL. Pass - to read JSON from standard input.',
33
+ ),
34
+ ] = None,
35
+ expand_context: ExpandContext = None,
36
+ base: Base = None,
37
+ extract_all_scripts: ExtractAllScripts = None,
38
+ ) -> None:
39
+ """Flatten a JSON-LD document."""
40
+ ensure_single_stdin(input_, context, expand_context)
41
+ options = processing_options(
42
+ base=base,
43
+ extract_all_scripts=extract_all_scripts,
44
+ expand_context=expand_context,
45
+ )
46
+ output_context = document_value(context) if context is not None else None
47
+ result = jsonld.flatten(document_value(input_), output_context, options=options)
48
+ print_json(result)