Skip to content

FrozenDocumentLoader

FrozenDocumentLoader serves only URLs in an allowlist and refuses all other document loads. It is intended for air-gapped runs, reproducible builds, and deployments that must avoid remote context fetching.

With no arguments, the loader serves the curated BUNDLED_CONTEXTS mapping:

from pyld import FrozenDocumentLoader, jsonld

jsonld.set_document_loader(FrozenDocumentLoader())

Bundled Contexts

Context URL Bundled file
https://w3id.org/security/suites/ed25519-2020/v1 lib/pyld/documentloader/frozen/bundled/security-ed25519-2020-v1.jsonld
https://w3id.org/security/suites/jws-2020/v1 lib/pyld/documentloader/frozen/bundled/security-jws-2020-v1.jsonld
https://w3id.org/security/v1 lib/pyld/documentloader/frozen/bundled/security-v1.jsonld
https://w3id.org/security/v2 lib/pyld/documentloader/frozen/bundled/security-v2.jsonld
https://www.w3.org/2018/credentials/v1 lib/pyld/documentloader/frozen/bundled/credentials-v1.jsonld
https://www.w3.org/ns/activitystreams lib/pyld/documentloader/frozen/bundled/activitystreams.jsonld
https://www.w3.org/ns/credentials/v2 lib/pyld/documentloader/frozen/bundled/credentials-v2.jsonld
https://www.w3.org/ns/did/v1 lib/pyld/documentloader/frozen/bundled/did-v1.jsonld

Extend the bundled mapping with additional vetted contexts:

from pathlib import Path

from pyld import BUNDLED_CONTEXTS, FrozenDocumentLoader, jsonld

loader = FrozenDocumentLoader(
    documents=dict(
        BUNDLED_CONTEXTS,
        **{"https://example.com/context": Path("contexts/example.jsonld")},
    )
)

jsonld.expand(doc, options={"documentLoader": loader})

The documents mapping may contain parsed JSON-LD dictionaries or pathlib.Path instances pointing to JSON files. Path entries are read lazily and cached after the first request.

Any URL outside the allowlist raises JsonLdError with code loading document failed.