Skip to main content

Create Research Object Crates (RO-Crates) using Pydantic types

Reason this release was yanked:

The directory naming in this build was incorrect

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.

Composite screenshots of subset of code from this README example and the rendered html previews

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_crate.crate.ro_crate import ROCrate
from pydantic_ro_crate.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_crate.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

  1. Clone the repository:

    git clone https://github.com/EBI-Metagenomics/pydantic-ro-crates.git
    cd pydantic-ro-crates
    
  2. Install with poetry:

    poetry install
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantic_ro_crates-0.2.0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydantic_ro_crates-0.2.0-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_ro_crates-0.2.0.tar.gz.

File metadata

  • Download URL: pydantic_ro_crates-0.2.0.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

Hashes for pydantic_ro_crates-0.2.0.tar.gz
Algorithm Hash digest
SHA256 59c9b0d4d8b90e3d431c730c3ff3f5fc285a80362dfbc19a09656da5dfd37e32
MD5 b704aa1a1548cf6501b8df63efb925bb
BLAKE2b-256 9693a5480e9f54cd14dec35e7b6b3c6b7613e8b80188f2953e0fc61aa17fd6c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_ro_crates-0.2.0.tar.gz:

Publisher: publish.yml on EBI-Metagenomics/pydantic-ro-crates

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pydantic_ro_crates-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_ro_crates-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 39cd8ccf07851a5ec743941f3893701e6d02092334ab205e473ecb1a3f944fc9
MD5 155cf0aaba24e9f1c04b391fd54c5c2b
BLAKE2b-256 a9a7e97186d70627210857c575a3de1bed6a6a27232b9c200e1640bab6065615

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_ro_crates-0.2.0-py3-none-any.whl:

Publisher: publish.yml on EBI-Metagenomics/pydantic-ro-crates

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page