kicad monkey v2026.11.30
On This Page (10)

kcr bom

Generate Bill of Materials (BOM) from KiCad .kicad_sch or .kicad_pro files. CSV/XLSX formats include parameters as columns; JSON preserves nested structure. Config-driven runs can emit raw JSON, grouped tables, and JLCPCB BOM upload columns in one invocation. Config group_fields controls which canonical fields must match before parts collapse into one line item.

CommandAliasesCategoryRuntimeConfigGuide
kcr bom—Fabrication & Manufacturing OutputsPython kcr + Native Rust k3./bom.config in the current working directory (kicad_cruncher.bom.config.a0, auto-created in config mode when --format is omitted)Fabrication & Outputs

Usage

sh
kcr bom [-h] [-o OUTPUT]
    [--format {csv,json,raw-json,generic-json,legacy-json,grouped-json,grouped-csv,grouped-xlsx,jlc-csv,jlc-xlsx,xlsx}]
    [--config CONFIG] [--write-config [PATH]]
    [--variant VARIANT] [--all-variants] [--no-color]
    [file]

Native Rust CLI Equivalent (k3)

Implemented natively in k3 for CSV, grouped CSV, JLC CSV, and JSON formats; Python kcr bom additionally writes formatted .xlsx spreadsheets.

sh
k3 bom [-o OUTPUT] [--format {csv,grouped-csv,jlc-csv,json,raw-json,grouped-json,generic-json}] [--config PATH] [--write-config [PATH]] [--variant NAME | --all-variants] [file]

Positional Arguments

ArgumentDescription
fileKiCad .kicad_sch, .kicad_pro, or .kicad_pcb file (optional if one .kicad_pro in CWD)

Options

FlagDescription
-o, --output OUTPUTOutput directory (default: ./output/bom)
--format FORMATSingle output format; overrides multi-output config mode. Choices: csv, json, raw-json, generic-json, legacy-json, grouped-json, grouped-csv, grouped-xlsx, jlc-csv, jlc-xlsx, xlsx.
--config CONFIGBOM/PnP JSON/JSONC config (default: ./bom.config; created when omitted in config mode)
--write-config PATHWrite a documented JSONC BOM/PnP config template
--variant VARIANTFilter by specific variant name
--all-variantsGenerate BOM for all variants (plus base)
--no-colorDisable ANSI colors and animated spinners

How It Works

kcr bom extracts, normalizes, and groups Bill of Materials tables from KiCad projects (.kicad_pro), standalone schematics (.kicad_sch), or PCBs (.kicad_pcb), with full assembly-variant support.

It operates in two distinct modes:

Input & Config Discovery

  1. Input resolution:
    • Accepts .kicad_pro, .kicad_sch, or .kicad_pcb. (Unlike kcr pnp and kcr jlc, kcr bom accepts standalone .kicad_sch files.)
    • If omitted, auto-detects a single *.kicad_pro in CWD, falling back to a single *.kicad_sch.
  2. bom.config lives in CWD — NOT beside the input file:
    • Explicit --config <path> loads that file.
    • Otherwise, kcr bom looks for ./bom.config in the current working directory.
    • Auto-creation difference across bom / pnp / jlc:
      • kcr bom auto-creates ./bom.config (or the --config path) in config mode when --format is omitted.
      • kcr pnp and kcr jlc never auto-create ./bom.config; they silently use built-in defaults if absent.
  3. --write-config [PATH] dual behavior:
    • With no input file (kcr bom --write-config or kcr bom --write-config bom.config): writes the commented template and exits 0 immediately.
    • With an input file (kcr bom project.kicad_pro --write-config bom.config): writes the template and continues running the BOM export.

Configuration (bom.config)

One shared JSONC schema (kicad_cruncher.bom.config.a0) drives kcr bom, kcr pnp, and kcr jlc:

