Skip to main content

Parse Apple BOM files using the Rust apple-bom parser

Project description

pyapplebom

pyapplebom is a Python library for parsing Apple Bill of Materials (BOM) files (commonly found inside .pkg installers).

It uses the Rust crate apple-bom for parsing and exposes rich metadata to Python.

Features

  • Full BOM file parsing through Rust apple-bom
  • High-level path metadata (paths, hl_index, size64, vindex)
  • Low-level metadata:
    • BOM header
    • blocks index
    • variables index
    • typed block decoding (BomInfo, Tree, Paths, PathRecord, etc.)
  • Optional raw block bytes (hex encoded)
  • Tested interface with a real BOM fixture
  • Cross-platform design for Linux, macOS, and Windows

Installation

From PyPI

pip install pyapplebom

From source

Prerequisites:

  • Python 3.8+
  • Rust toolchain (stable)
  • pip

Install:

python -m venv .venv
source .venv/bin/activate
pip install maturin
pip install -e .

On Windows PowerShell, activate with .venv\\Scripts\\Activate.ps1.

Quick Start

from pathlib import Path
import pyapplebom

bom = pyapplebom.parse_bom_file("/path/to/Bom")

print(bom["header"]["magic"])        # BOMStore
print(len(bom["paths"]))              # Number of parsed paths in the Paths tree
print(bom["paths"][0]["path"])       # e.g. "."
print(bom["paths"][0]["symbolic_mode"])  # e.g. drwxr-xr-x

API

parse_bom(data, *, include_blocks=True, include_raw_block_bytes=False, max_input_bytes=134217728, max_paths=250000)

Parse BOM content from bytes-like input.

parse_bom_bytes(data, *, include_blocks=True, include_raw_block_bytes=False, max_input_bytes=134217728, max_paths=250000)

Alias of parse_bom.

parse_bom_file(path, *, include_blocks=True, include_raw_block_bytes=False, max_input_bytes=134217728, max_paths=250000)

Parse BOM content from a file path.

All parsing functions also accept these keyword-only resource limits:

  • max_input_bytes=134217728: maximum input size (128 MiB)
  • max_paths=250000: maximum declared or traversed paths per optional path section

The defaults are exported as pyapplebom.DEFAULT_MAX_INPUT_BYTES and pyapplebom.DEFAULT_MAX_PATHS. Increase them explicitly only when parsing a trusted BOM that legitimately exceeds a default.

Exceptions

  • pyapplebom.BomParseError: Raised for BOM parsing errors.

Security Model

BOM files are treated as untrusted binary input. Before invoking the upstream parser, pyapplebom validates the file magic, index and block ranges, count-to-size relationships, path references, traversal cycles, expanded path data, and configured resource limits. Unexpected upstream Rust panics are contained and converted into parse errors.

Invalid top-level layout and resource amplification raise BomParseError. An invalid optional section such as Paths is returned as None with details in parse_errors, allowing safe metadata from other sections to remain available. Resource limits bound in-process work; they are not an operating-system sandbox for adversarial parsing.

Return Structure

Each parse call returns a dictionary with these keys:

  • format: Always "apple-bom"
  • byte_length: Input size in bytes
  • source_path: Included for parse_bom_file
  • header: BOM header metadata
  • blocks_index: Index metadata (count and block entries)
  • variables: BOM variables (BomInfo, Paths, HLIndex, VIndex, Size64 when present)
  • bom_info: Parsed BomInfo metadata, or None
  • paths: Parsed paths list, or None
  • hl_index: Parsed hard link index paths, or None
  • size64: Parsed Size64 paths, or None
  • vindex: Parsed VIndex paths, or None
  • blocks: Parsed block list (typed metadata) when include_blocks=True, else None
  • parse_errors: Optional parse errors for non-fatal sections, or None

Path entry fields

Path entries in paths/hl_index/size64/vindex include:

  • path, path_type, path_type_raw
  • file_mode, symbolic_mode
  • user_id, group_id
  • mtime, mtime_iso8601
  • size, crc32, link_name

Testing

Run tests:

python -m venv .venv
source .venv/bin/activate
python -m pip install -e '.[dev]'
python -m pytest --cov=pyapplebom --cov-report=term-missing

Run the full local quality and security suite:

cargo fmt --all -- --check
cargo clippy --all-targets --all-features --locked -- -D warnings
cargo test --all-targets --all-features --locked
python -m ruff check .
python -m ruff format --check .
python -m mypy
zizmor --offline --strict-collection --min-severity=medium .
python -m pip_audit --requirement <(python -m pip freeze --all --exclude-editable) --no-deps --strict --progress-spinner=off
cargo audit --deny warnings --file Cargo.lock

CI additionally measures src/validation.rs with cargo-llvm-cov and requires at least 80% line coverage. Python branch coverage is required to remain at 100%.

Build and Publish (manual PyPI workflow)

Build wheels and source distribution:

python -m venv .venv
source .venv/bin/activate
pip install maturin
maturin build --release --locked --out dist
maturin sdist --out dist

Artifacts are placed in dist/.

Publish manually with your preferred process (for example twine upload) after validating test/build outputs.

GitHub Tag Release Automation

