Skip to content

The validation subpackage

gamslib.sip.validation

Validation utilities for Bagit and object directories in GAMS projects.

This subpackage provides functions to validate the structure and metadata of Bagit directories, including checks for required files, manifests, and SIP JSON metadata.

All public functions are made available in the top-level gamslib.sip.validation namespace for easy access.

The most important function is validate_bag, which performs a comprehensive validation of a Bagit directory, including structure, required files, manifests, and SIP JSON metadata. It raises a BagValidationError if any validation check fails.

There are two more functions which might be useful for validating specific aspects of the bag or the metadata:

  • validate_pid(pid): Validates a given PID (Project Identifier) according to specific rules.
  • validate_datastream_id(datastream_id): Validates a given datastream ID

validate_pid

validate_pid(pid)

Validate a given PID (Project Identifier).

A valid id follows the rules of xml:id, with some modifications:

  • All letters must be lowercase ASCII letters.
  • Every id must have the project sigle as prefix, followed by a dot. The prefix must start with a letter, followed by any number of letters and numbers.
  • The part after the dot must start with a letter or a number, followed by any number of ASCII letters, numbers, dots, and dashes.
  • For legacy reasons, the project prefix can be proceeded by a type prefix like 'o:' but we discourage the use of this prefix for new objects. Only lowercase letters and numbers are allowed as type prefix.

Invalid ids are for example:

- .abcdef  (starts with a dot)
- 1abcdef (starts with a number)
- abc/def (contains invalid character '/')
- abc@def (contains invalid character '@')
- abcdef  (no dot)
- abc..def (double dot)
PARAMETER DESCRIPTION
pid

The ID to validate.

TYPE: str

RAISES DESCRIPTION
ValueError

If the ID is invalid. The error message will indicate the reason.

validate_datastream_id

validate_datastream_id(datastream_id)

Validate a given datastream ID.

A valid datastream is must start with a letter or a number, followed by any number of ASCII letters, numbers, dots, and dashes.

PARAMETER DESCRIPTION
datastream_id

The datastream ID to validate.

TYPE: str

RAISES DESCRIPTION
ValueError

If the datastream ID is invalid. The error message will indicate the reason.

validate_bag

validate_bag(bag_dir)

Validate the structure and metadata of a Bagit directory.

PARAMETER DESCRIPTION
bag_dir

Path to the Bagit directory to validate.

TYPE: Path

RAISES DESCRIPTION
BagValidationError

If the bag directory does not exist or any validation check fails.

Notes
  • Runs all standard validation checks: structure, bagit.txt, manifests, SIP JSON, and bag-info.txt.
  • Raises an error immediately if any check fails.