fair-metadata-integration
Integrate and package all metadata into RO-Crate, linking to other metadata files.
Given a Bilayers workflow
specification and the image data an analysis consumed and produced, this package
writes a Workflow RO-Crate:
an ro-crate-metadata.json describing the run, alongside copies of the files it
describes.
Installation
pip install fair-metadata-integration
Requires Python 3.12 or newer. rocrate is
installed automatically.
Usage
from fair_metadata_integration import create_ro_crate
create_ro_crate(
dest_path="crate",
workflow_schema_filename="config.yaml",
input_paths=["data/input.ome.zarr"],
output_paths=["crate/output.ome.zarr"],
metadata_paths=["data/metadata.yaml"],
parameters="parameters.yaml",
)
-
dest_path— directory the crate is written to, created if it does not exist. -
workflow_schema_filename— the Bilayersconfig.yamldescribing the workflow. -
input_paths— the data the workflow consumed (e.g. OME-Zarr directories or TIFF files). Each gets its own parameter. A single input can also be given as just its path. -
output_paths— the data the workflow produced. Each gets its own parameter. -
metadata_paths— further files describing the data (typically text: JSON, YAML, XML, CSV). They are part of the crate, and copied into its root when outsidedest_path. -
parameters— the values the run used for the parametersconfig.yamldefines: the path of a YAML or JSON file, which is copied into the crate, or adict. Values can be grouped under keys of your own, to any depth; a key that is one of the workflow's parameters is that parameter's value, wherever it is:segmentation: model: MitoNet_v1 tiling: tile_size: 512
A value whose key is not a parameter of the workflow is still recorded, under its dotted path (e.g.
segmentation.tiling.tile_size), with a warning. -
copy_inputs,copy_outputs— copy the inputs, or the outputs, into the crate root when they are outsidedest_path(defaultFalse: referenced, see below). -
gen_preview— write anro-crate-preview.htmlalongside the metadata (defaultTrue). -
name,description— the name and description of the crate's root dataset. -
metadata_conforms_to— the schema the metadata files follow, as adictof itsurland optionally itsnameandversion; each metadata file gets aconformsTolink to it. -
ome_version— whendest_pathis itself an OME-Zarr store, the OME-NGFF version it conforms to (default: the version the store states; see below).
workflow_schema_filename is optional: without it, the crate describes just the
data — the root dataset with the inputs, outputs and metadata files as its
parts — and has no workflow or run. parameters then cannot be given.
OME-Zarr stores, as inputs, outputs or as the crate itself, conform to the
OME-NGFF version they state (conformsTo e.g.
https://ngff.openmicroscopy.org/0.5/), read from zarr.json (0.5) or
.zattrs (0.4 and earlier).
An RO-Crate in an OME-Zarr store
create_zarr_ro_crate describes an OME-Zarr store, written by something else,
with an RO-Crate in the store itself. Only ro-crate-metadata.json (and the
preview) is written; the store is left as it is:
from fair_metadata_integration import create_zarr_ro_crate
create_zarr_ro_crate(
"cells.ome.zarr",
metadata_paths=["cells.ome.zarr/acquisition-metadata.yaml"],
metadata_conforms_to={"url": "https://example.org/model.yaml", "name": "Imaging model", "version": "2.0"},
)
The root dataset is the store: named after it (cells), with the EDAM Zarr
format, the OME-NGFF version it conforms to — ome_version, or else the one the
store states (a warning if they differ, or if neither is known) — and a
description, by default "OME-Zarr image", or "OME-Zarr image with labels".
The metadata files must be in the store; they are about the store.
Helpers for writing a run's files
To package a run of a tool with no hand-written Bilayers config, generate one from the values the run used, and write those values as its parameters file:
from fair_metadata_integration import (WORKFLOW_CONFIG_NAME, bilayers_config, bilayers_format,
create_ro_crate, image_entry, write_bilayers_config,
write_parameters)
values = {"model": "MitoNet_v1", "confidence": 0.5}
config = bilayers_config(
"empanada_3d", values,
inputs=[image_entry("input_image", formats=[bilayers_format("data/input.tif")])],
outputs=[image_entry("segmentation", formats=["omezarr"], section="outputs")],
citations=[{"name": "empanada-napari", "doi": "10.1083/jcb.202208005"}],
docker_image={"org": "ghcr.io/me", "name": "tool", "tag": "1.0", "platform": "linux/amd64"},
cli_command="python run.py",
choices={"model": ["MitoNet_v1", "MitoNet_v1_mini"]},
)
config_path = write_bilayers_config(f"crate/{WORKFLOW_CONFIG_NAME}", config)
parameters_path = write_parameters("crate", values) # crate/parameters.yaml
create_ro_crate("crate", config_path, ["data/input.tif"], ["crate/output.ome.zarr"],
parameters=parameters_path)
bilayers_configmakes every value a parameter whose default is that value, typed from it (checkbox,integer,float,textbox, ordropdownwhen it haschoices); values that areNoneare left out.parameter_entryandimage_entrybuild single entries.write_bilayers_configvalidates the config by converting it with biomero-schema's Bilayers adapter when biomero-schema is installed, and writes it.write_parameterswrites possibly nested values toparameters.yaml(PARAMETERS_FILE_NAME), with values YAML cannot hold (e.g. paths) as text;plain_valueandwrite_yamldo this for any data.
Command line
The same is available as the create-ro-crate command (or
python -m fair_metadata_integration):
create-ro-crate crate config.yaml \
--input data/input.ome.zarr \
--output crate/output.ome.zarr \
--metadata data/metadata.yaml \
--parameters parameters.yaml
--input, --output and --metadata each take one or more paths;
--copy-inputs, --copy-outputs and --gen-preview / --no-gen-preview match the arguments above.
Run create-ro-crate --help for details.
Only the workflow specification, the parameters file and metadata files are
copied into the crate. Data inside dest_path, such as the outputs the workflow
wrote there, is part of the crate where it is. Data outside it, typically the
original input, is not copied but referenced by its file:// URI (unless
copy_inputs or copy_outputs is set):
crate/
├── config.yaml
├── output.ome.zarr/
├── ro-crate-metadata.json
└── ro-crate-preview.html
ro-crate-preview.html is the human-readable
RO-Crate Website
for the crate: a static HTML page (no scripts) with a section for every entity
and all its properties. References between entities link to each other's
section, so you can follow e.g. the workflow to an output parameter and on to the
file it describes; external URIs, types and property names link to their
definitions. Files and folders also get a summary of their content:
- CSV and TSV files: number of rows and columns, and the column names (with
their types, for CellProfiler's
# headerline). - The Bilayers
config.yaml: citations, Docker image, command, and the inputs, outputs and parameters, with the values the run gave the parameters. - OME-Zarr folders (Zarr v2 and v3): axes and units, the shape, chunks, data type and scale of each resolution level, channels, label images, and the plate layout or bioformats2raw image series.
Text files, which a browser would download rather than show, link to a
browsable view in ro-crate-preview_files/: CSV and TSV files as a table (the
first 1,000 rows), JSON and YAML files as a tree of keys and values you can
collapse, and other text files such as CellProfiler pipelines as text (the first
1,000,000 characters).
The preview is described in the metadata as a CreativeWork about the root
dataset, and is not part of the root dataset's hasPart.
What the crate contains
The workflow specification is the crate's mainEntity, typed as a
ComputationalWorkflow. The metadata descriptor declares RO-Crate 1.3, and the
root dataset declares the Workflow RO-Crate 1.1 profile, and the
Process Run Crate and Workflow Run Crate
0.5 profiles for the run (not shown):
{
"@id": "ro-crate-metadata.json",
"@type": "CreativeWork",
"about": { "@id": "./" },
"conformsTo": { "@id": "https://w3id.org/ro/crate/1.3" }
},
{
"@id": "./",
"@type": "Dataset",
"conformsTo": [
{ "@id": "https://w3id.org/workflowhub/workflow-ro-crate/1.1" }
],
"mainEntity": { "@id": "config.yaml" }
}
The workflow's programmingLanguage is a ComputerLanguage entity for the
Bilayers specification, identified by its Zenodo concept DOI
10.5281/zenodo.17652333, which
resolves to the latest release of the spec.
Folders (e.g. OME-Zarr) are Dataset entities, files File entities, with a
path relative to the crate when they are in it and their file:// URI when
they are not. Their encodingFormat is an EDAM
format, from the file name: format_3915 for Zarr, format_3727 for OME-TIFF,
format_3591 for TIFF, and PNG, JPEG, HDF5, CSV, TSV, xlsx, JSON, YAML, XML and
text. Files also give their IANA media type, and each EDAM format is a WebPage
contextual entity with its name, as RO-Crate recommends.
Inputs and outputs are modelled as FormalParameter entities, whose
encodingFormat is the same EDAM format. Each data entity points back at the
parameter it realises via exampleOfWork:
{
"@id": "Nuclei.csv",
"@type": "File",
"encodingFormat": ["text/csv", { "@id": "http://edamontology.org/format_3752" }],
"exampleOfWork": { "@id": "#output" }
},
{
"@id": "#output",
"@type": "FormalParameter",
"name": "output",
"encodingFormat": { "@id": "http://edamontology.org/format_3752" }
},
{
"@id": "http://edamontology.org/format_3752",
"@type": "WebPage",
"name": "CSV"
}
Each parameter config.yaml defines is a FormalParameter input of the
workflow, with its data type (additionalType), description, default value and
whether it is required. The run is a CreateAction, mentioned by the root
dataset, with the workflow as instrument, the input data and parameter values
as object and the output data as result. Each parameter value is a
PropertyValue pointing at its parameter via exampleOfWork, and the
parameters file is about the run:
{
"@id": "#run",
"@type": "CreateAction",
"instrument": { "@id": "config.yaml" },
"object": [{ "@id": "file:///data/input.ome.zarr/" }, { "@id": "#value-model" }],
"result": [{ "@id": "output.ome.zarr/" }]
},
{
"@id": "#value-model",
"@type": "PropertyValue",
"name": "model",
"value": "MitoNet_v1",
"exampleOfWork": { "@id": "#parameter-model" }
},
{
"@id": "#parameter-model",
"@type": "FormalParameter",
"name": "model",
"additionalType": "Text",
"valueRequired": true,
"defaultValue": "MitoNet_v1_mini"
}
Values that are lists or mappings are recorded as JSON text.
The crate's JSON-LD context is extended with terms for describing biological
imaging metadata — biosample, specimen, organism_classification,
preparation_method, channel and others — so those properties can be added to
the crate's entities.
Development
git clone https://github.com/NL-BioImaging/fair-metadata-integration.git
cd fair-metadata-integration
pip install -e ".[test]"
pytest
To inspect an example crate (OME-Zarr input, OME-Zarr and CellProfiler CSV
outputs), test_example_crate writes one and prints its path and that of its
preview; pytest keeps the folders of its last three runs. Run the test module as
a script to write it to a folder of your choice instead:
pytest -s -k test_example_crate
python tests/test_metadata_integration.py [folder]
Releasing
The package version comes from the git tag, via
setuptools-scm; there is no version
to bump in pyproject.toml.
- Optionally, do a dry run: run the Publish to PyPI workflow manually from
the Actions tab. It builds, tests and uploads a development version (e.g.
0.2.4.dev2) to TestPyPI. - Create a GitHub release with a new tag, e.g.
v0.2.4, on the commit to release. Publishing the release builds, tests and uploads that version to PyPI.
PyPI never accepts the same version twice. If a release fails after uploading, release a new version rather than reusing the tag.
License
MIT
Metadata
Release files for fair-metadata-integration 0.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fair_metadata_integration-0.8.0.tar.gz | 43.8 kB | With provenance | Details for fair_metadata_integration-0.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fair_metadata_integration-0.8.0-py3-none-any.whl | Python 3 | none | any | Details for fair_metadata_integration-0.8.0-py3-none-any.whl |
Total release size: 71.1 kB
Release files / fair_metadata_integration-0.8.0.tar.gz
| Download URL | fair_metadata_integration-0.8.0.tar.gz |
|---|---|
| Size | 43.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
753b0bc1421fcc3239f491864f8d924a9d1fdaad5b915962b20b2e68669cd8a3
|
|
BLAKE2b-256 checksum How to use checksums |
0364802cdc6a10adddb86ecfd08c92ad279bf0dc46f1226fce199cfd18399982
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / fair_metadata_integration-0.8.0-py3-none-any.whl
| Download URL | fair_metadata_integration-0.8.0-py3-none-any.whl |
|---|---|
| Size | 27.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f8a6921da7abb2a905f10aed5bb1711ab545eae02d6f409c6b120438e9a95046
|
|
BLAKE2b-256 checksum How to use checksums |
313e6da4afa849ccb4f94ccb203a9b2a733eb14b4381a2f2b0654b5dd39c0b3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logSecurity for fair-metadata-integration 0.8.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for fair_metadata_integration-0.8.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.