EDA-RW : a Python library to read LibrePCB files (e.g. for Spice)

Hi, I am the author of GitHub - PySpice-org/PySpice: Simulate electronic circuit using Python and the Ngspice / Xyce simulators · GitHub a Python library for running Spice Simulation.

A few years ago, I wrote a Python library to read KiCad 6 schematics. However, extracting the netlist required an insane code because a KiCad schematic is essentially just a drawing similar to SVG but stored as S-expressions.

A week ago, I tested LibrePCB, and discovered its file format is far superior ! Thus, I decided to add support for it and revamped my project to GitHub - PySpice-org/eda-rw: Python library to read/write KiCad and LibrePCB Sexpr file format · GitHub. Thanks to modern Python, the code for reading LibrePCB file is short and efficient.

Actually, it is not certain that new features need to be added to LibrePCB. I think a custom attribute might suffice for this purpose.

I also recently tried the built-in simulation in KiCad, but it was a complete failure:

  • KiCad only offers raw SPICE; consequently, to simulate mains voltage, you have to enter SPICE commands manually and remember that the 230 V value is an RMS value…
  • My test was a reverse engineering, thus I drew the real circuit. But for simulation, it might make sense to merge two resistors in series, for example.
  • KiCad’s simulation user interface and plotting are inefficient ( I don’t want to say a toy feature ). And it is unrealistic to reimplement Matlab in KiCad…

I therefore consider KiCad’s approach to simulation to be unsuitable. Personally, I prefer designing the circuit using a graphical interface, then exporting it to PySpice and using Python code to handle the rest.

1 Like

Hi @fabrice,

Nice project! And the LibrePCB parser is indeed very short and simple :slightly_smiling_face:

It’s great to see some simulation approaches becoming available for LibrePCB. Generally I’d also like to integrate simulation into LibrePCB some day, but due to limited resources and higher priority tasks, this won’t happen in the near future. So it’s good to already have the possibility of using external tools to simulate LibrePCB circuits.

See also Simulation in LibrePCB.

Just let me know if you have any questions or ideas how we could help.

Do you actually already have some quickstart guide how to use PySpice for LibrePCB projects? I mean, what do I need to know to make the circuit usable by PySpice (you mentioned custom attributes)? In the end, it might be nice to publish a quick tutorial on docs.librepcb.org, since from time to time users are asking for simulation.