RO-Crate Python Library

0.15.0 · active · verified Thu Apr 16

The ro-crate-py library provides tools for generating, parsing, and manipulating RO-Crate (Research Object Crate) metadata. RO-Crate is a community effort to package research data with their metadata, using schema.org types serialized as JSON-LD, and is designed to be human- and machine-readable. The library is actively maintained with frequent releases, currently at version 0.15.0.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a basic RO-Crate, add a file (with content), add a contextual entity (a Person), link the file to the person, and then write the complete RO-Crate to a local directory.

from rocrate.rocrate import ROCrate
from rocrate.model import Person
import os

# Create a new RO-Crate
crate = ROCrate()

# Add a main entity (e.g., a README file)
readme_content = "# My Research Crate\nThis is a sample RO-Crate."
with open("README.md", "w") as f:
    f.write(readme_content)
readme_entity = crate.add_file("README.md")

# Add a person as a contextual entity
person = Person(crate, identifier="#john_doe", properties={
    "name": "John Doe",
    "affiliation": "University of Example"
})
crate.add(person)

# Link the README to the person
readme_entity['author'] = person

# Write the RO-Crate to a directory
output_dir = "my_first_crate"
crate.write(output_dir)

print(f"RO-Crate created at: {os.path.abspath(output_dir)}")
print(f"Contents: {os.listdir(output_dir)}")

view raw JSON →