Create Research Object Crates (RO-Crates) using Pydantic types
Project description
Pydantic-RO-Crates
Overview
Pydantic-RO-Crates is a Python library for preparing RO-Crates using Pydantic types. It supports the building of json-ld RO-Crate metadata graphs, as well as preparing rich HTML previews of them.
Features
- Build crates pythonically, using Pydantic types for all schema.org types
- Include ("localise") certain files into the crate
- Package crates as .zip
- Prepare HTML preview in the crate, as human-readable accompianment to the machine-readable RO-Crate metadata JSON-ld
- Where localised files are previewable (e.g. HTML files from reporting tools), these are linked into a "website in a crate"
- Plugins (
contribs) for extra functionality, like making HTML maps
Installation
pip install pydantic-ro-crates
Usage
from pydantic2_schemaorg.Dataset import Dataset
from pydantic2_schemaorg.GeoCoordinates import GeoCoordinates
from pydantic_ro_crates.crate.ro_crate import ROCrate
from pydantic_ro_crates.graph.models import ROOT_PATH, LocalalisableFile
roc = ROCrate()
# define a location metadata - we can use GeoCoordinates type from schema.org
location = GeoCoordinates(
longitude=14.25,
latitude=40.808333,
name="Sample location",
id_=f"#location-ERS2154049"
)
# add the location entity to the crate:
roc += location
# maybe we need to add a non-standard property to a standard type like the root Dataset
# just inherit the Pydantic type, and add another field!
class DataSetWithLocation(Dataset):
location: GeoCoordinates
# now make the root dataset - this is core to the RO-Crate spec
dataset = DataSetWithLocation(
id_=ROOT_PATH,
name="Sample ERS2154049 - Mediterranean surface marine water",
description="Mediterranean surface marine water, part of study of protist temporal diversity",
identifier="ERS2154049",
location=location,
)
# add root dataset to the crate, too
roc += dataset
# Use the mapping plugin to make a nice rendered map of the locations
from pydantic_ro_crates.contrib.mapping.render_map import render_leaflet_map
from pathlib import Path
render_leaflet_map([location], output=Path("map.html"), title=dataset.name)
# add the map html file as a "localisable" file; i.e. include it in the packaged crate AND the crate metadata graph
roc.add_localised_file(
LocalalisableFile(
id_="map.html",
source_on_host=Path("map.html"),
name="Sample map",
description="Map of sample coordinates"
)
)
# package the crate as a zip: the metadata json, preview html, and the included map html
roc.zip(Path("my-crate.zip"))
[!NOTE] Citing this work If you find this package useful for academic work and wish to cite it, it is described in a BioHackrXiv preprint:
Rogers A, Bäuerle F, Beracochea M, et al. Enhancing multi-omic analyses through a federated microbiome analysis service. BioHackrXiv; 2025. DOI: 10.37044/osf.io/3x274.
Development
Issues and pull-requests are very welcome.
Development requirements
poetry
Development installation
-
Clone the repository:
git clone https://github.com/EBI-Metagenomics/pydantic-ro-crates.git cd pydantic-ro-crates
-
Install with poetry:
poetry install -
Run tests:
poetry run pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_ro_crates-0.2.1.tar.gz.
File metadata
- Download URL: pydantic_ro_crates-0.2.1.tar.gz
- Upload date:
- Size: 17.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf32b2b6311ab21807870b57e5bca9d9f09065b02c512a50e9eb4f42432dc615
|
|
| MD5 |
e9b359c3787ec081e6fa4df09dedb99f
|
|
| BLAKE2b-256 |
b547f061f9f79fc9a5c8226a431b1d1ed70ccf305e02420e58603ab40228a6e6
|
Provenance
The following attestation bundles were made for pydantic_ro_crates-0.2.1.tar.gz:
Publisher:
publish.yml on EBI-Metagenomics/pydantic-ro-crates
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_ro_crates-0.2.1.tar.gz -
Subject digest:
bf32b2b6311ab21807870b57e5bca9d9f09065b02c512a50e9eb4f42432dc615 - Sigstore transparency entry: 169893385
- Sigstore integration time:
-
Permalink:
EBI-Metagenomics/pydantic-ro-crates@8d9ec179e6690fd4f0a162a02390f6079ae487c2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/EBI-Metagenomics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8d9ec179e6690fd4f0a162a02390f6079ae487c2 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file pydantic_ro_crates-0.2.1-py3-none-any.whl.
File metadata
- Download URL: pydantic_ro_crates-0.2.1-py3-none-any.whl
- Upload date:
- Size: 21.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2d57fdd2cf1d455464107466bd19cb688e3e69f642fea081fb6218caaa6ea9f
|
|
| MD5 |
4ffbb58f8d042a0591625bc0832a7928
|
|
| BLAKE2b-256 |
69d62100923295b7b79adacaea2779aa8e38280593bfc7a5d1f9f3ce9b30186f
|
Provenance
The following attestation bundles were made for pydantic_ro_crates-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on EBI-Metagenomics/pydantic-ro-crates
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_ro_crates-0.2.1-py3-none-any.whl -
Subject digest:
c2d57fdd2cf1d455464107466bd19cb688e3e69f642fea081fb6218caaa6ea9f - Sigstore transparency entry: 169893386
- Sigstore integration time:
-
Permalink:
EBI-Metagenomics/pydantic-ro-crates@8d9ec179e6690fd4f0a162a02390f6079ae487c2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/EBI-Metagenomics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8d9ec179e6690fd4f0a162a02390f6079ae487c2 -
Trigger Event:
workflow_run
-
Statement type: