ability to fetch from local ipfs instance
not sure if this functionality is on the roadmap but reading context's from IPFS are helpful to a personal use case.
Please let me know what you think, and what changes would be needed to add this to the library
Use example
from pyld import jsonld
import json
context = {
"@context": {
"name": "http://schema.org/name",
"image": {
"@id": "http://schema.org/image",
"@type": "@id"
},
"homepage": {
"@id": "http://schema.org/url",
"@type": "@id"
}
}
}
import ipfshttpclient
client = ipfshttpclient.connect()
cid = client.add_json(context)
doc = {
"@context": f"ipfs://{cid}",
"name": "Manu Sporny",
"homepage": "http://manu.sporny.org/",
"image": "http://manu.sporny.org/images/manu.png"
}
compacted = jsonld.compact(doc, context)
# {
# "@context": {
# "name": "http://schema.org/name",
# "image": {
# "@id": "http://schema.org/image",
# "@type": "@id"
# },
# "homepage": {
# "@id": "http://schema.org/url",
# "@type": "@id"
# }
# },
# "image": "http://manu.sporny.org/images/manu.png",
# "name": "Manu Sporny",
# "homepage": "http://manu.sporny.org/"
# }
@drbh this might be outdated, but I am also interested in using IPFS with pyld. I would believe though that it would be beneficial to create a separate Document Loader for IPFS instead of adding an if to existing requests based loader. Did you pursue that or a different venue to achieve your goal? Were you successful? Is there any public info about your project?
The jsonld.js library has pluggable document loaders--which looks to be what's actually needed here vs. adding custom loader code directly: https://github.com/digitalbazaar/jsonld.js#custom-document-loader
I'd suggest exploring implementing something like that custom document loader approach and then refactoring this to use that approach for pluggability.
closing since this is a bit outdated and a better impl strategy has been suggested above. Thanks!