Headless mode for pcbnew Python API / multiple KiCad instances with IPC

Hello,

We are using KiCad in our company for PCB development, and we have developed our own Python scripts based on pcbnew (KiCad 8).

One of our scripts needs to process multiple PCBs in order to extract footprints, zones, tracks, etc. Currently, with the new IPC API, we have to open a separate KiCad instance for each PCB and communicate with it.

What we really need is a headless mode, similar to the old pcbnew.LoadBoard, where we could open a PCB file directly and extract the board information (footprints, zones, tracks, …) without starting the full GUI.

Additionally, in the case where multiple KiCad instances are open, how can a script know which instance it is communicating with?

:point_right: Is a headless mode planned for the new API, or is there an alternative way to achieve this?

kicad-cli has been existing for a while.

Thanks for your reply, but kicad-cli is not what I’m looking for. It offers limited functionality and does not allow retrieving a board and then applying the Python API/IPC functions on it.

the new IPC API in KiCad 9 seems to be what you’re looking for. You can access the API without launching KiCad

If that’s true, the docs need some work:

KiCad IPC API
The IPC API is an interface that can be used to remotely control a running instance of KiCad.

The IPC API currently only supports communication with a running instance of the KiCad GUI. There is no support for running KiCad in a headless mode,

Ah I might have mixed it up then. You can access the KiCad API from a completely different program. I guess that doesn’t mean that you don’t have to run KiCad. Sorry!

However, there are KiCad docker images without UI. You can probably run it as a server for the API access

1 Like

It would probably be possible to have a “headless” version of KiCad instead of always launching a graphical instance. The idea would be to start a terminal or subprocess that we can communicate with, and omit the entire graphical layer. This would allow people like me to use the IPC API without being tied to a KiCad window for each .kicad_pcb file. In cases where a PCB is dense and contains many objects, the graphical part significantly slows down the loading process, which in turn slows down my scripts.

Is a headless mode (without the GUI) something that the development team is considering or has planned for the future?

It will eventually be supported through kicad-cli.

Though I’m not using v8/v9, so I can’t confirm but, even with my v7, I still use the Old method of manually placing my Plugin’s into the Plugins folder… very reliable and no need for Meta/etc…

Have you tried do that?

I do not want and cannot integrate my program as a plugin, because its functionality depends on multiple .kicad_pcb files, and I need to run my script in console mode while using the Python functions. The kicad-cli tool does not meet my needs because it does not allow the use of the kicad-python library to interact with KiCad.

For now you could open all kicad_pcb files in different KiCad instances and then use a script and the API to access all of them?

there is no need to be a ‘plugin’ in order to integrate with old SWIG api. You can run from console.
as stated before, for IPC the GUI instance must be running - but you can run it in the ‘background’ (virtual display) for example: adamws.github.io - Using the new KiCad IPC API in a CI environment