Load Symbol Library from Python Script

I have a project where I am generating the .sch file in Python. Following all rules of file format, I am successful till this stage. However, if there is any custom library (*.lib) file, I can get the pin locations from it, but the symbol doesn’t load.
This is my path to the library: User_Libs/MS50SFA_NRF52/MS50SFA_VCE.lib
So, the symbol should be at User_Libs/MS50SFA_NRF52/MS50SFA_VCE.lib:MS50SFA_NRF52

But, I get No Symbol Found error. If I load the symbol by adding the library, then it works fine. I want to know if there is a method from which I can upload the kicad symbol from a python script.

Thanks

You are missing a step. First you need to configure KiCad to see the library. This will give the library an internal KiCad name. In your symbol library table you will want to add a line to either the Global Libraries tab if you want all projects to see it, or the Project Specific Libraries tab if you only need it in your current project. You will give the library a nickname (for my example here I’ll call it foobar but you can name yours what ever makes sense), then specify the path that you’ve given User_Libs/MS50SFA_NRF52/MS50SFA_VCE.lib, and you can give it a description if you want.
Then when using the symbol you will want to access it as foobar:MS50SFA_NRF52.

For more details and some further tips, check out these FAQ entries:


1 Like

Project specific libraries for schematic symbols are listed in the “sym-lib-table” file of a project. Generating that file from Python would be easy.

Are you aware of the pdf with a description of (lots of) KiCad’s file formats:

Are you aware of the Skidl project?
It is a Python library with which you can generate a netlist directly from Python, so it skips the whole schematic part.
It does have a lot of overlap with what you do, such as creating symbols and making netlist connections. Maybe your idea to make a schematic from Python can build upon Skidl.

Thank you. I added the sym-lib-table file in the project folder and added the path to my library…
(sym_lib_table
(lib (name MS50SFA_VCE)(type Legacy)(uri ${VCE_SYMBOL_DIR}/MS50SFA_NRF52/MS50SFA_VCE.lib)(options “”)(descr “”))
)
This added the library as a project specific library. It has fixed my issue. Thank you.

1 Like

Yes, I am trying to have a script generate the schematic from a modular script… I added the sym-lib-table file and it has fixed my bug. Thank you.