Registry / serialization / rocrate

rocrate

JSON →
library0.15.0pypypi✓ verified 87d ago

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.

pip install rocrate
INSTALL
IMPORT
SIG · ROCRATE
R
rocrate
serializationpythonv0.15.0
Install
2.7s avg
Import
822ms
Disk
25MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.15.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.865s · 26.4MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.7s · import 0.780s · 27MB
25MB installed
● package 25MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ROCrate
from rocrate.rocrate import ROCrate
Entity
from rocrate.model import Entity
File
from rocrate.model import File
Dataset
from rocrate.model import Dataset
Person
from rocrate.model import Person

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)}")
rocrate --version
Debug
Known issues
breakingThe `id` attribute of `Entity` objects became read-only in version `0.10.0`. Attempts to modify `entity.id` directly after creation will raise an `AttributeError`.
fix
Entity IDs must be set during instantiation. If you need a different ID, create a new `Entity` instance with the desired ID and update references accordingly.
affects: >=0.10.0
gotchaFrom version `0.12.0`, contextual entity IDs are no longer automatically prepended with a hash (`#`) by default. If your code relied on this implicit hashing, the generated IDs will differ.
fix
Review how contextual entity IDs are generated and referenced in your application. Ensure that IDs are consistent with the new explicit handling, or update your code to prepend the hash manually if required for specific uses.
affects: >=0.12.0
deprecatedPython 3.8 support was dropped in version `0.12.0`. Projects requiring `rocrate` `0.12.0` or newer must use Python 3.9 or higher.
fix
Upgrade your Python environment to 3.9 or newer. If upgrading Python is not an option, you must pin `rocrate` to a version older than `0.12.0` (e.g., `rocrate<0.12.0`).
affects: >=0.12.0
gotchaVersion `0.15.0` introduced updates for reading data entities, especially for RO-Crate 1.2 specifications. While generally backward compatible, complex or non-standard RO-Crate 1.2 structures might require explicit handling or thorough testing.
fix
When consuming RO-Crates, especially those conforming to RO-Crate 1.2, ensure your parsing logic is robust. Test with your specific RO-Crate structures to confirm compatibility, and refer to the `RO-Crate version selector` if encountering issues.
affects: >=0.15.0
Errors
Common errors & fixes
AttributeError: can't set attribute 'id'
Attempting to modify the `id` attribute of an `Entity` instance after `rocrate==0.10.0`.
fix
The `id` attribute is read-only. Create a new `Entity` instance with the desired ID and update any references to it.
ModuleNotFoundError: No module named 'rocrate.model'
Incorrect import path for core RO-Crate classes like `Entity`, `File`, `Dataset`, or `Person`.
fix
Ensure you are importing these classes directly from `rocrate.model`, e.g., `from rocrate.model import File`.
ValidationError: 1 validation error for ROCrate
Incompatible constructor options or schema validation failures due to stricter validation introduced in versions like `0.14.0`, often related to `pydantic`.
fix
Review the traceback for specific field errors. Consult the latest documentation for `ROCrate` and entity constructors to ensure all arguments and properties conform to the expected schema and types for your `rocrate` version.
TypeError: ROCrate.__init__() got an unexpected keyword argument 'source'
Using outdated constructor arguments for `ROCrate`, or attempting to pass arguments not supported by the current version.
fix
Check the `ROCrate` constructor signature in the documentation for your `rocrate` version. For example, to read an existing RO-Crate, use `ROCrate('/path/to/crate')` or `ROCrate(source=zip_file_object)` (if applicable) instead of `source` as a keyword argument.
Upgrade
Version history
0.15.0latest on PyPI · released Apr 13, 2026
Audit
Dependencies
requestsrequiredFor handling HTTP requests, e.g., fetching remote files.
jsonschemarequiredFor JSON Schema validation.
pydanticrequiredUsed for data validation and parsing, specifically versions 2.x.
typing_extensionsrequiredFor backporting newer `typing` features to older Python versions if needed.
Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
rocrate — pip install rocrate · libregistry