KiPart
Python package for generating multi-unit schematic symbols for KiCad from a CSV file.
Install / Use
/learn @devbisme/KiPartREADME
KiPart
Generate multi-unit schematic symbols for KiCad from a CSV, text, Excel, or SPD file.
Features
- Generates schematic part libraries for KiCad from CSV or Excel files.
- Converts one or more lists of pins in a file into a library of multi-unit schematic part symbols.
- Each row of the file lists the number, name, type, style, and unit of a pin along with what side of the symbol to place the pin on.
- Has several command-line options for controlling the arrangement and order of the pins.
- Pins with the same name (e.g., GND) can be placed at the same location so they can all be tied to a net with a single connection.
- Also includes
spd2csvfor converting Shorthand Part Description (SPD) files to CSV format which can then be turned into schematic part libraries. - Also includes
kilib2csvfor converting existing schematic part libraries into CSV files suitable for input to KiPart.
Example Use Case
From a user:
I had a very complex library for a microprocessor that I needed to refactor--- I needed to reorder hundreds of pins in a sane human-usable format. I thought I was going to have do it by hand in KiCAD's graphical symbol editor. I tried that, got very frustrated with all the clicking and dragging.
So I then:
- searched and found this tool,
- used
kilib2csvto export my KiCAD lib to CSV, - imported the CSV in a spreadsheet program
- edited the spreadsheet (mainly sorting the pins by function using
the spreadsheet's
sort()function), - exported the spreadsheet back to CSV,
- used
kipartto export back to KiCAD.
Boom! Usable part in minutes.
Installation
Simple enough:
pip install kipart
This will install three command-line utilities:
kipart: The main utility for generating schematic symbols from rows of pin data stored in CSV or Excel files.spd2csv: A utility for converting SPD (Shorthand Part Description) files to CSV format for use with KiPart.kilib2csv: A utility for converting existing KiCad libraries into CSV files. This is useful for converting existing libraries into a format that can be used with KiPart.
Usage
KiPart
KiPart is mainly intended to be used as a script:
usage: kipart [-h] [-o OUTPUT] [-w] [-m] [-1] [-s {row,num,name}] [-r] [--ccw] [--scrunch] [--side {left,right,top,bottom}] [--type TYPE] [--style STYLE] [--push PUSH] [-a ALT_DELIMITER] [-b]
[--bundle-style {none,count,range}] [--hide-pin-num] [-j {left,center,right}] [-v]
[input_files ...]
Convert CSV or Excel files into KiCad symbol libraries
positional arguments:
input_files Input symbol pin data CSV or Excel files (.csv, .xlsx, .xls). If no files are given, reads from stdin.
options:
-h, --help show this help message and exit
-o, --output OUTPUT Output KiCad symbol library file (.kicad_sym)
-w, --overwrite Allow overwriting of an existing symbol library
-m, --merge Merge symbols into an existing library rather than overwriting completely
-1, --one-symbol Ignore blank lines rather than starting a new symbol
-s, --sort {row,num,name}
Sort the part pins by their entry order in the CSV file (row), their pin number (num), or their pin name (name)
-r, --reverse Sort pins in reverse order
--ccw Arrange pins counter-clockwise around the symbol
--scrunch Compress symbol pins on the left/right sides underneath the top/bottom sides
--side {left,right,top,bottom}
Default side for pins without a side specifier
--type TYPE Default type for pins without a type specifier (e.g., input, output, bidirectional, passive)
--style STYLE Default style for pins without a style specifier (e.g., line, inverted, clock)
--push PUSH Position of pin groups on each side (0.0=start, 0.5=centered, 1.0=end)
-a, --alt-delimiter ALT_DELIMITER
Delimiter character for splitting pin names into alternatives
-b, --bundle Bundle identically-named power or ground input pins into single schematic pins
--bundle-style {none,count,range}
When bundling pins, selects what is appended to the net name
--hide-pin-num Hide pin numbers
-j, --justify {left,center,right}
Sets the justification on visible properties
-v, --version show program's version number and exit
The input to kipart is one or more CSV or Excel files.
These contain the following items:
-
The part name or number stands alone in the first column of a row.
-
Part properties are listed on the following rows. Each property begins with a property name followed by a colon and the property value. The standard properties are:
Reference: The reference designator such asU.Value: The part value (often the same as the name).Footprint: The part's package type (e.g., QFP, BGA, etc.).Datasheet: A URL to the part's datasheet.Description: A description of the part.Keywords: Keywords for searching for the part.Filters: The footprint filters for the part.Locked: I have no idea what this does...
You can also list part properties with arbitrary names of your own choosing.
-
After the properties, the next row contains the column headers. The required headers are
PinandName. Optional columns areUnit,Side,Type,Style, andHidden. These can be placed in any order and in any column. -
Immediately after the column headers, each succeeding row contains the following data for one of the part's pins: the pin number, name, unit identifier (if the schematic symbol will have multiple units), pin type and style. Each of these items should be entered in the same column as the corresponding header.
-
Pin numbers can be either numeric (e.g.,
69) if the part is a DIP or QFP, or they can be alphanumeric (e.g.,C10) for BGAs or CSPs. Using a * character instead of a pin number creates non-existent "gap" pins that can be used to visually separate the pins into groups. (This only works when the-s rowsorting option is selected.) -
Pin names can be any combination of letters, numbers and special characters (except a comma). If the pin name contains one or more delimiter characters specified with the
-aoption, then the name will be split at each delimiter and the resulting substrings will be entered as alternate pin functions. -
The unit identifier can be blank or any combination of letters, numbers and special characters (except a comma). A separate unit will be generated in the schematic symbol for each distinct unit identifier.
-
The side column specifies the side of the symbol the pin will be placed on. The allowable values are:
- left - right - top - bottom -
The type column specifies the electrical type of the pin. The allowable values are:
- input, inp, in, clk - output, outp, out - bidirectional, bidir, bi, inout, io, iop - tristate, tri, tri_state, tristate - passive, pass - free - unspecified, un, analog - power_in, pwr_in, pwrin, power, pwr, ground, gnd - power_out, pwr_out, pwrout, pwr_o - open_collector, opencollector, open_coll, opencoll, oc - open_emitter, openemitter, open_emit, openemit, oe - no_connect, noconnect, no_conn, noconn, nc -
The style column specifies the graphic representation of the pin. The allowable pin styles are:
- line, <blank> - inverted, inv, ~, # - clock, clk, rising_clk - inverted_clock, inv_clk, clk_b, clk_n, ~clk, #clk - input_low, inp_low, in_lw, in_b, in_n, ~in, #in - clock_low, clk_low, clk_lw, clk_b, clk_n, ~clk, #clk - output_low, outp_low, out_lw, out_b, out_n, ~out, #out - edge_clock_high - non_logic, nl, analog -
The hidden column specifies whether the pin is invisible. This can be one of 'y', 'yes', 't', 'true', or '1' to make it invisible, anything else makes it visible.
-
-
A blank row ends the list of pins for the part.
-
Multiple parts (each consisting of a name, properties, column header and pin data rows) separated by blank lines are allowed in a single CSV file. Each part will become a separate symbol in the KiCad library.
The -s option specifies the pin order on each side of the symbol:
-s rowplaces the pins in the order they were entered into the file.-s nameplaces the pins in increasing order of their names.-s numplaces the pins in increasing order of their pin numbers and arranged in a counter-clockwise fashion around the symbol starting from the upper-left corner.
The --reverse option reverses the sort order for the pins.
The --ccw option arranges the pins running counter-clockwise
around the symbol starting from the upper-left corner. If this
option is not enabled, the pins on the left/right sides will run from
top to bottom and the pins on the top/bottom sides will run from
left to right.
The --scrunch option will compress a three- or four-sided schematic
symbol by moving the left and right columns of pins closer together so
that their pin labels are shadowed by the pins on the top and bottom
rows.
The --side, --type, and --style options set the default
