Skip to main content

A Python package to validate RO-Crates

Project description

rocrate-validator

Testing Pipeline Status Release Pipeline Status PyPI - Version Documentation Status License

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.
Note: 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.

Installation

You can install the package using pip or poetry. The following instructions assume you have Python 3.9 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

Development

When working from source, install the dependencies (including the dev and test groups) with:

poetry install

Pre-commit hooks

The repository ships a pre-commit configuration (.pre-commit-config.yaml) that runs spell checking (typos), linting and formatting (ruff), static type checking (mypy), and static analysis (pylint). The hooks are not active until you install them once in your local clone:

poetry run pre-commit install

After this, the fast checks (typos, ruff, basic file hygiene) run automatically on every git commit. The slow whole-project checksmypy, pylint (rocrate_validator), and pylint (tests) — are configured as manual-stage hooks and are not triggered by git commit; run them explicitly when you want a full review:

# Run all auto hooks against the whole codebase
poetry run pre-commit run --all-files

# Run a single auto hook (e.g. typos or ruff)
poetry run pre-commit run typos --all-files

# Run ALL manual hooks (mypy + both pylint runs)
poetry run pre-commit run --hook-stage manual --all-files

# Run a single manual hook
poetry run pre-commit run --hook-stage manual mypy
poetry run pre-commit run --hook-stage manual pylint-main    # rocrate_validator/
poetry run pre-commit run --hook-stage manual pylint-tests   # tests/  (uses tests/.pylintrc)

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:

Co-funded by the EU

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

roc_validator-0.11.1.tar.gz (192.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

roc_validator-0.11.1-py3-none-any.whl (380.4 kB view details)

Uploaded Python 3

File details

Details for the file roc_validator-0.11.1.tar.gz.

File metadata

  • Download URL: roc_validator-0.11.1.tar.gz
  • Upload date:
  • Size: 192.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for roc_validator-0.11.1.tar.gz
Algorithm Hash digest
SHA256 626819bc3cdae2ff6c0846754beaea866cdc3edc342b259a0d9cc16b4983441b
MD5 42706234f06ef4cb799b5ea561cdadd4
BLAKE2b-256 85d38bb5a14f82cae5824059c19347198115b34018aaa5edc8beb01178957572

See more details on using hashes here.

Provenance

The following attestation bundles were made for roc_validator-0.11.1.tar.gz:

Publisher: release.yaml on crs4/rocrate-validator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file roc_validator-0.11.1-py3-none-any.whl.

File metadata

  • Download URL: roc_validator-0.11.1-py3-none-any.whl
  • Upload date:
  • Size: 380.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for roc_validator-0.11.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a00d45b9ac0191e78d920aa214053122aa601efee5ba32f0cfec2d028cac1bd4
MD5 1e02611ebaef639b2b5d0506d901461c
BLAKE2b-256 26e7429faa4da609b6ac868ca3e740a79d0d3866e37a803cfef8be24322932d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for roc_validator-0.11.1-py3-none-any.whl:

Publisher: release.yaml on crs4/rocrate-validator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page