Python scripting interface

I’m writing a program that uses the pcbnew python API to pull data from a kicad_pcb file. I’ve been using the low-level python interface, but there seem to be several other options, for instance, pointhi’s abstraction layer and this one as well. I’m getting the job done with the low-level interface, but it’s slow-going; I’m spending most of my time reading the kicad C++ source code, which I hadn’t looked at before this. I’m thinking about switching to one of these abstraction layers, but I’m not sure which to choose (there are even a few others but don’t seem to be maintained). Is it worth using one of these over the SWIG interface? If so, any thoughts on which one? Is there any plan to bring one of these into the main Kicad source?

@pointhi’s abstraction layer seems to be adopted by the lead developers if I have understood correctly.

I also use the low level API and I mainly use the doxygen documentation for the reference. From my experience the API does change, but not significantly. Though it did force me to implement unit/integration testing for spotting the changes quickly.

that’s the plan. I assume I can start improving it in summer, to cover more parts of the pcbnew api. To be clear: don’t assume that this API stays the same. And be aware it is missing some fundamental parts at the moment (where you need to fallback on the lowlevel api). Like adding new items.

1 Like

Great, thanks for the reply. I noticed setup.py specifies python2. I did a quick test with the list_pcb.py using python3 and it seems to work fine. Is there a reason the shebang line states python2?

The simple reason: This port was made before the Python 3 port, but it is fully compatible to Python 3. I assume the final API will be Python 3 only to make sure no Python 2 code is written anymore :stuck_out_tongue:

4 Likes

On a more serious note:
Ditching python 2 support also removes a lot of unneeded incompatibility handling that would be needed to ensure both are supported. And with python 2 being allowed to finally die this year i am convinced that it is simply not worth investing any time into new stuff to get it compatible with python 2

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.