This repo includes a release workflow at .github/workflows/release.yml that:

  • builds wheels for:
    • Linux x86_64 and aarch64
    • Windows x86_64 and aarch64
    • macOS x86_64 and aarch64
  • builds an sdist
  • verifies the tag version matches both pyproject.toml and Cargo.toml
  • publishes to PyPI on tags matching v* (for example v0.1.0)

Compatibility Notes

  • Uses pyo3 with abi3 (abi3-py38) for broad CPython binary compatibility.
  • CI runs dependency-free installed-wheel smoke tests on Python 3.8 and the full test suite on a maintained Python release.
  • No platform-specific runtime logic is required for parsing.
  • Build targets are suitable for Windows, Linux, and macOS when compiled on those platforms.

License

MIT

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

pyapplebom-0.1.1.tar.gz (33.4 kB view details)

Uploaded Source

Built Distributions

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

pyapplebom-0.1.1-cp38-abi3-win_arm64.whl (157.9 kB view details)

Uploaded CPython 3.8+Windows ARM64

pyapplebom-0.1.1-cp38-abi3-win_amd64.whl (163.4 kB view details)

Uploaded CPython 3.8+Windows x86-64

pyapplebom-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (249.4 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

pyapplebom-0.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (237.6 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

pyapplebom-0.1.1-cp38-abi3-macosx_11_0_arm64.whl (226.8 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

pyapplebom-0.1.1-cp38-abi3-macosx_10_12_x86_64.whl (235.7 kB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file pyapplebom-0.1.1.tar.gz.

File metadata

  • Download URL: pyapplebom-0.1.1.tar.gz
  • Upload date:
  • Size: 33.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pyapplebom-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6c572abaf21444b0eafdb0ddd86b0362b26d88d14e5b1c2b82535ec9e25f8262
MD5 1aa16585d96ff7b670384ed53e555c02
BLAKE2b-256 ab36993bc8db450cfde34f92921e77b0e2efc23f4a673175b75d34455e440d53

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapplebom-0.1.1.tar.gz:

Publisher: release.yml on bwhitn/pyapplebom

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

File details

Details for the file pyapplebom-0.1.1-cp38-abi3-win_arm64.whl.

File metadata

  • Download URL: pyapplebom-0.1.1-cp38-abi3-win_arm64.whl
  • Upload date:
  • Size: 157.9 kB
  • Tags: CPython 3.8+, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pyapplebom-0.1.1-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 191b6fa2d42e5e78e0d2427a2d099b140a6cae895edcf004bc8f887c63a5f1d3
MD5 19cc220b52b786d4af28ca5b8d4b9ed1
BLAKE2b-256 461cee96430c1b0df4749f8d937bd444fcae0fffbb7b2981063f909b4d504a85

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapplebom-0.1.1-cp38-abi3-win_arm64.whl:

Publisher: release.yml on bwhitn/pyapplebom

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

File details

Details for the file pyapplebom-0.1.1-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: pyapplebom-0.1.1-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 163.4 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pyapplebom-0.1.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 52d00ce5aacc3b79da910ec09f0e3edbfd539347c61625c4eabd4de801d9cc82
MD5 5699c2ef8a63c24636306e95e4341c80
BLAKE2b-256 70cdc1aa0d1098c4f57bae25fcf39bd000cf0559083b172997478103f664234d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapplebom-0.1.1-cp38-abi3-win_amd64.whl:

Publisher: release.yml on bwhitn/pyapplebom

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

File details

Details for the file pyapplebom-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyapplebom-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f7e4651875d6f6ccd2b044edc986da5bc22bdb232a627e4ae896592a9d3d0096
MD5 3b129a4bcce9d065ce6f81f3fb2c33a7
BLAKE2b-256 579354e5e4aee4a8509b0ffb7dc5c0e327998e898518dd484325c15476e9a3d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapplebom-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on bwhitn/pyapplebom

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

File details

Details for the file pyapplebom-0.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyapplebom-0.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9ab3db485018fc7e84e5e07471ff044f24ab52c53f5d3f46f57d75b5830dce25
MD5 d77c4219314b5b1a547712bdf368d130
BLAKE2b-256 e1c387d4abd50c5ab33babdece14bda30d731158f321825447a14ac4af372606

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapplebom-0.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on bwhitn/pyapplebom

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

File details

Details for the file pyapplebom-0.1.1-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyapplebom-0.1.1-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f8adea2b714f8a9f34987a237ad6e5adc4e2817a3790b124539f97abfe812818
MD5 b25f88f36875dbd38607c111981d8722
BLAKE2b-256 4801463d76ea9658613114a77737a759e3f93adf3d576acdd04f00b9cd813cfe

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapplebom-0.1.1-cp38-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on bwhitn/pyapplebom

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

File details

Details for the file pyapplebom-0.1.1-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pyapplebom-0.1.1-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 aff7b75822efc37d8685f21abef5e9f485351d447011a1008f8af412f1d9b91c
MD5 1f1c94b00f5b190df737f1ccc1d678fc
BLAKE2b-256 ce2d34b5dd2d25196bfeed07569d61a19bdd85f7ca18db56f488a6ca394488be

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapplebom-0.1.1-cp38-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on bwhitn/pyapplebom

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