I built a Python library for reading and writing KiCAD schematic files. I use it for Circuit-Synth, but figured others might find it useful so I made a separate project for just this part.
GitHub: GitHub - circuit-synth/kicad-sch-api: API for manipulating sexpr in KiCAD schematic editor
PyPI: pip install kicad-sch-api
Why I Built This
I needed programmatic schematic generation for Circuit-Synth and wanted to decouple the core schematic logic into a standalone library. Design goals:
- Simple - Straightforward API, no complexity
- Format-preserving - Output attempts to matche KiCAD exactly
- Standalone - No KiCAD installation required, although you need the KiCAD symbol libraries
What It Does
Reads and writes .kicad_sch files directly (no KiCAD installation needed). Here’s a complete working example:
import kicad_sch_api as ksa
# Create schematic
sch = ksa.create_schematic("Voltage Divider")
# Add resistors
r1 = sch.components.add("Device:R", "R1", "10k", position=(100, 100))
r2 = sch.components.add("Device:R", "R2", "10k", position=(100, 110))
# Wire them together
sch.add_wire(start=(100, 105), end=(100, 108))
# Add labels
sch.add_label("VCC", position=(100, 100))
sch.add_label("VOUT", position=(100, 105))
sch.add_label("GND", position=(100, 115))
# Save
sch.save("voltage_divider.kicad_sch")
Output: A valid .kicad_sch file that opens in KiCAD 9.
You can see working examples here: kicad-sch-api/examples at main · circuit-synth/kicad-sch-api · GitHub
Technical Approach
Format Preservation:
- Parses KiCAD S-expressions
- Output tested against
kicad-clinetlist generation - 70+ tests including byte-for-byte format verification
- Reference schematics created manually in KiCAD, then compared
What Works:
- Components (add, remove, update)
- Wires, labels, junctions, power symbols
- Hierarchical sheets
- Component rotation (0°, 90°, 180°, 270°)
- Multi-unit components
What Doesn’t Work (Yet):
- Graphical elements (arcs, circles, polylines)
- Some advanced KiCAD features
- PCB layout (out of scope - schematics only)
See docs/KNOWN_LIMITATIONS.md for details.
MCP Server
Includes an MCP (Model Context Protocol) server with 15 tools. Works well with Claude Code for automating schematic tasks. Just a programmatic interface - no AI magic.
Use Cases
I use it for Circuit-Synth. Other possible uses:
- Storing circuits as Python code in git (instead of .kicad_sch files)
- Parametric circuit generation
- Circuit templates and automation
Feedback Welcome
Curious what people think:
- API design - Intuitive enough?
- Actual use cases - Would you use this? For what?
- Missing features - What would make it more useful?
Happy to answer questions, thanks for reading.
Shane