Registry / serialization / pyld
library3.0.0pypypi✓ verified 87d ago

PyLD is a Python implementation of a JSON-LD processor, providing tools for working with Linked Data in JSON. It offers core JSON-LD operations such as compaction, expansion, flattening, and framing, adhering to the JSON-LD 1.1 specification. The library is actively maintained, with its current version 3.0.0 released in February 2024. While there isn't a fixed public release cadence, the project shows ongoing development and significant updates.

pip install pyld
INSTALL
IMPORT
SIG · PYLD
P
pyld
serializationpythonv3.0.0
Install
3.3s avg
Import
567ms
Disk
40MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.960 runs
installs and imports cleanly · install 0.0s · import 0.479s · 40.2MB
glibc
py 3.103.960 runs
installs and imports cleanly · install 3.3s · import 0.428s · 42MB
40MB installed
● package 40MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

jsonld
from pyld import jsonld

This quickstart demonstrates the core functionalities of `pyld` including `compact`, `expand`, and `flatten` operations using a sample JSON-LD document and context. It processes the document to show its compacted, expanded, and flattened forms.

import json from pyld import jsonld doc = { "http://schema.org/name": "Manu Sporny", "http://schema.org/url": {"@id": "http://manu.sporny.org/"}, "http://schema.org/image": {"@id": "http://manu.sporny.org/images/manu.png"} } context = { "name": "http://schema.org/name", "homepage": {"@id": "http://schema.org/url", "@type": "@id"}, "image": {"@id": "http://schema.org/image", "@type": "@id"} } # Compact a document according to a particular context compacted = jsonld.compact(doc, context) print("Compacted document:") print(json.dumps(compacted, indent=2)) # Expand a document, removing its context expanded = jsonld.expand(compacted) print("\nExpanded document:") print(json.dumps(expanded, indent=2)) # Flatten a document flattened = jsonld.flatten(doc) print("\nFlattened document:") print(json.dumps(flattened, indent=2))
Debug
Known issues
breakingPyLD 3.x has increased its Python version requirement. Version 2.x supported Python 3.6+, but 3.x explicitly requires Python 3.10 or later.
fix
Ensure your Python environment is version 3.10 or newer. Upgrade Python if necessary.
affects: 3.0.0 and later
breakingThe `requests` library, previously a default dependency for remote document loading, is no longer automatically installed with `pip install pyld`. If you use PyLD's document loader for fetching remote JSON-LD, you must explicitly install `requests` or `aiohttp`.
fix
Install `pyld` with the `requests` or `aiohttp` extra: `pip install pyld[requests]` or `pip install pyld[aiohttp]`. Alternatively, install `requests` or `aiohttp` directly: `pip install requests`.
affects: 3.0.0 and later
gotchaPyLD uses its own native JSON-LD data structures, which can make direct interoperability with `rdflib` (a common Python RDF library) non-trivial without serialization/re-parsing. A compatibility layer (`rdflib_pyld_compat.py`) exists but is not part of `pyld` itself.
fix
If combining PyLD with `rdflib`, consider using the `rdflib_pyld_compat.py` utility or explicitly convert between data structures by serializing and then re-parsing (e.g., to N-Quads) if a direct bridge is not suitable.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'requests'
The default synchronous document loader in PyLD relies on the `requests` library, but `requests` is no longer a direct dependency of the `pyld` package as of version 3.0.0.
fix
Install `requests` explicitly using `pip install requests` or `pip install pyld[requests]`.
SyntaxError: 'return' outside function (or similar Python version incompatibility errors)
PyLD 3.x requires Python 3.10 or newer. Running it on an older Python version will lead to syntax or runtime errors due to incompatible language features.
fix
Upgrade your Python environment to version 3.10 or higher.
jsonld.compact() (or expand, frame) produces unexpected output (e.g., @context not applied, terms not shortened)
Misunderstanding of how JSON-LD contexts work, or an incorrect/incomplete context being provided to the PyLD processor functions. The JSON-LD specification defines complex algorithms for these operations.
fix
Consult the JSON-LD 1.1 specification (linked from PyLD's documentation) for detailed explanations of compaction, expansion, and framing algorithms. Experiment with simpler contexts and gradually build up to complex ones, verifying each step. Ensure your `@context` definitions are accurate and cover the terms in your document.
Upgrade
Version history
3.0.0latest on PyPI · released Apr 2, 2026
Audit
Dependencies
pythonrequiredPyLD 3.x requires Python 3.10 or later.
requestsoptionalRequired for the default synchronous document loader if fetching remote contexts/documents.
aiohttpoptionalRequired for the asynchronous document loader if fetching remote contexts/documents.
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
pyld — pip install pyld · libregistry