URI Schemes and Backends¶
Py-EthPM uses the
BaseURIBackend as the parent class for all of its URI backends. To write your own backend, it must implement the following methods.
Return a bool indicating whether or not this backend is capable of resolving the given URI to a manifest. A content-addressed URI pointing to valid manifest is said to be capable of “resolving”.
Return a bool indicating whether this backend class can translate the given URI to a corresponding content-addressed URI. A registry URI is said to be capable of “transalating” if it points to another content-addressed URI in its respective on-chain registry.
Fetch the contents stored at the provided uri, if an available backend is capable of resolving the URI. Validates that contents stored at uri match the content hash suffixing the uri.
Py-EthPM has multiple backends available to fetch/pin files to IPFS. The desired backend can be set via the environment variable:
- Connect to a local IPFS API gateway running on port 5001.
- Won’t pin/fetch files to an actual IPFS node, but mocks out this behavior.
Pin asset(s) found at the given path and returns the pinned asset data.
Py-EthPM offers a backend to fetch files from Github,
A valid content-addressed Github URI must conform to the following scheme, as described in ERC1319, to be used with this backend.
This util function will return a content-addressed URI, as defined by Github’s blob scheme. To generate a content-addressed URI for any manifest stored on github, this function requires accepts a Github API uri that follows the following scheme.
>>> from ethpm.uri import create_content_addressed_github_uri >>> owned_github_api_uri = "https://api.github.com/repos/ethpm/py-ethpm/contents/ethpm/assets/owned/1.0.1.json" >>> content_addressed_uri = "https://api.github.com/repos/ethpm/py-ethpm/git/blobs/a7232a93f1e9e75d606f6c1da18aa16037e03480" >>> actual_blob_uri = create_content_addressed_github_uri(owned_github_api_uri) >>> assert actual_blob_uri == content_addressed_uri
The URI to lookup a package from a registry should follow the following format. (subject to change as the Registry Contract Standard makes it’s way through the EIP process)
- URI must be a string type
authority: Must be a valid ENS domain or a valid checksum address pointing towards a registry contract.
package-name: Must conform to the package-name as specified in the EthPM-Spec.
version: The URI escaped version string, should conform to the semver version numbering specification.