Another simple BOM generator script

It’s here on Ye Olde Github.

Obviously there is a lot of discussion about this topic and about what KiCad should and should not provide. This is not going to end those discussions, but I’m posting this to show that it’s possible to write a little Python script to run a KiCad schematic against a master parts list and generate a BOM with actual orderable part numbers you can use to buy parts. I based my script on the standard examples that ship with KiCad 6.

The parts list database is a CSV file exported from an Apple Numbers spreadsheet, but you can use any source you like. Details about what the CSV file must contain are noted in the README.

This requires that every symbol in the design have a custom field called PN, and that field must be populated with a Part Number that exists in the CSV file’s first column. The README has a description of this field and how it is used.

This script solved an immediate need I have, using the current stable version of KiCad. Perhaps it can be a model for others, or at least spark ideas. A previous version of this script took the CSV file that the KiCad 5 XSL scripts created and looked up each part against my parts list. This script eliminates the need for that intermediate script.

What this script does not do (so don’t get your hopes up, Cheese):

  1. It doesn’t accept a “number of kits” parameter, so it’s the BOM for one kit for assembly. A full-fledged plug-in with user interface that asks that question is probably the way to go with this, but I think that will have to wait until support for plug-ins for KiCad Schematic is added.
  2. It doesn’t output a BOM you can directly submit to Mouser, DigiKey or one of the PCB assembly places. I suppose it should not be too difficult to read their support docs and see what they need. In that case, it’s probably best to have a script, a script, and so forth.
  3. It does not have support for assembly variants, for example a do-not-stuff marker for one assembly but not another. I have an idea that involves the use of Text Variables in the Schematic Setup, but I haven’t figured out how to put on the schematic a list of the variants allowed for parts that need them.
  4. The “estimated cost” is really just a WAG as it’s based on a number I put into my “part cost” field when I added the part to the spreadsheet. Ideally it could look up a price on Mouser or OctoPart but … later.

Regarding whether the script is “Pythonic” or not. Hey, I do FPGAs all day, and I use Python for quick scripts and to drive tests. I don’t write applications in the language.