Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ability to fetch from local ipfs instance #153

Closed
wants to merge 1 commit into from

Conversation

drbh
Copy link

@drbh drbh commented May 14, 2021

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/"
# }

@anatoly-scherbakov
Copy link
Contributor

@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?

@@ -60,7 +60,22 @@ def loader(url, options={}):
headers = {
'Accept': 'application/ld+json, application/json'
}
response = requests.get(url, headers=headers, **kwargs)

if pieces.scheme == "ipfs":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I have already commented earlier, this should probably be refactored to a separate project.

@BigBlueHat
Copy link
Contributor

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.

@drbh
Copy link
Author

drbh commented Nov 1, 2023

closing since this is a bit outdated and a better impl strategy has been suggested above. Thanks!

@drbh drbh closed this Nov 1, 2023
@drbh drbh deleted the dev/read-from-ipfs branch November 1, 2023 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants