# rocrate-validator
[](https://github.com/crs4/rocrate-validator/actions/workflows/testing.yaml) [](https://github.com/crs4/rocrate-validator/actions/workflows/release.yaml) [](https://pypi.org/project/roc-validator/) [](https://rocrate-validator.readthedocs.io/en/latest/) [](https://opensource.org/licenses/Apache-2.0)
<!-- [](https://repolab.crs4.it/lifemonitor/rocrate-validator/-/pipelines?page=1&scope=branches&ref=develop) -->
<!-- [](https://codecov.io/gh/crs4/rocrate-validator) -->
`rocrate-validator` (available as `roc-validator` on PyPI) is a Python package to validate [RO-Crate](https://researchobject.github.io/ro-crate/)s
against different profiles, including the base RO-Crate profile and various extensions.
## Features
- Validates RO-Crates against the profiles they declare to conform to.
Currently, validation for the following profiles is implemented:
- [RO-Crate](https://w3id.org/ro/crate/1.1) *(base profile)*
- [Workflow RO-Crate](https://w3id.org/workflowhub/workflow-ro-crate/1.0)
- [Workflow Testing RO-Crate](https://w3id.org/ro/wftest)
- [Workflow Run Crate](https://w3id.org/ro/wfrun/workflow)
- [Process Run Crate](https://w3id.org/ro/wfrun/process)
- [Provenance Run Crate](https://w3id.org/ro/wfrun/provenance)
- Filters profile validation rules by requirement level (i.e., `REQUIRED`, `RECOMMENDED`, `OPTIONAL`).
- Provides detailed information about the issues found during validation.
- Supports validation of RO-Crates stored locally as directories or as ZIP archives (`.zip` files) or remotely accessible via HTTP or HTTPS (e.g., `http://example.com/ro-crate.zip`).
- Supports [CLI-based validation](#cli-based-validation) as well as [programmatic validation](#programmatic-validation) (so it can easily be used by Python code).
- Extensible framework: new RO-Crate profiles can be added, implementing profile requirements as SHACL shapes and/or Python code.
<div style="background: #F0F8FF; border-left: 4px solid #007ACC; text-indent: -43px; padding: 20px 60px; border-radius: 8px; margin-bottom: 40px; height: auto; font-weight: lighter;">
<b>Note:</b> <span class="disabled font-light">this software is still work in progress. Feel free to try it out,
report positive and negative feedback. We also welcome contributions, but we suggest you send us a note (e.g., by opening an Issue) before starting to develop any code. The implementation of validation code for additional RO-Crate profiles would be particularly welcome.
</div>
## Installation
You can install the package using `pip` or `poetry`. The following instructions assume you have Python 3.8 or later installed.
#### [Optional Step: Create a Virtual Environment](#optional-step-create-a-virtual-environment)
It’s recommended to create a virtual environment before installing the package to avoid dependency conflicts. You can create one using the following command:
```bash
python3 -m venv .venv
```
Then, activate the virtual environment:
- On **Unix** or **macOS**:
```bash
source .venv/bin/activate
```
- On **Windows** (Command Prompt):
```bash
.venv\Scripts\activate
```
- On **Windows** (PowerShell):
```powershell
.venv\Scripts\Activate.ps1
```
### 1. Using `pip` (from PyPI)
You can install the package using `pip`:
```bash
pip install roc-validator
```
### 2. Using `poetry` (from source)
Clone the repository:
```bash
git clone https://github.com/crs4/rocrate-validator.git
```
Navigate to the project directory:
```bash
cd rocrate-validator
```
Ensure you have Poetry installed. If not, follow the instructions [here](https://python-poetry.org/docs/#installation). Then, install the package using `poetry`:
```bash
poetry install
```
## CLI-based Validation
After installation, use the `rocrate-validator` command to validate RO-Crates. You can run this in an active virtual environment (if created in the [optional step](#optional-step-create-a-virtual-environment) above) or without a virtual environment if none was created.
### 1. Using the installed package
Run the validator using the following command:
```bash
rocrate-validator validate <path_to_rocrate>
```
where `<path_to_rocrate>` is the path to the RO-Crate you want to validate.
Type `rocrate-validator --help` for more information.
### 2. Using `poetry`
Run the validator using the following command:
```bash
poetry run rocrate-validator validate <path_to_rocrate>
```
where `<path_to_rocrate>` is the path to the RO-Crate you want to validate.
Type `rocrate-validator --help` for more information.
## Programmatic Validation
You can also integrate the package programmatically in your Python code.
Here's an example:
```python
# Import the `services` and `models` module from the rocrate_validator package
from rocrate_validator import services, models
# Create an instance of `ValidationSettings` class to configure the validation
settings = services.ValidationSettings(
# Set the path to the RO-Crate root directory
rocrate_uri='/path/to/ro-crate',
# Set the identifier of the RO-Crate profile to use for validation.
# If not set, the system will attempt to automatically determine the appropriate validation profile.
profile_identifier='ro-crate-1.1',
# Set the requirement level for the validation
requirement_severity=models.Severity.REQUIRED,
)
# Call the validation service with the settings
result = services.validate(settings)
# Check if the validation was successful
if not result.has_issues():
print("RO-Crate is valid!")
else:
print("RO-Crate is invalid!")
# Explore the issues
for issue in result.get_issues():
# Every issue object has a reference to the check that failed, the severity of the issue, and a message describing the issue.
print(f"Detected issue of severity {issue.severity.name} with check \"{issue.check.identifier}\": {issue.message}")
```
The following is a possible output:
```bash
RO-Crate is invalid!
Detected issue of severity REQUIRED with check "ro-crate-1.1:root_entity_exists: The RO-Crate must contain a root entity.
```
## Running the tests
To run the `rocrate-validator` tests, use the following command:
```bash
poetry run pytest
```
<!-- ## Contributing
Contributions are welcome! Please read our [contributing guidelines](CONTRIBUTING.md) for details. -->
## License
This project is licensed under the terms of the Apache License 2.0. See the
[LICENSE](LICENSE) file for details.
## Acknowledgements
This work has been partially funded by the following sources:
- the [BY-COVID](https://by-covid.org/) project (HORIZON Europe grant agreement number 101046203);
- the [LIFEMap](https://www.thelifemap.it/) project, funded by the Italian Ministry of Health (Piano Operative Salute, Trajectory 3).
<img alt="Co-funded by the EU"
src="https://raw.githubusercontent.com/crs4/rocrate-validator/develop/docs/img/eu-logo/EN_Co-fundedbytheEU_RGB_POS.png"
width="250" align="right"/>
Raw data
{
"_id": null,
"home_page": null,
"name": "roc-validator",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": "RO-Crate, validation, metadata, research object, data management, scientific data, Python",
"author": "Marco Enrico Piras",
"author_email": "kikkomep@crs4.it",
"download_url": "https://files.pythonhosted.org/packages/d1/1b/b41f048ff76c6d8d450b9f41c45d775db061500f6f21b4674166465d3941/roc_validator-0.6.0.tar.gz",
"platform": null,
"description": "# rocrate-validator\n\n[](https://github.com/crs4/rocrate-validator/actions/workflows/testing.yaml) [](https://github.com/crs4/rocrate-validator/actions/workflows/release.yaml) [](https://pypi.org/project/roc-validator/) [](https://rocrate-validator.readthedocs.io/en/latest/) [](https://opensource.org/licenses/Apache-2.0)\n\n<!-- [](https://repolab.crs4.it/lifemonitor/rocrate-validator/-/pipelines?page=1&scope=branches&ref=develop) -->\n\n<!-- [](https://codecov.io/gh/crs4/rocrate-validator) -->\n\n`rocrate-validator` (available as `roc-validator` on PyPI) is a Python package to validate [RO-Crate](https://researchobject.github.io/ro-crate/)s\nagainst different profiles, including the base RO-Crate profile and various extensions.\n\n## Features\n\n- Validates RO-Crates against the profiles they declare to conform to.\n Currently, validation for the following profiles is implemented:\n - [RO-Crate](https://w3id.org/ro/crate/1.1) *(base profile)*\n - [Workflow RO-Crate](https://w3id.org/workflowhub/workflow-ro-crate/1.0)\n - [Workflow Testing RO-Crate](https://w3id.org/ro/wftest)\n - [Workflow Run Crate](https://w3id.org/ro/wfrun/workflow)\n - [Process Run Crate](https://w3id.org/ro/wfrun/process)\n - [Provenance Run Crate](https://w3id.org/ro/wfrun/provenance)\n- Filters profile validation rules by requirement level (i.e., `REQUIRED`, `RECOMMENDED`, `OPTIONAL`).\n- Provides detailed information about the issues found during validation.\n- Supports validation of RO-Crates stored locally as directories or as ZIP archives (`.zip` files) or remotely accessible via HTTP or HTTPS (e.g., `http://example.com/ro-crate.zip`).\n- Supports [CLI-based validation](#cli-based-validation) as well as [programmatic validation](#programmatic-validation) (so it can easily be used by Python code).\n- Extensible framework: new RO-Crate profiles can be added, implementing profile requirements as SHACL shapes and/or Python code.\n\n<div style=\"background: #F0F8FF; border-left: 4px solid #007ACC; text-indent: -43px; padding: 20px 60px; border-radius: 8px; margin-bottom: 40px; height: auto; font-weight: lighter;\">\n<b>Note:</b> <span class=\"disabled font-light\">this software is still work in progress. Feel free to try it out,\nreport positive and negative feedback. We also welcome contributions, but we suggest you send us a note (e.g., by opening an Issue) before starting to develop any code. The implementation of validation code for additional RO-Crate profiles would be particularly welcome.\n</div>\n\n## Installation\n\nYou can install the package using `pip` or `poetry`. The following instructions assume you have Python 3.8 or later installed.\n\n#### [Optional Step: Create a Virtual Environment](#optional-step-create-a-virtual-environment)\n\nIt\u2019s recommended to create a virtual environment before installing the package to avoid dependency conflicts. You can create one using the following command:\n\n```bash\npython3 -m venv .venv\n```\n\nThen, activate the virtual environment:\n\n- On **Unix** or **macOS**:\n\n```bash\nsource .venv/bin/activate\n```\n\n- On **Windows** (Command Prompt):\n\n```bash\n.venv\\Scripts\\activate\n```\n\n- On **Windows** (PowerShell):\n\n```powershell\n.venv\\Scripts\\Activate.ps1\n```\n\n### 1. Using `pip` (from PyPI)\n\nYou can install the package using `pip`:\n\n```bash\npip install roc-validator\n```\n\n### 2. Using `poetry` (from source)\n\nClone the repository:\n\n```bash\ngit clone https://github.com/crs4/rocrate-validator.git\n```\n\nNavigate to the project directory:\n\n```bash\ncd rocrate-validator\n```\n\nEnsure you have Poetry installed. If not, follow the instructions [here](https://python-poetry.org/docs/#installation). Then, install the package using `poetry`:\n\n```bash\npoetry install\n```\n\n## CLI-based Validation\n\nAfter installation, use the `rocrate-validator` command to validate RO-Crates. You can run this in an active virtual environment (if created in the [optional step](#optional-step-create-a-virtual-environment) above) or without a virtual environment if none was created.\n\n### 1. Using the installed package\n\nRun the validator using the following command:\n\n```bash\nrocrate-validator validate <path_to_rocrate>\n```\n\nwhere `<path_to_rocrate>` is the path to the RO-Crate you want to validate.\n\nType `rocrate-validator --help` for more information.\n\n### 2. Using `poetry`\n\nRun the validator using the following command:\n\n```bash\npoetry run rocrate-validator validate <path_to_rocrate>\n```\n\nwhere `<path_to_rocrate>` is the path to the RO-Crate you want to validate.\n\nType `rocrate-validator --help` for more information.\n\n## Programmatic Validation\n\nYou can also integrate the package programmatically in your Python code.\n\nHere's an example:\n\n```python\n\n# Import the `services` and `models` module from the rocrate_validator package\nfrom rocrate_validator import services, models\n\n# Create an instance of `ValidationSettings` class to configure the validation\nsettings = services.ValidationSettings(\n # Set the path to the RO-Crate root directory\n rocrate_uri='/path/to/ro-crate',\n # Set the identifier of the RO-Crate profile to use for validation.\n # If not set, the system will attempt to automatically determine the appropriate validation profile.\n profile_identifier='ro-crate-1.1',\n # Set the requirement level for the validation\n requirement_severity=models.Severity.REQUIRED,\n)\n\n# Call the validation service with the settings\nresult = services.validate(settings)\n\n# Check if the validation was successful\nif not result.has_issues():\n print(\"RO-Crate is valid!\")\nelse:\n print(\"RO-Crate is invalid!\")\n # Explore the issues\n for issue in result.get_issues():\n # Every issue object has a reference to the check that failed, the severity of the issue, and a message describing the issue.\n print(f\"Detected issue of severity {issue.severity.name} with check \\\"{issue.check.identifier}\\\": {issue.message}\")\n```\n\nThe following is a possible output:\n\n```bash\nRO-Crate is invalid!\nDetected issue of severity REQUIRED with check \"ro-crate-1.1:root_entity_exists: The RO-Crate must contain a root entity.\n```\n\n## Running the tests\n\nTo run the `rocrate-validator` tests, use the following command:\n\n```bash\npoetry run pytest\n```\n\n<!-- ## Contributing\n\nContributions are welcome! Please read our [contributing guidelines](CONTRIBUTING.md) for details. -->\n\n## License\n\nThis project is licensed under the terms of the Apache License 2.0. See the\n[LICENSE](LICENSE) file for details.\n\n## Acknowledgements\n\nThis work has been partially funded by the following sources:\n\n- the [BY-COVID](https://by-covid.org/) project (HORIZON Europe grant agreement number 101046203);\n- the [LIFEMap](https://www.thelifemap.it/) project, funded by the Italian Ministry of Health (Piano Operative Salute, Trajectory 3).\n\n<img alt=\"Co-funded by the EU\"\n src=\"https://raw.githubusercontent.com/crs4/rocrate-validator/develop/docs/img/eu-logo/EN_Co-fundedbytheEU_RGB_POS.png\"\n width=\"250\" align=\"right\"/>\n\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "A Python package to validate RO-Crates",
"version": "0.6.0",
"project_urls": {
"Documentation": "https://github.com/crs4/rocrate-validator",
"Homepage": "https://github.com/crs4/rocrate-validator",
"Repository": "https://github.com/crs4/rocrate-validator"
},
"split_keywords": [
"ro-crate",
" validation",
" metadata",
" research object",
" data management",
" scientific data",
" python"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "0f8a47e9a09351acffb8fa9eac3c44b2032e2a18e9de24ef742ed047a55aed74",
"md5": "d5cfbb9cef7e8710dd6a91b6ae1db58a",
"sha256": "d7b2741973a5ac53f48b9aa2d6633569162e29ebf94113c7572e26efbad02359"
},
"downloads": -1,
"filename": "roc_validator-0.6.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d5cfbb9cef7e8710dd6a91b6ae1db58a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 188035,
"upload_time": "2025-02-06T11:06:34",
"upload_time_iso_8601": "2025-02-06T11:06:34.808901Z",
"url": "https://files.pythonhosted.org/packages/0f/8a/47e9a09351acffb8fa9eac3c44b2032e2a18e9de24ef742ed047a55aed74/roc_validator-0.6.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "d11bb41f048ff76c6d8d450b9f41c45d775db061500f6f21b4674166465d3941",
"md5": "25d751c8f22493b5f963278b6b7720c3",
"sha256": "1ea4dec3c49b364fd57b726db6a81a739db45fe97adba910f1cb51f57e1888ea"
},
"downloads": -1,
"filename": "roc_validator-0.6.0.tar.gz",
"has_sig": false,
"md5_digest": "25d751c8f22493b5f963278b6b7720c3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 94165,
"upload_time": "2025-02-06T11:06:36",
"upload_time_iso_8601": "2025-02-06T11:06:36.823320Z",
"url": "https://files.pythonhosted.org/packages/d1/1b/b41f048ff76c6d8d450b9f41c45d775db061500f6f21b4674166465d3941/roc_validator-0.6.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-06 11:06:36",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "crs4",
"github_project": "rocrate-validator",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "roc-validator"
}