{"id":7688,"library":"rocrate","title":"RO-Crate Python Library","description":"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.","status":"active","version":"0.15.0","language":"en","source_language":"en","source_url":"https://github.com/ResearchObject/ro-crate-py/","tags":["research object","data packaging","metadata","FAIR data","JSON-LD","schema.org"],"install":[{"cmd":"pip install rocrate","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"For handling HTTP requests, e.g., fetching remote files.","package":"requests","optional":false},{"reason":"For JSON Schema validation.","package":"jsonschema","optional":false},{"reason":"Used for data validation and parsing, specifically versions 2.x.","package":"pydantic","optional":false},{"reason":"For backporting newer `typing` features to older Python versions if needed.","package":"typing_extensions","optional":false}],"imports":[{"symbol":"ROCrate","correct":"from rocrate.rocrate import ROCrate"},{"symbol":"Entity","correct":"from rocrate.model import Entity"},{"symbol":"File","correct":"from rocrate.model import File"},{"symbol":"Dataset","correct":"from rocrate.model import Dataset"},{"symbol":"Person","correct":"from rocrate.model import Person"}],"quickstart":{"code":"from rocrate.rocrate import ROCrate\nfrom rocrate.model import Person\nimport os\n\n# Create a new RO-Crate\ncrate = ROCrate()\n\n# Add a main entity (e.g., a README file)\nreadme_content = \"# My Research Crate\\nThis is a sample RO-Crate.\"\nwith open(\"README.md\", \"w\") as f:\n    f.write(readme_content)\nreadme_entity = crate.add_file(\"README.md\")\n\n# Add a person as a contextual entity\nperson = Person(crate, identifier=\"#john_doe\", properties={\n    \"name\": \"John Doe\",\n    \"affiliation\": \"University of Example\"\n})\ncrate.add(person)\n\n# Link the README to the person\nreadme_entity['author'] = person\n\n# Write the RO-Crate to a directory\noutput_dir = \"my_first_crate\"\ncrate.write(output_dir)\n\nprint(f\"RO-Crate created at: {os.path.abspath(output_dir)}\")\nprint(f\"Contents: {os.listdir(output_dir)}\")\n","lang":"python","description":"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."},"warnings":[{"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.","message":"The `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`.","severity":"breaking","affected_versions":">=0.10.0"},{"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.","message":"From 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.","severity":"gotcha","affected_versions":">=0.12.0"},{"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`).","message":"Python 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.","severity":"deprecated","affected_versions":">=0.12.0"},{"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.","message":"Version `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.","severity":"gotcha","affected_versions":">=0.15.0"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"The `id` attribute is read-only. Create a new `Entity` instance with the desired ID and update any references to it.","cause":"Attempting to modify the `id` attribute of an `Entity` instance after `rocrate==0.10.0`.","error":"AttributeError: can't set attribute 'id'"},{"fix":"Ensure you are importing these classes directly from `rocrate.model`, e.g., `from rocrate.model import File`.","cause":"Incorrect import path for core RO-Crate classes like `Entity`, `File`, `Dataset`, or `Person`.","error":"ModuleNotFoundError: No module named 'rocrate.model'"},{"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.","cause":"Incompatible constructor options or schema validation failures due to stricter validation introduced in versions like `0.14.0`, often related to `pydantic`.","error":"ValidationError: 1 validation error for ROCrate"},{"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.","cause":"Using outdated constructor arguments for `ROCrate`, or attempting to pass arguments not supported by the current version.","error":"TypeError: ROCrate.__init__() got an unexpected keyword argument 'source'"}]}