{"id":20993,"library":"bagit","title":"BagIt","description":"Create and validate BagIt packages, a hierarchical file packaging format for digital preservation. This library supports BagIt version 0.97 and offers strong validation. Current stable release is 1.9.0 (released March 2023). It is mature and well-maintained.","status":"active","version":"1.9.0","language":"python","source_language":"en","source_url":"https://github.com/LibraryOfCongress/bagit-python","tags":["bagit","digital preservation","validation","packaging"],"install":[{"cmd":"pip install bagit","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Python 2/3 compatibility, used in internal utilities.","package":"six","optional":false},{"reason":"Required for installation and metadata handling.","package":"setuptools","optional":true}],"imports":[{"note":"The main module is bagit, not Bag. Bag is a class inside the module.","wrong":"from bagit import Bag","symbol":"bagit","correct":"import bagit"},{"note":"You import the class directly from the module.","wrong":"import bagit.Bag","symbol":"Bag","correct":"from bagit import Bag"}],"quickstart":{"code":"import bagit\nimport os\n\n# Create a bag\nbag_path = '/tmp/mybag'\nos.makedirs(bag_path, exist_ok=True)\nwith open(os.path.join(bag_path, 'test.txt'), 'w') as f:\n    f.write('hello')\nbag = bagit.make_bag(bag_path, checksums=['md5', 'sha256'])\nprint('Bag created:', bag)\n\n# Validate an existing bag\nvalid, messages = bagit.validate_bag(bag_path)\nif valid:\n    print('Bag is valid')\nelse:\n    print('Errors:', messages)","lang":"python","description":"Create a BagIt bag and then validate it."},"warnings":[{"fix":"When making a bag, specify checksums=['md5'] if you need backward compatibility with older tools.","message":"In bagit 1.8.0+, the default checksum algorithm changed from MD5 to SHA256. Scripts relying on MD5 must explicitly pass checksums=['md5'].","severity":"breaking","affected_versions":">=1.8.0"},{"fix":"Use validate_bag(..., fast=True) to skip remote file validation, or use check_completeness() separately.","message":"The validate_bag function modifies the bag in place by writing fetch.txt if any file is missing from the payload. This is unexpected and can cause side effects.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure all file paths within the bag use consistent casing.","message":"Paths in bagit are case-sensitive on Linux but not on macOS/Windows. This can cause validation failures when moving bags between systems.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade to Python 3, or pin bagit to 1.6.0 for Python 2.","message":"Python 2 support ended in bagit 1.9.0. If you need Python 2 compatibility, use bagit < 1.7.0.","severity":"deprecated","affected_versions":">=1.9.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run 'pip install bagit' in the correct Python environment (check with which python or python -m pip).","cause":"The library is not installed or installed in a different Python environment.","error":"ModuleNotFoundError: No module named 'bagit'"},{"fix":"Recreate the bag with bagit.make_bag() or manually add entries to manifest-*.txt.","cause":"The payload directory contains files not listed in the manifest.","error":"ValueError: No manifest declarations for ... but file found in payload."},{"fix":"Restore the missing file or regenerate the bag.","cause":"A file declared in the manifest is missing from the payload directory.","error":"bagit.BagError: Bag validation failed: missing expected file ..."},{"fix":"Update to latest bagit: pip install --upgrade bagit","cause":"Using an older version of bagit (<1.5) that does not support the checksums parameter.","error":"TypeError: make_bag() got an unexpected keyword argument 'checksums'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}