A Python package to validate RO-Crates
Project description
rocrate-validator
rocrate-validator
(available as roc-validator
on PyPI) is a Python package to validate RO-Crates
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:
- 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 as well as 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.
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
It’s recommended to create a virtual environment before installing the package to avoid dependency conflicts. You can create one using the following command:
python3 -m venv .venv
Then, activate the virtual environment:
- On Unix or macOS:
source .venv/bin/activate
- On Windows (Command Prompt):
.venv\Scripts\activate
- On Windows (PowerShell):
.venv\Scripts\Activate.ps1
1. Using pip
(from PyPI)
You can install the package using pip
:
pip install roc-validator
2. Using poetry
(from source)
Clone the repository:
git clone https://github.com/crs4/rocrate-validator.git
Navigate to the project directory:
cd rocrate-validator
Ensure you have Poetry installed. If not, follow the instructions here. Then, install the package using poetry
:
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 above) or without a virtual environment if none was created.
1. Using the installed package
Run the validator using the following command:
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:
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:
# 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:
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:
poetry run pytest
License
This project is licensed under the terms of the Apache License 2.0. See the LICENSE file for details.
Acknowledgements
This work has been partially funded by the following sources:
- the BY-COVID project (HORIZON Europe grant agreement number 101046203);
- the LIFEMap project, funded by the Italian Ministry of Health (Piano Operative Salute, Trajectory 3).
- the Italian Research Center on High Performance Computing, Big Data and Quantum Computing - Spoke 9.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file roc_validator-0.7.1.tar.gz
.
File metadata
- Download URL: roc_validator-0.7.1.tar.gz
- Upload date:
- Size: 97.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cba6faae414e32e3ffa6a20419b7354681584d8da869b93bf4e8228a8b8932e5 |
|
MD5 | b970840b354167ed2337e28596b2302a |
|
BLAKE2b-256 | 109e871c93c6e963f27df6c11efd567e8b195fa09f10ef9b4271bc6447443172 |
Provenance
The following attestation bundles were made for roc_validator-0.7.1.tar.gz
:
Publisher:
release.yaml
on crs4/rocrate-validator
-
Statement:
- Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
roc_validator-0.7.1.tar.gz
- Subject digest:
cba6faae414e32e3ffa6a20419b7354681584d8da869b93bf4e8228a8b8932e5
- Sigstore transparency entry: 215699096
- Sigstore integration time:
- Permalink:
crs4/rocrate-validator@43a64320b5baae5a4100d86e4d1d0687b8f400f9
- Branch / Tag:
refs/tags/0.7.1
- Owner: https://github.com/crs4
- Access:
public
- Token Issuer:
https://token.actions.githubusercontent.com
- Runner Environment:
github-hosted
- Publication workflow:
release.yaml@43a64320b5baae5a4100d86e4d1d0687b8f400f9
- Trigger Event:
push
- Statement type:
File details
Details for the file roc_validator-0.7.1-py3-none-any.whl
.
File metadata
- Download URL: roc_validator-0.7.1-py3-none-any.whl
- Upload date:
- Size: 191.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 620e50beb2e97b808cf3a79a416ec248378647e184de7cac71d02991a005bb47 |
|
MD5 | 7fb0a3d12f5bfa5f8826032e3cf2a778 |
|
BLAKE2b-256 | 991edfe8e669a4ef5a6778ad772c07895cf990a59d9513f68f061bc3b6aa3316 |
Provenance
The following attestation bundles were made for roc_validator-0.7.1-py3-none-any.whl
:
Publisher:
release.yaml
on crs4/rocrate-validator
-
Statement:
- Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
roc_validator-0.7.1-py3-none-any.whl
- Subject digest:
620e50beb2e97b808cf3a79a416ec248378647e184de7cac71d02991a005bb47
- Sigstore transparency entry: 215699099
- Sigstore integration time:
- Permalink:
crs4/rocrate-validator@43a64320b5baae5a4100d86e4d1d0687b8f400f9
- Branch / Tag:
refs/tags/0.7.1
- Owner: https://github.com/crs4
- Access:
public
- Token Issuer:
https://token.actions.githubusercontent.com
- Runner Environment:
github-hosted
- Publication workflow:
release.yaml@43a64320b5baae5a4100d86e4d1d0687b8f400f9
- Trigger Event:
push
- Statement type: