Python utilities for converting KiCad schematics (.kicad_sch) to and from JSON/YAML formats. Built for the open-schematics dataset on Hugging Face.
The open-schematics dataset is a collection of open-source KiCad schematics designed for training and fine-tuning AI models on electronic circuit design. Each entry contains:
| Field | Description |
|---|---|
schematic |
Raw KiCad schematic file content (.kicad_sch) |
image |
Rendered schematic image |
components_used |
List of components in the design |
json |
Simplified JSON representation |
yaml |
Simplified YAML representation |
name |
Project name |
description |
Project description |
type |
File type |
pip install kiutils pyyaml datasets| Script | Direction | Description |
|---|---|---|
kicad_to_json.py |
KiCad → JSON | Convert schematic to simplified JSON |
kicad_to_yaml.py |
KiCad → YAML | Convert schematic to simplified YAML |
json_to_kicad.py |
JSON → KiCad | Reconstruct schematic from JSON |
yaml_to_kicad.py |
YAML → KiCad | Reconstruct schematic from YAML |
Load the dataset from Hugging Face:
from datasets import load_dataset
dataset = load_dataset("bshada/open-schematics")
# Access a schematic entry
entry = dataset['train'][0]
print(entry['name']) # Project name
print(entry['description']) # Project description
print(entry['components_used']) # List of components
print(entry['json']) # Simplified JSON format
print(entry['yaml']) # Simplified YAML formatConvert existing KiCad schematics to the simplified format used in the dataset:
# Convert to JSON
python kicad_to_json.py my_project.kicad_sch
# Convert to YAML
python kicad_to_yaml.py my_project.kicad_sch
# Specify output path
python kicad_to_json.py my_project.kicad_sch -o output.json
python kicad_to_yaml.py my_project.kicad_sch -o output.yamlReconstruct KiCad schematics from the simplified format. This is useful for:
- Generating schematics from AI model outputs
- Converting dataset entries back to editable KiCad files
# From JSON (uses kicad-symbols folder by default)
python json_to_kicad.py schematic.json
# From YAML
python yaml_to_kicad.py schematic.yaml
# Specify custom symbols path
python json_to_kicad.py schematic.json -s /path/to/symbols
# Specify output path
python json_to_kicad.py schematic.json -o output.kicad_schThe -s/--symbols flag defaults to kicad-symbols folder in the project directory. You can override it to point to a different location if needed.
from datasets import load_dataset
import json
# Load dataset
dataset = load_dataset("bshada/open-schematics")
entry = dataset['train'][0]
# Save JSON to file
with open('schematic.json', 'w') as f:
f.write(entry['json'])
# Then convert to KiCad format
# python json_to_kicad.py schematic.json -o project.kicad_schThe simplified JSON/YAML format captures essential schematic elements:
libSymbols:
- "Connector:USB_C_Receptacle"
- "Device:R"
- "Device:C"
schematicSymbols:
- libraryNickname: "Device"
entryName: "R"
position: {x: 100, y: 50, angle: 0}
properties:
- {key: "Reference", value: "R1", position: {...}}
- {key: "Value", value: "10k", position: {...}}
junctions:
- position: {x: 100, y: 100, angle: 0}
graphicalItems:
- type: "wire"
points:
- {x: 100, y: 50}
- {x: 100, y: 100}
globalLabels:
- text: "VCC"
shape: "input"
position: {x: 50, y: 25, angle: 0}MIT