Here’s the ironic bummer of it all.  I have been watching Adafruit/Digikey’s excellent “All The Internet of Things” videos.  Ironic, because in the 2nd episode where Limor discusses public JSON APIs, I can’t find a JSON API for Digikey.  Um…so this is why in MakeDigikeyBom I resorted to screen scraping.  Well guess what?  Screen scraping is considered by the Digikey server to be a spam bot making evil…when all I want to do is automate buying parts from Digikey.  Sad.  Very sad…

(A note: I have done many posts about MakeDigikeyBom….it’s what I use to go from a Kicad eeschema to ordering parts on Digikey…I am a novice Python developer and all that good stuff.  If you want to make a BoM with a more professional tool, run – don’t walk – to Kicost.)

To start again….

How neat is this? Octopart has a BoM tool that accepts a CSV/spreadsheet files of parts to buy.  It searches multiple parts sources and returns where the parts can be purchased and how much it costs.  To make things even better, they have made it easy to order parts after the search.  My goal is to update the current workflow I have to go from Schematic design to order parts (mostly on Digikey) to include Octopart’s BoM tool in the back end.  Using Octopart’s BoM tool makes it easiest for me to go from an inventory of parts I need to choosing the quantity/price/vendor for parts to order.  In the process, I keep track of my current inventory of parts in an effort to avoid over ordering of parts I use between projects.

The Goal

The goal of this post is to document the changes I made to MakeDigikeyBoM in order to use Octopart’s BoM tool. 

Open Source

Files for this project are located at this GitHub location.


Oh…before we begin…let me fess up and say the input mechanic I am using is horrible.  At this point, I’m hard coding the file path/file names.  I was thinking of getting “fancy” and using something like Tkinter … but I left doing so for another occasion.  I wanted to move on to something else I am working on…since I see this tool as for my own use, it is trivial for me to go in and modify file locations.  Sorry about that!

I’m calling this project “makeBOMCSV.”  The biggest improvement is not screen scraping Digikey!  MakeDigikeyBoM gets the HTML page and then parses through to get quantity/price info.  makeBOMCSV just creates a CSV file that is then loaded into Octopart’s BoM tool.  I then rely on Octopart’s BoM tool to go from my order list to ordering from one or more suppliers.   

Here is a block diagram for makeBOMCSV:

I reuse the MakeDigikeyBom code that reads in the XML file created after running eeSchema’s “XML BoM Generator”. is the workhorse code.  It contains the function:

def replaceJellyBeanParts(outputFrom_bom2csv,jellyBeanFile):

This function sucks in the rows of the two files:

Munges around in them, ultimately spitting out an intermediate CSV file that has resolved the manufacturing numbers for the jelly bean parts.  Now all parts have manufacturer numbers which is used by the Octopart tool to search supplier’s sites for availability/quantity/pricing.
The intermediate CSV file is fed to the function:
def makeBOMfile(parts,outDir):
that is located in
The python codes opens up the inventory CSV file that I’ve manually and somewhat grumpily keep updated with inventory information.  
Note: there is a variable 
numPCBs =3
Which is a multiplier on the number of parts to order.  Since I order from OSH Park, this is usually 3.  I end up messing one or two attempts, so I typically make sure I have an inventory for three build.
The **** in quantity is a visual that lets me know when I don’t have any inventory for a part.  This is just a safety measure over total reliance on automation.
An updated inventory file is created that includes the current date/time in the name.  This is to be used the next time a BoM is created in place of the current inventory.csv file.
And the file that gets fed into the Octopart BoM tool, BoMforOctopart.csv is created.
The next step is using the Octopart BoM tool and feeding in the BoMforOctopart.csv file.

Maybe this stuff is useful to you.  If so, I am happy!  Thanks for reading this far.  Please find many things to smile about.