skidl.netlist_to_skidl module¶
Convert a KiCad netlist into equivalent hierarchical SKiDL programs.
This module enables the conversion of KiCad netlists to SKiDL Python scripts, preserving the hierarchical structure. The resulting SKiDL scripts can be used to regenerate the circuit or as a starting point for circuit modifications.
- class skidl.netlist_to_skidl.HierarchicalConverter(src)[source]¶
Bases:
object
Converts a KiCad netlist into hierarchical SKiDL Python scripts.
This class analyzes a KiCad netlist and generates equivalent SKiDL scripts that preserve the hierarchical structure of the original schematic.
- analyze_nets()[source]¶
Analyze net usage to determine origins and required connections.
This method examines how nets are used across sheets to determine which sheets need to pass nets to their children, which nets are local, and which are imported.
- assign_components_to_sheets()[source]¶
Assign each component from the netlist to its appropriate sheet.
This method assigns components to their respective sheets based on the sheet path information in the netlist.
- component_to_skidl(comp: object) str [source]¶
Return a SKiDL instantiation string for a component.
This method generates SKiDL code to instantiate a component with all its relevant properties preserved.
- convert(output_dir: str = None)[source]¶
Run the complete conversion and write files if output_dir is provided.
This method performs the full netlist-to-SKiDL conversion process and optionally writes the generated Python files to a directory.
- cull_from_top()[source]¶
Remove top-level sheets that are not needed.
This method simplifies the hierarchy by removing unnecessary empty top-level sheets, making the resulting SKiDL code more concise.
- extract_sheet_info()[source]¶
Populate self.sheets with Sheet objects built from the netlist.
This method examines the netlist to identify all sheets and their hierarchical relationships, creating Sheet objects to represent them.
- find_lowest_common_ancestor(sheet1, sheet2)[source]¶
Return the lowest common ancestor (LCA) of two sheets.
This method finds the sheet that is the closest common parent of two sheets in the schematic hierarchy.
- generate_main_code()[source]¶
Generate the code for the main.py file that creates nets and calls subcircuits.
This method creates the top-level Python script that imports and calls the top-level subcircuit and generates the final netlist.
- Returns:
SKiDL Python code for the main script
- Return type:
- generate_sheet_code(sheet: Sheet) str [source]¶
Generate the SKiDL code for a given sheet.
This method creates a complete SKiDL subcircuit function for a sheet, including component instantiation, connections, and calls to child subcircuits.
- class skidl.netlist_to_skidl.NetSexp(sexp)[source]¶
Bases:
object
This class delivers attributes from a net S-expression.
- class skidl.netlist_to_skidl.NetlistSexp(sexp)[source]¶
Bases:
object
Represents a KiCad netlist.
This class encapsulates the structure of a KiCad netlist, including its parts, nets, and sheets. It provides methods to access and manipulate the netlist data.
- parts¶
List of components in the netlist
- Type:
List
- nets¶
List of electrical nets in the netlist
- Type:
List
- sheets¶
List of hierarchical sheets in the netlist
- Type:
List
- class skidl.netlist_to_skidl.PartSexp(sexp)[source]¶
Bases:
object
This class delivers attributes from a component S-expression.
- class skidl.netlist_to_skidl.PinSexp(sexp)[source]¶
Bases:
object
This class delivers attributes from a pin S-expression.
- class skidl.netlist_to_skidl.PropertySexp(sexp)[source]¶
Bases:
object
This class delivers attributes from a property S-expression.
- class skidl.netlist_to_skidl.Sheet(**attribs)[source]¶
Bases:
object
Represents a hierarchical sheet from a KiCad schematic.
This object stores information about a sheet in the schematic hierarchy, including its components, nets, and relationship to other sheets.
- components¶
Components contained in this sheet
- Type:
List
- class skidl.netlist_to_skidl.SheetSexp(sexp)[source]¶
Bases:
object
This class delivers attributes from a sheet S-expression.
- skidl.netlist_to_skidl.find_common_path_prefix(path1: str, path2: str) str [source]¶
Return the common path prefix of two paths.
This function finds the longest common hierarchical path prefix between two paths.
- Parameters:
- Returns:
The common path prefix including the trailing separator
- Return type:
Examples
>>> find_common_path_prefix("/path/to/sheet1/", "/path/to/sheet2/") "/path/to/"
- skidl.netlist_to_skidl.legalize_name(name: str, is_filename: bool = False) str [source]¶
Return a version of name that is a legal Python identifier.
This function converts arbitrary strings to valid Python identifiers by replacing illegal characters with underscores and handling special cases for names starting with numbers or containing special symbols.
- Parameters:
- Returns:
A legal Python identifier derived from the input name
- Return type:
Examples
>>> legalize_name("1wire") "_1wire" >>> legalize_name("5V+") "_5V_p"
- skidl.netlist_to_skidl.netlist_to_skidl(netlist_src: str, output_dir: str = None)[source]¶
Convert a KiCad netlist to hierarchical SKiDL Python files.
This function creates a HierarchicalConverter and uses it to convert a KiCad netlist into SKiDL Python scripts.
- Parameters:
- Returns:
- If output_dir is None, returns the main sheet code as a string.
Otherwise, returns an empty string after writing files.
- Return type: