Skip to content

Commit 1179227

Browse files
committed
Add legacyMode to options and document its use.
1 parent a2f2392 commit 1179227

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ memory footprint in order to operate.
4141
## Requirements
4242

4343
* Python (3.10 or later)
44+
* rdflib (7.3 or later)
4445
* [Requests](http://docs.python-requests.org/) (optional)
4546
* [aiohttp](https://aiohttp.readthedocs.io/) (optional)
4647

@@ -128,6 +129,15 @@ normalized = jsonld.normalize(
128129
# that can be used for hashing, comparison, etc.
129130
```
130131

132+
`jsonld.to_rdf()` returns an `rdflib.Dataset` when no output `format` is
133+
requested. To keep the RDF.js-like dataset `dict` used by PyLD versions lower
134+
than 4, pass
135+
`{'legacyMode': True}`:
136+
137+
```python
138+
dataset = jsonld.to_rdf(doc, {'legacyMode': True})
139+
```
140+
131141
## Features & conformance
132142

133143
This library aims to conform with the following W3C Recommendations:
@@ -421,4 +431,4 @@ See [`LICENSE`](./LICENSE) file for details.
421431
The PyLD library is maintained by [Miel Vander
422432
Sande](https://github.com/mielvds), [Anatoly
423433
Scherbakov](https://github.com/anatoly-scherbakov) and [Digital
424-
Bazaar](https://github.com/digitalbazaar) (Original authors of `PyLD`).
434+
Bazaar](https://github.com/digitalbazaar) (Original authors of `PyLD`).

docs/reference/to_rdf.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
show_bases: false
1313
heading_level: 3
1414

15+
When `format` is not set, `jsonld.to_rdf()` returns an
16+
[`rdflib.Dataset`](https://rdflib.readthedocs.io/). Set `legacyMode` to `True`
17+
to return the RDF.js-like dataset `dict` used by PyLD versions lower than 4.
18+
1519
## Example
1620

1721
{{ example('to_rdf.py') }}

lib/pyld/options.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ class ToRdfOptions(ProcessingOptions, total=False):
178178
rdfDirection: Literal['i18n-datatype']
179179
"""Only `i18n-datatype` supported."""
180180

181+
legacyMode: bool
182+
"""`True` to return the RDF.js-like dataset `dict` used by PyLD versions lower than 4 instead of an `rdflib.Dataset` when `format` is not set (default: `False`)."""
183+
181184

182185
class FromRdfOptions(TypedDict, total=False):
183186
format: Literal['application/n-quads']

0 commit comments

Comments
 (0)