jsonc
{
  "schema": "kicad_cruncher.bom.config.a0",

  // Case-insensitive parameter aliases; source parameters beat intrinsic fallbacks.
  "field_aliases": {
    "manufacturer": ["Manufacturer", "Mfr", "MFG", "Manufacturer Name", "Mfr Name"],
    "manufacturer_part_number": ["Manufacturer Part Number", "MPN", "Mfr Part Number", "Mfr PN", "MFG PN", "Part Number"],
    "jlcpcb_part_number": ["JLCPCB Part #", "JLCPCB Part Number", "JLC Part #", "JLC Part Number", "LCSC Part #", "LCSC Part Number", "LCSC"],
    "value": ["Value", "Comment"],
    "description": ["Description", "Desc"],
    "footprint": ["Footprint", "Pattern", "Package"]
  },

  // Used when CLI --variant / --all-variants are omitted.
  "variants": {
    "mode": "all",                 // "base" | "all" | "named"
    "names": [],                   // Variant names when mode is "named"
    "include_base": true           // Include base build when mode is "all" or "named"
  },

  "bom": {
    "source_mode": "schematic",    // "schematic" | "pcb" | "merged" (merged resolves like schematic)
    "outputs": ["raw-json", "grouped-xlsx"],
    // Allowed: "raw-json", "legacy-json", "grouped-json", "grouped-csv",
    //          "grouped-xlsx", "jlc-csv", "jlc-xlsx"
    "group_fields": ["mfg", "mpn", "description"],
    "output_fields": ["mfg", "mpn", "description", "quantity", "designators"],
    "include_dnp": true,
    "split_dnp": true,             // Separate fitted vs DNP lines even when group_fields match
    "dnp_placement": "inline",     // "inline" | "end" | "separate"
    "highlight_dnp_rows": true,    // Highlight DNP rows in XLSX workbooks
    "prefix_order": [],            // Shared prefix sort priority (pnp.prefix_order overrides when non-empty)
    "pcb_line_item": {             // Optional synthetic PCB line appended to grouped BOMs
      "enabled": false,
      "designator": "PCB",
      "fields": {}
    }
  },

  "pnp": {
    "outputs": ["json", "csv"],    // "json" | "csv" | "xlsx" | "jlc-cpl" | "jlc-cpl-xlsx"
    "output_fields": ["designator", "comment", "layer", "footprint", "center_x", "center_y", "rotation", "description"],
    "units": "mm",                 // "mm" | "mils" (JLC CPL strictly requires "mm")
    "position_mode": "component-center",
    "exclude_no_bom": false,
    "layer_order": ["top", "bottom"],
    "prefix_order": []
  },

  // Path templates for config mode (supports project text variables + built-in tokens).
  "output": {
    "dir_template": "{Command}",
    "name_template": "{SourceStem}_{VariantName}_{OutputKind}"
  }
}

Available template tokens in output.dir_template and output.name_template: {Command}, {OutputKind}, {SourceName}, {SourceStem}, {VariantName}, plus any KiCad project text variables (e.g. ${REV} -> {REV}).

Precedence & Conflict Rules

  1. Config mode vs legacy --format mode:
    • Passing --format switches to single-output legacy mode, ignores bom.outputs and output.*_template, changes the default output root from ./output to ./output/bom, and suppresses ./bom.config auto-creation. (If ./bom.config or --config already exists, its variants and bom.source_mode are still read.)
  2. Variant selection ladder (highest wins):
    1. --all-variants (emits base + every variant defined in the project; in Python kcr, wins over --variant if both are passed — native Rust k3 rejects combining --variant and --all-variants).
    2. --variant <NAME>.
    3. variants.mode / variants.names / variants.include_base in bom.config.
    • Requesting an unknown variant name logs a warning rather than aborting with a non-zero exit code.
  3. Empty group_fields fallback:
    • When every configured field in bom.group_fields is empty for a component (for instance, a part missing mfg, mpn, and description), grouping automatically falls back to (value, footprint, description) so unrelated parts never collapse into one line.
  4. bom.source_mode behavior:
    • "schematic" reads compiled schematic BOM rows; "pcb" derives BOM rows from PCB placements (exclude_no_bom=True, dnp=False); "merged" currently resolves identically to "schematic" in the KiCad command path.
  5. Provenance snapshots:
    • Config-mode runs always write bom.config.used.json (plain JSON, stripped of JSONC comments) into each generated artifact's directory so downstream ERP/purchasing pipelines can verify the exact effective config.
  6. Python kcr vs native Rust k3:
    • Native Rust k3 bom writes CSV and JSON formats (csv, grouped-csv, jlc-csv, json, raw-json, grouped-json, generic-json), whereas Python kcr bom additionally writes formatted .xlsx spreadsheets (xlsx, grouped-xlsx, jlc-xlsx).

Quick Examples

sh
# Config mode (uses or creates ./bom.config; writes raw-json + grouped-xlsx by default)
kcr bom project.kicad_pro -o output
sh
# Single-format legacy mode (does not auto-create bom.config)
kcr bom project.kicad_pro --format grouped-csv -o output/bom
sh
# Export BOM for a specific assembly variant
kcr bom project.kicad_pro --variant Proto -o output
kicad-monkey v2026.11.30·Docs updated 2026.12.01 15:43 UTC (fd9b75b)