I’m developing an external tool in Python to help me build a database-driven component library. As part of this, I want to write a script that, when given the name of a component (e.g., STM32WBA55HEFx
), retrieves and prints the associated data from the KiCad symbol libraries — such as the symbol name, footprint assignment (e.g Package_CSP:ST_WLCSP-41_2.98x2.76mm_Layout13x7_P0.4mm_Stagger), datasheet URL, and any custom fields.
However, I’m having trouble finding a programmatic way to extract this information without manually opening the symbol chooser and copy-pasting it by hand.
Is there a recommended API, scripting interface, or supported approach to access this data externally? Any pointers would be greatly appreciated.
you could open the file and parse it
All KiCad’s files are readable text in S-expression - Wikipedia format You can load such a file into a buffer in Python with just a few lines of code.
Here’s over 200 KiCad repositories, many with libraries for doing stuff to KiCad files: KiCADNexus · GitHub
There’s bound to be something in there that will help you, if you can find it.
In part, I’m amusing myself this morning and thus, offer the following:
• There are many ways to do what you want in Python
• What you want to do is accomplished by using one of those ways and, in a small way, it doesn’t matter which way you choose
• In a bigger-way, the way you choose does matter because the ‘specific’ Syntax, the IDE/Editor and File Management is usually tied to the Python you choose
Thus, difficult to suggest because you have not indicated the Python you want to use…
• To avoid needing to copy and paste file contents, you can use Python’s File tools and can Hard-Code the FileName/Path and/or use a File-Chooser…
I suggest:
• Make a list of the Things you want the User and Code to do
• Sketch/Draw what the GUI would look like (unless wanting to do it all from Command-Line input and output/display)
• With that info in-hand, search the Internet for Python Tutorials on doing it… many, many out there. Check out; GeeksforGeeks, W3Schools, pythontutorial all are very popular with good examples. StackExchange is also good for Help
That said, here’s a Teaser (video) showing some GUI’s I made in WXFormBuilder (because it’s my favorite WX Python GUI Tool but, I’ve done many with other popular Python-IDE/GUI’s).
Some List files, some Read/list contents, some Search&Replace content some will Walk-Through the entire Directory and take acton on All of the Files or, just the one selected…
And, you can Make Plugin’s with your code…
Good Luck…