Skip to main content
The Python (SWIG) API is being deprecated in favor of the modern IPC API. For new integrations, we strongly recommend using the IPC Protocol which provides better performance, language-agnostic access, improved stability, and future-proof compatibility. The Python API is maintained for backward compatibility but may not receive new features.
KiCad provides a comprehensive Python API for automating PCB design tasks, creating action plugins, and generating footprint wizards. The API is accessible through the pcbnew module.

Getting Started

Import the pcbnew module to access the Python API:

Core Functions

Board Management

LoadBoard(filename, format=None)

Loads a board from file. Parameters:
  • filename (str): Path to the board file
  • format (PCB_IO_MGR.PCB_FILE_T, optional): File format specifier
Returns: BOARD object or None if loading fails

GetBoard()

Returns the currently active board in the PCB editor. Returns: BOARD object or None

CreateEmptyBoard()

Constructs a default BOARD with a temporary project. Returns: New BOARD object

NewBoard(filename)

Creates a new board and project with the given filename (will overwrite existing files). Parameters:
  • filename (str): Full path for the new board file
Returns: BOARD object or None

SaveBoard(filename, board, skipSettings=False)

Saves a board to file in KiCad native format. Parameters:
  • filename (str): Target file path
  • board (BOARD): Board object to save
  • skipSettings (bool): If True, only save the board file (loses project settings)
Returns: True if successful, False otherwise

Drawing and Plotting

PLOT_CONTROLLER(board)

Creates a plot controller for generating output files. Parameters:
  • board (BOARD): Board to plot

Plot Options Methods

  • SetOutputDirectory(dir) - Set output directory for plot files
  • SetPlotFrameRef(bool) - Enable/disable frame reference plotting
  • SetSketchPadLineWidth(width) - Set pad line width for sketch mode
  • SetAutoScale(bool) - Enable/disable auto-scaling
  • SetScale(scale) - Set plot scale (typically 1)
  • SetMirror(bool) - Enable/disable mirroring
  • SetUseGerberAttributes(bool) - Include Gerber X2 attributes
  • SetIncludeGerberNetlistInfo(bool) - Include netlist information
  • SetCreateGerberJobFile(bool) - Generate .gbrjob file
  • SetUseAuxOrigin(bool) - Use auxiliary origin
  • SetPlotReference(bool) - Plot component references
  • SetPlotValue(bool) - Plot component values
  • SetSubtractMaskFromSilk(bool) - Remove soldermask from silkscreen
  • SetDrillMarksType(type) - Set drill mark style

Drill File Generation

EXCELLON_WRITER(board)

Creates a drill file writer.

Library Management

GetFootprintLibraries()

Returns all configured footprint library nicknames. Returns: wxArrayString of library nicknames

GetFootprints(nickname)

Returns all footprint names in a library. Parameters:
  • nickname (str): Library nickname
Returns: wxArrayString of footprint names

Utility Functions

Unit Conversion

Refresh()

Updates the board display after modifications.

UpdateUserInterface()

Updates layer manager and widgets from board setup.

GetUserUnits()

Returns the current user unit setting. Returns: 0 for inches, 1 for mm, -1 if frame not set

GetCurrentSelection()

Returns currently selected board items. Returns: deque of BOARD_ITEM objects

FocusOnItem(item, layer=UNDEFINED_LAYER)

Focuses the view on a specific board item. Parameters:
  • item (BOARD_ITEM): Target item
  • layer (PCB_LAYER_ID): Layer ID (optional)

DRC and Validation

WriteDRCReport(board, filename, units, reportAllTrackErrors)

Runs DRC check and writes results to a report file. Parameters:
  • board (BOARD): Board to check
  • filename (str): Output report path
  • units (EDA_UNITS): Units for report
  • reportAllTrackErrors (bool): Report all errors or just first per track
Returns: True if successful

BOARD Class

The BOARD class represents a PCB design.

Common Methods

Layer Constants

Common layer identifiers:

Plot Format Constants

Complete Example: Board Export

See Also