BagIt Profile Validator
The `bagit-profile` library provides tools to validate BagIt Profiles, ensuring that digital preservation packages conform to a specified set of rules. It is designed to work in conjunction with the `bagit` library to validate actual BagIt bags against these profiles. The current version is 1.3.1, with an infrequent release cadence (last major release in 2020).
Common errors
-
ModuleNotFoundError: No module named 'bagit_profile'
cause The `bagit-profile` library is not installed in your current Python environment.fixRun `pip install bagit-profile` to install the library. -
AttributeError: module 'bagit_profile' has no attribute 'BagitProfile'
cause This usually happens when you try to access the `BagitProfile` class after a generic `import bagit_profile` without explicitly importing the class. For example: `import bagit_profile; profile = bagit_profile.BagitProfile(...)`fixUse the correct import statement: `from bagit_profile import BagitProfile`. Then you can directly use `profile = BagitProfile(...)`. -
json.decoder.JSONDecodeError: Expecting value: line X column Y (char Z)
cause The BagIt Profile JSON file or URI you are trying to load is malformed or invalid JSON, preventing the library from parsing it.fixInspect the JSON content (from file or URI) for syntax errors (e.g., missing commas, unclosed brackets, incorrect string escaping). Use a JSON validator tool to pinpoint the exact issue.
Warnings
- gotcha The `bagit-profile` library has not been updated since March 2020. While functional, users should be aware of its infrequent maintenance and consider potential compatibility issues with newer Python versions or significant changes in the `bagit` library.
- breaking Prior to version 1.3.1, validation of Bag-Info tags was case-sensitive, which could lead to unexpected validation failures if tag names varied in casing (e.g., 'Bagging-Date' vs 'bagging-date').
- gotcha The library explicitly depends on `bagit==1.7.0`. While `bagit` is generally stable, future breaking changes in the `bagit` library could cause incompatibilities if `bagit-profile` is not updated.
Install
-
pip install bagit-profile
Imports
- BagitProfile
import bagit_profile; profile = bagit_profile.BagitProfile(...)
from bagit_profile import BagitProfile
Quickstart
import os
from bagit_profile import BagitProfile
# Define a public BagIt Profile URI for demonstration
profile_uri = "https://raw.githubusercontent.com/bagit-profiles/bagit-profiles/master/bagitProfileFAB.json"
print(f"Attempting to load BagIt Profile from URI: {profile_uri}")
try:
# Load the BagIt Profile from the URI
profile = BagitProfile.from_uri(profile_uri)
print(f"\nSuccessfully loaded profile with identifier: {profile.bag_profile_identifier}")
print(f"Profile version: {profile.profile_version}")
print(f"BagIt-Profile-Description: {profile.bag_info.get('BagIt-Profile-Description', 'N/A')}")
# To perform actual validation, you would need a 'bagit.Bag' object:
# from bagit import Bag
# bag = Bag('/path/to/your/bag') # Replace with an actual Bag path
# is_valid = profile.validate(bag)
# print(f"\nBag validation result: {is_valid}")
# if not is_valid:
# print("Validation errors:")
# for error in profile.errors:
# print(f"- {error}")
except Exception as e:
print(f"\nAn error occurred during profile loading: {e}")