Skip to content

SDKs

The ohi SDKs let Scala/JVM, Python and TypeScript applications search publications on ohi.dev, inspect their metadata, download selected files and save file selections.

Node 22 or later, or a browser with Fetch. Browsers need CORS access to the catalog, publication and artifact endpoints.

Terminal window
npm i @neverblink/ohi

The CLI, the Python package and the TypeScript package share the ohi LinkML release version.

from ohi import CatalogClient, SearchRequest
client = CatalogClient()
page = client.search(
SearchRequest(q="sensors", page=1, per_page=10)
)
if page.hits:
publication = client.inspect(page.hits[0].base_url)
artifact = publication.artifacts[0]
content = client.get(artifact.url)

ohi.CatalogClient is synchronous. search, inspect and get return SearchResult, Publication and bytes, respectively.

Search uses ohi.dev by default. Each call returns one page. Use page to request the next page, per_page to request up to 250 results, and q="*" to browse. See the search options for filtering, sorting and facets.

When a search reports search_cutoff: true, its results or counts may be incomplete.

Pass a hit’s base_url to inspect, choose an artifact in the format you need, then pass its url to get. get returns the file’s bytes for your application to save or load. Dependency files must be selected and retrieved separately.

A known publication or artifact URL can be passed directly to inspect or get, without searching first.

Set timeout_ms to change the default 30000 ms timeout.

from ohi import CatalogClient, CatalogConfig
client = CatalogClient(CatalogConfig(timeout_ms=60000))

To override search settings, supply search_url and query_by together. Omitting both selects ohi.dev. Supplying only one is an error.

Supply all selected and dependency files with their hashes from publication metadata. The URLs and hash below are illustrative.

from ohi import ArtifactSelection, Lock, LockedFile, read_lock, write_lock
selected = LockedFile(
base_url="https://hub.example/releases/energy/2/",
url="https://files.example/energy.ttl",
format="owl-turtle",
sha256="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
)
lock = Lock(
format_version=2,
selections=[ArtifactSelection(base_url=selected.base_url, url=selected.url)],
files=[selected],
)
write_lock("ohi.lock.json", lock)
saved = read_lock("ohi.lock.json")

Use decode_lock and encode_lock from ohi for JSON text. File paths accept a string or path-like object.

Version-1 locks omit hashes and remain supported. See the lock schema.

Create the parent directory before writing a lock. Writes replace an existing lock and preserve its contents on failure.

The ohi SDKs accept revision 2 publication metadata, illustrated by the synthetic Sensors example. Check the publication’s licenses and each artifact’s format and loading roots. Verify downloaded bytes against its size_bytes and sha256 if needed. get does not perform that check.

Catalog failures raise CatalogException. Lock validation and file failures raise LockException. Both expose an .error record with a code and explanatory message. See the error schemas for additional fields.

Use the final HTTP(S) URL for publications and files. Requests do not follow redirects or retry.