ScriptedPCB
Scripting PCB design with Python, via pcbnew or KiCad's IPC API
Tutorials for automating KiCad with Python: footprints, traces, vias, copper zones, DRC, and fabrication export — with pcbnew and KiCad 10/11's IPC API.
Available tutorials
Installation & build(9)
Enabling KiCad's IPC API and checking that Python connects
Tick “Enable KiCad API”, install kicad-python and test the connection in 6 lines. The “Connection refused” error explained, tested on KiCad 10.
Headless KiCad: Python scripts and kicad-cli without the GUI
Edit a board, run DRC and export Gerber and drill files without opening KiCad: headless pcbnew, kicad-cli, and exit codes for CI pipelines.
Migrating your pcbnew scripts to the IPC API before KiCad 11
pcbnew is being removed in KiCad 11: a pcbnew → kipy mapping table, the key differences, and a method to port your KiCad Python scripts.
Fix “ModuleNotFoundError: No module named 'pcbnew'” in KiCad Python
Why import pcbnew fails outside KiCad, and 4 fixes tested on KiCad 10: bundled Python, KiCad Command Prompt, venv, IPC API.
Creating a new net by script and assigning it with KiCad's Python API
Create a net that doesn't exist yet on the board and assign it to a via or a pad — with the tested trap that silently drops it.
Rotating a position around an arbitrary center with KiCad's Python API
Compute a point's new position after rotating around any center — the base building block for array or panel placement, with pcbnew or the IPC API.
Resolving a layer name to an ID by script with pcbnew's Python API
Convert a layer name ("F.Cu", "B.SilkS"...) into a numeric ID by script, and back again, with pcbnew or KiCad's IPC API — and the pitfalls on both sides.
Loading a board and inventorying it in one pass with pcbnew's Python API
Load a .kicad_pcb file and list footprints, zones, tracks, vias, text, and nets in a single pass, by script — with pcbnew or KiCad's IPC API.
Installing KiCad and using its Python API (GUI, console, headless)
Set up KiCad's Python API: run scripts in the console or headless, fix “No module named 'pcbnew'”, and compare pcbnew with the IPC API.
Footprints(6)
Placing components on a circle (LED ring) with KiCad's Python API
Place N footprints on a perfect circle and orient them outwards by script — a 24-LED WS2812B ring, with pcbnew or KiCad's IPC API.
Giving a pad an orientation independent of its footprint with KiCad's Python API
Rotate a single pad without touching the rest of the footprint — and the tested trap that silently loses that setting on one of KiCad's two APIs.
Duplicating an existing footprint with pcbnew's Python API
Clone an already-placed footprint instead of recreating one from scratch, to quickly reproduce a component with its properties — with pcbnew or KiCad's IPC API.
Flipping a footprint to the back layer with pcbnew's Python API
Move a footprint from the front to the back layer of the PCB by script, for a component mounted on B.Cu — with pcbnew or KiCad's IPC API.
Placing a grid of footprints with pcbnew's Python API
Position several identical footprints in a grid by script — useful for an LED panel or a row of connectors — with pcbnew or KiCad's IPC API.
Positioning a footprint with pcbnew's Python API
Learn how to position and rotate a footprint on a PCB by scripting pcbnew's Python API directly, without going through the GUI.
Traces & routing(3)
Adding a layer-change via in the middle of a route with pcbnew's Python API
Move a trace from the front to the back layer through a via placed mid-route, by script — with pcbnew or KiCad's IPC API.
Routing a right-angle bent trace with pcbnew's Python API
Create a trace with a right-angle bend between two unaligned points, by script — with pcbnew or KiCad's IPC API.
Routing a trace with pcbnew's Python API
Create a copper trace between two points, with a defined width, by script — with pcbnew or KiCad's IPC API.
Vias(5)
Via stitching: covering a ground plane with vias using KiCad's Python API
Place hundreds of GND vias on a ground plane by script while avoiding the mounting holes: pitch, clearance, with pcbnew or the IPC API.
Auditing and counting a board's vias with pcbnew's Python API
List and count a board's existing vias by net, to spot an excess of vias or check a fabrication constraint — with pcbnew or KiCad's IPC API.
Creating a blind or buried via with pcbnew's Python API
Turn a regular through via into a blind or buried via, restricted to certain inner layers, by script — with pcbnew or KiCad's IPC API.
Creating a stitching-via grid with pcbnew's Python API
Generate a full grid of ground-connected stitching vias by script, instead of one via at a time — with pcbnew or KiCad's IPC API.
Creating a via with pcbnew's Python API
Add, position, and size a through-hole via on a PCB by scripting it, with pcbnew or KiCad's IPC API.
Copper zones(5)
Duplicating and repositioning an existing copper zone with KiCad's Python API
Clone an already-placed copper zone, move it, and rotate it around an arbitrary center without redrawing the outline — with pcbnew or KiCad's IPC API.
Creating a multi-layer copper zone with pcbnew's Python API
Apply the same copper zone to several layers at once with an LSET, instead of duplicating the zone layer by layer — with pcbnew or KiCad's IPC API.
Setting a copper zone's thermal relief with pcbnew's Python API
Configure the thermal relief around pads connected to a copper zone, by script — with pcbnew or KiCad's IPC API.
Creating a keepout (keep-out) zone with pcbnew's Python API
Create a keep out zone by script: a rule area where no track, via or copper fill can go — around a connector or an antenna — with pcbnew or the IPC API.
Creating a copper zone (ground plane) with pcbnew's Python API
Generate a copper zone connected to a net and trigger its fill by script, with pcbnew or KiCad's IPC API.