Skip to content

Packages

Use client.Packages to browse a project's Package Registry, transfer generic package files, and download an ARC's generated RO-Crate. packageId is the numeric registry package ID; generic file operations use the package name, version, and file name instead.

Upload and download currently accept or return text strings. These methods do not provide a binary byte-stream API. Listing returns the server's current page.

Setup

Replace the example token and project ID with your own. Python examples call each API from an async function, then run that function with asyncio.run. In an existing async application, call the API with await inside its running event loop. The repository runs these exact snippets against offline fixtures during documentation checks.

#r "nuget: DataHubClient"

open DataHubClient

let client = DataHubClient("https://git.nfdi4plants.org", Authentication.PersonalAccessToken("your-datahub-pat"))
let projectId = 42
import { DataHubClient } from "@nfdi4plants/datahub-client";
import { Authentication } from "@nfdi4plants/datahub-client/Http/Authentication.js";

const client = new DataHubClient("https://git.nfdi4plants.org", Authentication.PersonalAccessToken("your-datahub-pat"));
const projectId = 42;
import asyncio
from datahub_client import DataHubClient, Authentication

client = DataHubClient("https://git.nfdi4plants.org", Authentication.PersonalAccessToken("your-datahub-pat"))
project_id = 42

ListAsync

Filter the registry by package type and name. Both filters are optional.

let packages =
    client.Packages.ListAsync(projectId, packageType = "generic", packageName = "arc-export")
    |> Async.RunSynchronously
for package in packages do printfn $"{package.Name}@{package.Version}"
const packages = await client.Packages.ListAsync(projectId, "generic", "arc-export");
for (const pkg of packages) console.log(`${pkg.Name}@${pkg.Version}`);
async def list_example():
    return await client.Packages.ListAsync(
        project_id, package_type="generic", package_name="arc-export"
    )


packages = asyncio.run(list_example())
for package in packages:
    print(f"{package.Name}@{package.Version}")

GetAsync

Read the registry metadata for a package ID returned by ListAsync.

let package = client.Packages.GetAsync(projectId, 9) |> Async.RunSynchronously
printfn "%s" package.Version
const pkg = await client.Packages.GetAsync(projectId, 9);
console.log(pkg.Version);
async def get_example():
    return await client.Packages.GetAsync(project_id, 9)


package = asyncio.run(get_example())
print(package.Version)

UploadGenericFileAsync

Upload a text file under a generic package name and version. This writes to the registry and returns the server's response body as a string.

let uploadResponse =
    client.Packages.UploadGenericFileAsync(projectId, "arc-export", "1.0.0", "manifest.json", """{"name":"My ARC"}""")
    |> Async.RunSynchronously
printfn "%s" uploadResponse
const uploadResponse = await client.Packages.UploadGenericFileAsync(
  projectId, "arc-export", "1.0.0", "manifest.json", JSON.stringify({ name: "My ARC" })
);
console.log(uploadResponse);
async def upload_example():
    return await client.Packages.UploadGenericFileAsync(
        project_id, "arc-export", "1.0.0", "manifest.json", '{"name":"My ARC"}'
    )


upload_response = asyncio.run(upload_example())
print(upload_response)

DownloadGenericFileAsync

Read a generic package file as text; parse it separately when it contains JSON or another structured format.

For the DataHub's generated ARC export, see DownloadROCrateAsync, which supplies the standard package coordinates for you.

let content =
    client.Packages.DownloadGenericFileAsync(projectId, "arc-export", "1.0.0", "manifest.json")
    |> Async.RunSynchronously
printfn "%s" content
const content = await client.Packages.DownloadGenericFileAsync(
  projectId, "arc-export", "1.0.0", "manifest.json"
);
console.log(content);
async def download_example():
    return await client.Packages.DownloadGenericFileAsync(
        project_id, "arc-export", "1.0.0", "manifest.json"
    )


content = asyncio.run(download_example())
print(content)

DownloadROCrateAsync

Download an ARC's currently available generated main-branch RO-Crate as JSON-LD text. This method takes only the numeric project ID and fetches isa_arc_json/0.0.1/arc-ro-crate-metadata.json from the generic Package Registry. It is available since version 0.5.0.

The following examples create an anonymous client. Replace the project ID and use a token if the export requires credentials. The JavaScript and TypeScript examples retrieve JSON-LD text in either a browser or Node.js; the F# and Python examples also save the text as UTF-8. See Download and save for Node.js filesystem and browser download-link examples.

#r "nuget: DataHubClient"

open System.IO
open System.Text
open DataHubClient

let client = DataHubClient("https://git.nfdi4plants.org", Authentication.Anonymous())
let projectId = 42

let metadata =
    client.Packages.DownloadROCrateAsync(projectId)
    |> Async.RunSynchronously

File.WriteAllText("arc-ro-crate-metadata.json", metadata, UTF8Encoding(false))
printfn "Saved arc-ro-crate-metadata.json"
import { DataHubClient } from "@nfdi4plants/datahub-client";
import { Authentication } from "@nfdi4plants/datahub-client/Http/Authentication.js";

const client = new DataHubClient("https://git.nfdi4plants.org", Authentication.Anonymous());
const projectId = 42;

const metadata = await client.Packages.DownloadROCrateAsync(projectId);
import asyncio
from pathlib import Path
from datahub_client import DataHubClient, Authentication

client = DataHubClient("https://git.nfdi4plants.org", Authentication.Anonymous())
project_id = 42


async def download_ro_crate():
    metadata = await client.Packages.DownloadROCrateAsync(project_id)
    Path("arc-ro-crate-metadata.json").write_text(metadata, encoding="utf-8", newline="")
    print("Saved arc-ro-crate-metadata.json")


asyncio.run(download_ro_crate())

The export is not guaranteed to represent the latest commit. See Download an ARC RO-Crate for export freshness and handling missing or inaccessible exports.