AioHttpDocumentLoader
AioHttpDocumentLoader retrieves JSON-LD documents with aiohttp.
Example aiohttp_class.py
import json
from pyld import AioHttpDocumentLoader, jsonld
doc = {
"@context": {"name": "http://schema.org/name"},
"name": "Earth",
}
loader = AioHttpDocumentLoader(timeout=10)
result = jsonld.expand(doc, options={"documentLoader": loader})
print(json.dumps(result, indent=2))
Output[
{
"http://schema.org/name": [
{
"@value": "Earth"
}
]
}
]
This loader uses asynchronous fetching internally, but JSON-LD processing itself
remains synchronous.
Use secure=True to require HTTPS URLs:
Example aiohttp_secure.py
import json
from pyld import AioHttpDocumentLoader, jsonld
doc = {
"@context": {"name": "http://schema.org/name"},
"name": "Earth",
}
loader = AioHttpDocumentLoader(secure=True, timeout=10)
result = jsonld.expand(doc, options={"documentLoader": loader})
print(json.dumps(result, indent=2))
Output[
{
"http://schema.org/name": [
{
"@value": "Earth"
}
]
}
]
Extra keyword arguments are forwarded to aiohttp request calls:
Example aiohttp_extra_kwargs.py
import json
from pyld import AioHttpDocumentLoader, jsonld
doc = {
"@context": {"name": "http://schema.org/name"},
"name": "Earth",
}
loader = AioHttpDocumentLoader(timeout=10)
result = jsonld.expand(doc, options={"documentLoader": loader})
print(json.dumps(result, indent=2))
Output[
{
"http://schema.org/name": [
{
"@value": "Earth"
}
]
}
]
Install the optional dependency with:
pip install "PyLD[aiohttp]"