kicad-sch-api 0.1.7__py3-none-any.whl → 0.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kicad_sch_api/__init__.py +6 -2
- kicad_sch_api/cli.py +119 -272
- kicad_sch_api/core/component_bounds.py +477 -0
- kicad_sch_api/core/components.py +22 -10
- kicad_sch_api/core/config.py +127 -0
- kicad_sch_api/core/formatter.py +183 -23
- kicad_sch_api/core/geometry.py +111 -0
- kicad_sch_api/core/ic_manager.py +43 -37
- kicad_sch_api/core/junctions.py +17 -22
- kicad_sch_api/core/manhattan_routing.py +430 -0
- kicad_sch_api/core/parser.py +495 -196
- kicad_sch_api/core/pin_utils.py +149 -0
- kicad_sch_api/core/schematic.py +630 -207
- kicad_sch_api/core/simple_manhattan.py +228 -0
- kicad_sch_api/core/types.py +9 -4
- kicad_sch_api/core/wire_routing.py +380 -0
- kicad_sch_api/core/wires.py +29 -25
- kicad_sch_api/discovery/__init__.py +1 -1
- kicad_sch_api/discovery/search_index.py +142 -107
- kicad_sch_api/library/cache.py +70 -62
- kicad_sch_api-0.2.1.dist-info/METADATA +483 -0
- kicad_sch_api-0.2.1.dist-info/RECORD +31 -0
- {kicad_sch_api-0.1.7.dist-info → kicad_sch_api-0.2.1.dist-info}/entry_points.txt +0 -1
- kicad_sch_api/mcp/__init__.py +0 -7
- kicad_sch_api/mcp/server.py +0 -1511
- kicad_sch_api-0.1.7.dist-info/METADATA +0 -322
- kicad_sch_api-0.1.7.dist-info/RECORD +0 -26
- {kicad_sch_api-0.1.7.dist-info → kicad_sch_api-0.2.1.dist-info}/WHEEL +0 -0
- {kicad_sch_api-0.1.7.dist-info → kicad_sch_api-0.2.1.dist-info}/licenses/LICENSE +0 -0
- {kicad_sch_api-0.1.7.dist-info → kicad_sch_api-0.2.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kicad-sch-api
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: Professional KiCAD schematic manipulation library with exact format preservation
|
|
5
|
+
Author-email: Circuit-Synth <shane@circuit-synth.com>
|
|
6
|
+
Maintainer-email: Circuit-Synth <shane@circuit-synth.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/circuit-synth/kicad-sch-api
|
|
9
|
+
Project-URL: Documentation, https://circuit-synth.github.io/kicad-sch-api/
|
|
10
|
+
Project-URL: Repository, https://github.com/circuit-synth/kicad-sch-api.git
|
|
11
|
+
Project-URL: Bug Reports, https://github.com/circuit-synth/kicad-sch-api/issues
|
|
12
|
+
Project-URL: Changelog, https://github.com/circuit-synth/kicad-sch-api/blob/main/CHANGELOG.md
|
|
13
|
+
Keywords: kicad,schematic,eda,electronics,circuit-design,ai,automation,pcb
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Operating System :: OS Independent
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: sexpdata>=0.0.3
|
|
29
|
+
Requires-Dist: typing-extensions>=4.0.0; python_version < "3.11"
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
33
|
+
Requires-Dist: pytest-xdist>=3.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: black>=22.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: isort>=5.0.0; extra == "dev"
|
|
36
|
+
Requires-Dist: flake8>=4.0.0; extra == "dev"
|
|
37
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
38
|
+
Requires-Dist: pre-commit>=3.0.0; extra == "dev"
|
|
39
|
+
Provides-Extra: docs
|
|
40
|
+
Requires-Dist: sphinx>=5.0.0; extra == "docs"
|
|
41
|
+
Requires-Dist: sphinx-rtd-theme>=1.0.0; extra == "docs"
|
|
42
|
+
Requires-Dist: myst-parser>=0.18.0; extra == "docs"
|
|
43
|
+
Dynamic: license-file
|
|
44
|
+
|
|
45
|
+
# KiCAD Schematic API
|
|
46
|
+
|
|
47
|
+
**Professional Python library for KiCAD schematic file manipulation with exact format preservation**
|
|
48
|
+
|
|
49
|
+
## Overview
|
|
50
|
+
|
|
51
|
+
Create and manipulate KiCAD schematic files programmatically with guaranteed exact format preservation. This library serves as the foundation for EDA automation tools and AI agents that need reliable, professional-grade schematic manipulation capabilities.
|
|
52
|
+
|
|
53
|
+
## 🎯 Core Features
|
|
54
|
+
|
|
55
|
+
- **📋 Exact Format Preservation**: Byte-perfect KiCAD output that matches native formatting
|
|
56
|
+
- **🏗️ Professional Component Management**: Object-oriented collections with search and validation
|
|
57
|
+
- **⚡ High Performance**: Optimized for large schematics with intelligent caching
|
|
58
|
+
- **🔍 Real KiCAD Library Integration**: Access to actual KiCAD symbol libraries and validation
|
|
59
|
+
- **📐 Component Bounding Boxes**: Precise component boundary calculation and visualization
|
|
60
|
+
- **🎨 Colored Rectangle Graphics**: KiCAD-compatible rectangles with all stroke types and colors
|
|
61
|
+
- **🛣️ Manhattan Routing**: Intelligent wire routing with obstacle avoidance
|
|
62
|
+
- **🤖 AI Agent Ready**: MCP server for seamless integration with AI development tools
|
|
63
|
+
- **📚 Hierarchical Design**: Complete support for multi-sheet schematic projects
|
|
64
|
+
|
|
65
|
+
## 🚀 Quick Start
|
|
66
|
+
|
|
67
|
+
### Installation
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# Install from PyPI
|
|
71
|
+
pip install kicad-sch-api
|
|
72
|
+
|
|
73
|
+
# Or install from source
|
|
74
|
+
git clone https://github.com/circuit-synth/kicad-sch-api.git
|
|
75
|
+
cd kicad-sch-api/python
|
|
76
|
+
uv pip install -e .
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Basic Usage
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
import kicad_sch_api as ksa
|
|
83
|
+
|
|
84
|
+
# Create a new schematic
|
|
85
|
+
sch = ksa.create_schematic("My Circuit")
|
|
86
|
+
|
|
87
|
+
# Add components with proper validation
|
|
88
|
+
resistor = sch.components.add(
|
|
89
|
+
lib_id="Device:R",
|
|
90
|
+
reference="R1",
|
|
91
|
+
value="10k",
|
|
92
|
+
position=(100.0, 100.0),
|
|
93
|
+
footprint="Resistor_SMD:R_0603_1608Metric",
|
|
94
|
+
datasheet="~",
|
|
95
|
+
description="Resistor"
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
capacitor = sch.components.add(
|
|
99
|
+
lib_id="Device:C",
|
|
100
|
+
reference="C1",
|
|
101
|
+
value="100nF",
|
|
102
|
+
position=(150.0, 100.0),
|
|
103
|
+
footprint="Capacitor_SMD:C_0603_1608Metric"
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
# Add wires for connectivity
|
|
107
|
+
sch.wires.add(start=(100, 110), end=(150, 110))
|
|
108
|
+
|
|
109
|
+
# Pin-to-pin wiring (NEW in v0.3.1)
|
|
110
|
+
wire_uuid = sch.add_wire_between_pins("R1", "2", "C1", "1") # Connect R1 pin 2 to C1 pin 1
|
|
111
|
+
external_wire = sch.add_wire_to_pin((50, 100), "R1", "1") # Connect external point to R1 pin 1
|
|
112
|
+
|
|
113
|
+
# Add labels for nets
|
|
114
|
+
sch.add_label("VCC", position=(125, 110))
|
|
115
|
+
|
|
116
|
+
# Save with exact format preservation
|
|
117
|
+
sch.save("my_circuit.kicad_sch")
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Hierarchical Design
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
# Create main schematic with hierarchical sheet
|
|
124
|
+
main_sch = ksa.create_schematic("Main Board")
|
|
125
|
+
|
|
126
|
+
# Add hierarchical sheet
|
|
127
|
+
power_sheet = main_sch.add_hierarchical_sheet(
|
|
128
|
+
name="Power Supply",
|
|
129
|
+
filename="power.kicad_sch",
|
|
130
|
+
position=(100, 100),
|
|
131
|
+
size=(80, 60)
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
# Add sheet pins for connectivity
|
|
135
|
+
power_sheet.add_pin("VIN", pin_type="input", position=(0, 10))
|
|
136
|
+
power_sheet.add_pin("VOUT", pin_type="output", position=(80, 10))
|
|
137
|
+
|
|
138
|
+
# Create the sub-schematic
|
|
139
|
+
power_sch = ksa.create_schematic("Power Supply")
|
|
140
|
+
power_sch.add_hierarchical_label("VIN", label_type="input", position=(50, 25))
|
|
141
|
+
power_sch.add_hierarchical_label("VOUT", label_type="output", position=(150, 25))
|
|
142
|
+
|
|
143
|
+
# Save both schematics
|
|
144
|
+
main_sch.save("main.kicad_sch")
|
|
145
|
+
power_sch.save("power.kicad_sch")
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## 🔧 Advanced Features
|
|
149
|
+
|
|
150
|
+
### Component Bounding Boxes and Colored Graphics (NEW in v0.3.1)
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
from kicad_sch_api.core.component_bounds import get_component_bounding_box
|
|
154
|
+
|
|
155
|
+
# Add components
|
|
156
|
+
resistor = sch.components.add("Device:R", "R1", "10k", (100, 100))
|
|
157
|
+
opamp = sch.components.add("Amplifier_Operational:LM358", "U1", "LM358", (150, 100))
|
|
158
|
+
|
|
159
|
+
# Get component bounding boxes
|
|
160
|
+
bbox_body = get_component_bounding_box(resistor, include_properties=False)
|
|
161
|
+
bbox_full = get_component_bounding_box(resistor, include_properties=True)
|
|
162
|
+
|
|
163
|
+
# Draw colored bounding box rectangles
|
|
164
|
+
sch.draw_bounding_box(bbox_body, stroke_width=0.5, stroke_color="blue", stroke_type="solid")
|
|
165
|
+
sch.draw_bounding_box(bbox_full, stroke_width=0.3, stroke_color="red", stroke_type="dash")
|
|
166
|
+
|
|
167
|
+
# Draw bounding boxes for all components at once
|
|
168
|
+
bbox_uuids = sch.draw_component_bounding_boxes(
|
|
169
|
+
include_properties=True,
|
|
170
|
+
stroke_width=0.4,
|
|
171
|
+
stroke_color="green",
|
|
172
|
+
stroke_type="dot"
|
|
173
|
+
)
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Manhattan Routing with Obstacle Avoidance (NEW in v0.3.1)
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
from kicad_sch_api.core.manhattan_routing import ManhattanRouter
|
|
180
|
+
from kicad_sch_api.core.types import Point
|
|
181
|
+
|
|
182
|
+
# Create router
|
|
183
|
+
router = ManhattanRouter()
|
|
184
|
+
|
|
185
|
+
# Add components that act as obstacles
|
|
186
|
+
r1 = sch.components.add("Device:R", "R1", "1k", (50, 50))
|
|
187
|
+
r2 = sch.components.add("Device:R", "R2", "2k", (150, 150))
|
|
188
|
+
obstacle = sch.components.add("Device:C", "C1", "100nF", (100, 100))
|
|
189
|
+
|
|
190
|
+
# Get obstacle bounding boxes
|
|
191
|
+
obstacle_bbox = get_component_bounding_box(obstacle, include_properties=False)
|
|
192
|
+
|
|
193
|
+
# Route around obstacles
|
|
194
|
+
start_point = Point(r1.position.x, r1.position.y)
|
|
195
|
+
end_point = Point(r2.position.x, r2.position.y)
|
|
196
|
+
path = router.route_between_points(start_point, end_point, [obstacle_bbox], clearance=2.0)
|
|
197
|
+
|
|
198
|
+
# Add wires along the path
|
|
199
|
+
for i in range(len(path) - 1):
|
|
200
|
+
sch.wires.add(path[i], path[i + 1])
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Pin-to-Pin Wiring
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
# Connect component pins directly - automatically calculates pin positions
|
|
207
|
+
wire_uuid = sch.add_wire_between_pins("R1", "2", "R2", "1") # R1 pin 2 to R2 pin 1
|
|
208
|
+
|
|
209
|
+
# Connect arbitrary point to component pin
|
|
210
|
+
external_wire = sch.add_wire_to_pin((75, 125), "R1", "1") # External point to R1 pin 1
|
|
211
|
+
tuple_wire = sch.add_wire_to_pin(Point(100, 150), "C1", "2") # Using Point object
|
|
212
|
+
|
|
213
|
+
# Get component pin positions for advanced operations
|
|
214
|
+
pin_position = sch.get_component_pin_position("R1", "1")
|
|
215
|
+
if pin_position:
|
|
216
|
+
print(f"R1 pin 1 is at ({pin_position.x:.2f}, {pin_position.y:.2f})")
|
|
217
|
+
|
|
218
|
+
# Error handling - returns None for invalid components/pins
|
|
219
|
+
invalid_wire = sch.add_wire_between_pins("R999", "1", "R1", "1") # Returns None
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Component Bounding Box Visualization (NEW in v0.3.1)
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
from kicad_sch_api.core.component_bounds import get_component_bounding_box
|
|
226
|
+
|
|
227
|
+
# Get component bounding box (body only)
|
|
228
|
+
resistor = sch.components.get("R1")
|
|
229
|
+
bbox = get_component_bounding_box(resistor, include_properties=False)
|
|
230
|
+
print(f"R1 body size: {bbox.width:.2f}×{bbox.height:.2f}mm")
|
|
231
|
+
|
|
232
|
+
# Get bounding box including properties (reference, value, etc.)
|
|
233
|
+
bbox_with_props = get_component_bounding_box(resistor, include_properties=True)
|
|
234
|
+
print(f"R1 with labels: {bbox_with_props.width:.2f}×{bbox_with_props.height:.2f}mm")
|
|
235
|
+
|
|
236
|
+
# Draw bounding box as rectangle graphics (for visualization/debugging)
|
|
237
|
+
rect_uuid = sch.draw_bounding_box(bbox)
|
|
238
|
+
print(f"Drew bounding box rectangle: {rect_uuid}")
|
|
239
|
+
|
|
240
|
+
# Draw bounding boxes for all components
|
|
241
|
+
bbox_uuids = sch.draw_component_bounding_boxes(
|
|
242
|
+
include_properties=False # True to include reference/value labels
|
|
243
|
+
)
|
|
244
|
+
print(f"Drew {len(bbox_uuids)} component bounding boxes")
|
|
245
|
+
|
|
246
|
+
# Expand bounding box for clearance analysis
|
|
247
|
+
expanded_bbox = bbox.expand(2.54) # Expand by 2.54mm (0.1 inch)
|
|
248
|
+
clearance_rect = sch.draw_bounding_box(expanded_bbox)
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Manhattan Routing with Obstacle Avoidance (NEW in v0.3.1)
|
|
252
|
+
|
|
253
|
+
```python
|
|
254
|
+
# Automatic Manhattan routing between component pins
|
|
255
|
+
wire_segments = sch.auto_route_pins(
|
|
256
|
+
"R1", "2", # From component R1, pin 2
|
|
257
|
+
"R2", "1", # To component R2, pin 1
|
|
258
|
+
routing_mode="manhattan", # Manhattan (L-shaped) routing
|
|
259
|
+
avoid_components=True # Avoid component bounding boxes
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
# Direct routing (straight line)
|
|
263
|
+
direct_wire = sch.auto_route_pins("C1", "1", "C2", "2", routing_mode="direct")
|
|
264
|
+
|
|
265
|
+
# Manual obstacle avoidance using bounding boxes
|
|
266
|
+
bbox_r1 = get_component_bounding_box(sch.components.get("R1"))
|
|
267
|
+
bbox_r2 = get_component_bounding_box(sch.components.get("R2"))
|
|
268
|
+
|
|
269
|
+
# Check if routing path intersects with component
|
|
270
|
+
def path_clear(start, end, obstacles):
|
|
271
|
+
# Custom collision detection logic
|
|
272
|
+
return not any(bbox.intersects_line(start, end) for bbox in obstacles)
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Component Search and Management
|
|
276
|
+
|
|
277
|
+
```python
|
|
278
|
+
# Search for components
|
|
279
|
+
resistors = sch.components.find(lib_id_pattern='Device:R*')
|
|
280
|
+
power_components = sch.components.filter(reference_pattern=r'U[0-9]+')
|
|
281
|
+
|
|
282
|
+
# Bulk updates
|
|
283
|
+
sch.components.bulk_update(
|
|
284
|
+
criteria={'lib_id': 'Device:R'},
|
|
285
|
+
updates={'properties': {'Tolerance': '1%'}}
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
# Component validation
|
|
289
|
+
validation_result = sch.components.validate_component(
|
|
290
|
+
'Device:R',
|
|
291
|
+
'Resistor_SMD:R_0603_1608Metric'
|
|
292
|
+
)
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Component and Element Removal
|
|
296
|
+
|
|
297
|
+
```python
|
|
298
|
+
# Remove components by reference
|
|
299
|
+
removed = sch.components.remove("R1") # Returns True if removed
|
|
300
|
+
|
|
301
|
+
# Remove wires, labels, and other elements
|
|
302
|
+
sch.remove_wire(wire_uuid)
|
|
303
|
+
sch.remove_label(label_uuid)
|
|
304
|
+
sch.remove_hierarchical_label(label_uuid)
|
|
305
|
+
|
|
306
|
+
# Remove from collections
|
|
307
|
+
sch.wires.remove(wire_uuid)
|
|
308
|
+
sch.junctions.remove(junction_uuid)
|
|
309
|
+
|
|
310
|
+
# lib_symbols are automatically cleaned up when last component of type is removed
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### Configuration and Customization
|
|
314
|
+
|
|
315
|
+
```python
|
|
316
|
+
import kicad_sch_api as ksa
|
|
317
|
+
|
|
318
|
+
# Access global configuration
|
|
319
|
+
config = ksa.config
|
|
320
|
+
|
|
321
|
+
# Customize property positioning
|
|
322
|
+
config.properties.reference_y = -2.0 # Move reference labels higher
|
|
323
|
+
config.properties.value_y = 2.0 # Move value labels lower
|
|
324
|
+
|
|
325
|
+
# Customize tolerances and precision
|
|
326
|
+
config.tolerance.position_tolerance = 0.05 # Tighter position matching
|
|
327
|
+
config.tolerance.wire_segment_min = 0.005 # Different wire segment threshold
|
|
328
|
+
|
|
329
|
+
# Customize defaults
|
|
330
|
+
config.defaults.project_name = "my_company_project"
|
|
331
|
+
config.defaults.stroke_width = 0.1
|
|
332
|
+
|
|
333
|
+
# Grid and spacing customization
|
|
334
|
+
config.grid.unit_spacing = 10.0 # Tighter multi-unit IC spacing
|
|
335
|
+
config.grid.component_spacing = 5.0 # Closer component placement
|
|
336
|
+
|
|
337
|
+
# Sheet settings for hierarchical designs
|
|
338
|
+
config.sheet.name_offset_y = -1.0 # Different sheet label position
|
|
339
|
+
config.sheet.file_offset_y = 1.0 # Different file label position
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### KiCAD Integration
|
|
343
|
+
|
|
344
|
+
```python
|
|
345
|
+
# Run electrical rules check using KiCAD CLI
|
|
346
|
+
erc_result = sch.run_erc_check()
|
|
347
|
+
print(f"ERC Status: {erc_result.status}")
|
|
348
|
+
for violation in erc_result.violations:
|
|
349
|
+
print(f"- {violation.type}: {violation.message}")
|
|
350
|
+
|
|
351
|
+
# Generate netlist for connectivity analysis
|
|
352
|
+
netlist = sch.generate_netlist()
|
|
353
|
+
net_info = netlist.analyze_net("VCC")
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
## 🤖 AI Agent Integration
|
|
357
|
+
|
|
358
|
+
This library serves as the foundation for AI agent integration. For Claude Code or other AI agents, use the **[mcp-kicad-sch-api](https://github.com/circuit-synth/mcp-kicad-sch-api)** MCP server (included as a submodule in `submodules/mcp-kicad-sch-api/`).
|
|
359
|
+
|
|
360
|
+
## 🏗️ Architecture
|
|
361
|
+
|
|
362
|
+
### Library Structure
|
|
363
|
+
|
|
364
|
+
```
|
|
365
|
+
kicad-sch-api/
|
|
366
|
+
├── kicad_sch_api/ # Core Python library
|
|
367
|
+
│ ├── core/ # Core schematic manipulation
|
|
368
|
+
│ ├── library/ # KiCAD library integration
|
|
369
|
+
│ ├── discovery/ # Component search and indexing
|
|
370
|
+
│ └── utils/ # Validation and utilities
|
|
371
|
+
├── submodules/ # Related projects as submodules
|
|
372
|
+
│ └── mcp-kicad-sch-api/ # MCP server for AI agents
|
|
373
|
+
├── tests/ # Comprehensive test suite
|
|
374
|
+
└── examples/ # Usage examples and tutorials
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
### Design Principles
|
|
378
|
+
|
|
379
|
+
- **Building Block First**: Designed to be the foundation for other tools
|
|
380
|
+
- **Exact Format Preservation**: Guaranteed byte-perfect KiCAD output
|
|
381
|
+
- **Professional Quality**: Comprehensive error handling and validation
|
|
382
|
+
- **MCP Foundation**: Designed as a stable foundation for MCP servers and AI agents
|
|
383
|
+
- **Performance Optimized**: Fast operations on large schematics
|
|
384
|
+
|
|
385
|
+
## 🧪 Testing & Quality
|
|
386
|
+
|
|
387
|
+
```bash
|
|
388
|
+
# Run all tests (29 tests covering all functionality)
|
|
389
|
+
uv run pytest tests/ -v
|
|
390
|
+
|
|
391
|
+
# Format preservation tests (critical - exact KiCAD output matching)
|
|
392
|
+
uv run pytest tests/reference_tests/ -v
|
|
393
|
+
|
|
394
|
+
# Component removal tests (comprehensive removal functionality)
|
|
395
|
+
uv run pytest tests/test_*_removal.py -v
|
|
396
|
+
|
|
397
|
+
# Code quality checks
|
|
398
|
+
uv run black kicad_sch_api/ tests/
|
|
399
|
+
uv run mypy kicad_sch_api/
|
|
400
|
+
uv run flake8 kicad_sch_api/ tests/
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
### Test Categories
|
|
404
|
+
|
|
405
|
+
- **Format Preservation**: Byte-for-byte compatibility with KiCAD native files
|
|
406
|
+
- **Component Management**: Creation, modification, and removal of components
|
|
407
|
+
- **Element Operations**: Wires, labels, junctions, hierarchical sheets
|
|
408
|
+
- **Configuration**: Customizable settings and behavior
|
|
409
|
+
- **Performance**: Large schematic handling and optimization
|
|
410
|
+
- **Integration**: Real KiCAD library compatibility
|
|
411
|
+
|
|
412
|
+
## 🆚 Why This Library?
|
|
413
|
+
|
|
414
|
+
### vs. Direct KiCAD File Editing
|
|
415
|
+
- **Professional API**: High-level operations vs low-level S-expression manipulation
|
|
416
|
+
- **Guaranteed Format**: Byte-perfect output vs manual formatting
|
|
417
|
+
- **Validation**: Real KiCAD library integration and component validation
|
|
418
|
+
- **Performance**: Optimized collections vs manual iteration
|
|
419
|
+
|
|
420
|
+
### vs. Other Python KiCAD Libraries
|
|
421
|
+
- **Format Preservation**: Exact KiCAD compatibility vs approximate output
|
|
422
|
+
- **Modern Design**: Object-oriented collections vs legacy patterns
|
|
423
|
+
- **AI Integration**: Purpose-built MCP server vs no agent support
|
|
424
|
+
- **Professional Focus**: Production-ready vs exploration tools
|
|
425
|
+
|
|
426
|
+
## 🔗 Ecosystem
|
|
427
|
+
|
|
428
|
+
This library serves as the foundation for specialized tools and MCP servers:
|
|
429
|
+
|
|
430
|
+
```python
|
|
431
|
+
# Foundation library
|
|
432
|
+
import kicad_sch_api as ksa
|
|
433
|
+
|
|
434
|
+
# MCP servers and specialized libraries built on this foundation:
|
|
435
|
+
# - mcp-kicad-sch-api: Full MCP server for AI agents
|
|
436
|
+
# - kicad_sourcing_tools: Component sourcing extensions
|
|
437
|
+
# - kicad_placement_optimizer: Layout optimization
|
|
438
|
+
# - kicad_dfm_checker: Manufacturing validation
|
|
439
|
+
|
|
440
|
+
# Foundation provides reliable schematic manipulation
|
|
441
|
+
sch = ksa.load_schematic('project.kicad_sch')
|
|
442
|
+
|
|
443
|
+
# All extensions use the same stable API
|
|
444
|
+
# mcp_server.use_schematic(sch) # MCP server integration
|
|
445
|
+
# sourcing.update_sourcing(sch) # Component sourcing
|
|
446
|
+
# placement.optimize_layout(sch) # Layout optimization
|
|
447
|
+
|
|
448
|
+
# Foundation ensures exact format preservation
|
|
449
|
+
sch.save() # Guaranteed exact KiCAD format
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
## 📖 Documentation
|
|
453
|
+
|
|
454
|
+
- **[API Reference](docs/api.md)**: Complete API documentation
|
|
455
|
+
- **[Examples](examples/)**: Code examples and tutorials
|
|
456
|
+
- **[MCP Integration](docs/mcp.md)**: AI agent integration guide
|
|
457
|
+
- **[Development](docs/development.md)**: Contributing and development setup
|
|
458
|
+
|
|
459
|
+
## 🤝 Contributing
|
|
460
|
+
|
|
461
|
+
We welcome contributions! Key areas:
|
|
462
|
+
|
|
463
|
+
- KiCAD library integration and component validation
|
|
464
|
+
- Performance optimizations for large schematics
|
|
465
|
+
- Additional MCP tools for AI agents
|
|
466
|
+
- Test coverage and format preservation validation
|
|
467
|
+
|
|
468
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
469
|
+
|
|
470
|
+
## 📄 License
|
|
471
|
+
|
|
472
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
473
|
+
|
|
474
|
+
## 🔗 Related Projects
|
|
475
|
+
|
|
476
|
+
- **[mcp-kicad-sch-api](https://github.com/circuit-synth/mcp-kicad-sch-api)**: MCP server for AI agents built on this library (included as submodule)
|
|
477
|
+
- **[circuit-synth](https://github.com/circuit-synth/circuit-synth)**: High-level circuit design automation using this library
|
|
478
|
+
- **[Claude Code](https://claude.ai/code)**: AI development environment with MCP support
|
|
479
|
+
- **[KiCAD](https://kicad.org/)**: Open source electronics design automation suite
|
|
480
|
+
|
|
481
|
+
---
|
|
482
|
+
|
|
483
|
+
**Professional KiCAD schematic manipulation for the AI age ⚡**
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
kicad_sch_api/__init__.py,sha256=pxSnH_vkk5oJSRMp55RsitpoxRjum84Jw5JpQrGcSPc,2919
|
|
2
|
+
kicad_sch_api/cli.py,sha256=ZzmwzfHEvPgGfCiQBU4G2LBAyRtMNiBRoY21pivJSYc,7621
|
|
3
|
+
kicad_sch_api/py.typed,sha256=e4ldqxwpY7pNDG1olbvj4HSKr8sZ9vxgA_2ek8xXn-Q,70
|
|
4
|
+
kicad_sch_api/core/__init__.py,sha256=ur_KeYBlGKl-e1hLpLdxAhGV2A-PCCGkcqd0r6KSeBA,566
|
|
5
|
+
kicad_sch_api/core/component_bounds.py,sha256=BFYJYULyzs5it2hN7bHTimyS9Vet4dxsMklRStob-F4,17509
|
|
6
|
+
kicad_sch_api/core/components.py,sha256=tXRL18GObl2u94wl5jP-1ID56s_UD9F1gQ_iRIyZ_Kw,25290
|
|
7
|
+
kicad_sch_api/core/config.py,sha256=itw0j3DeIEHaFVf8p3mfAS1SP6jclBwvMv7NPdkThE4,4309
|
|
8
|
+
kicad_sch_api/core/formatter.py,sha256=ggOc1PZZAGkpdMMNxm1ukCCz9riYnd_sM93nB0fBYuw,20390
|
|
9
|
+
kicad_sch_api/core/geometry.py,sha256=27SgN0padLbQuTi8MV6UUCp6Pyaiv8V9gmYDOhfwny8,2947
|
|
10
|
+
kicad_sch_api/core/ic_manager.py,sha256=Kg0HIOMU-TGXiIkrnwcHFQ1Kfv_3rW2U1cwBKJsKopc,7219
|
|
11
|
+
kicad_sch_api/core/junctions.py,sha256=Ay6BsWX_DLs-wB0eMA2CytKKq0N8Ja41ZubJWpAqNgM,6122
|
|
12
|
+
kicad_sch_api/core/manhattan_routing.py,sha256=t_T2u0zsQB-a8dTijFmY-qFq-oDt2qDebYyXzD_pBWI,15989
|
|
13
|
+
kicad_sch_api/core/parser.py,sha256=raQdKrJZgw3v2ZKyECK7SbzqLMD762H-lQWwxUMDwks,52992
|
|
14
|
+
kicad_sch_api/core/pin_utils.py,sha256=XGEow3HzBTyT8a0B_ZC8foMvwzYaENSaqTUwDW1rz24,5417
|
|
15
|
+
kicad_sch_api/core/schematic.py,sha256=5BSPVWHgj9uwzlwCBT6JSg7sjx9jlADd1aEprO_yOd0,59498
|
|
16
|
+
kicad_sch_api/core/simple_manhattan.py,sha256=CvIHvwmfABPF-COzhblYxEgRoR_R_eD-lmBFHHjDuMI,7241
|
|
17
|
+
kicad_sch_api/core/types.py,sha256=exIJ0cA1puYj09uxiq6inom2YVAs6JTDjf1ka0bKN8g,12872
|
|
18
|
+
kicad_sch_api/core/wire_routing.py,sha256=G-C7S-ntQxwuu1z3OaaYlkURXwKE4r4xmhbbi6cvvaI,12830
|
|
19
|
+
kicad_sch_api/core/wires.py,sha256=608t9oH4UzppdGgNgUd-ABK6T-ahyETZwhO_-CuKFO8,8319
|
|
20
|
+
kicad_sch_api/discovery/__init__.py,sha256=qSuCsnC-hVtaLYE8fwd-Gea6JKwEVGPQ-hSNDNJYsIU,329
|
|
21
|
+
kicad_sch_api/discovery/search_index.py,sha256=KgQT8ipT9OU6ktUwhDZ37Mao0Cba0fJOsxUk9m8ZKbY,15856
|
|
22
|
+
kicad_sch_api/library/__init__.py,sha256=NG9UTdcpn25Bl9tPsYs9ED7bvpaVPVdtLMbnxkQkOnU,250
|
|
23
|
+
kicad_sch_api/library/cache.py,sha256=7na88grl465WHwUOGuOzYrrWwjsMBXhXVtxhnaJ9GBY,33208
|
|
24
|
+
kicad_sch_api/utils/__init__.py,sha256=1V_yGgI7jro6MUc4Pviux_WIeJ1wmiYFID186SZwWLQ,277
|
|
25
|
+
kicad_sch_api/utils/validation.py,sha256=XlWGRZJb3cOPYpU9sLQQgC_NASwbi6W-LCN7PzUmaPY,15626
|
|
26
|
+
kicad_sch_api-0.2.1.dist-info/licenses/LICENSE,sha256=Em65Nvte1G9MHc0rHqtYuGkCPcshD588itTa358J6gs,1070
|
|
27
|
+
kicad_sch_api-0.2.1.dist-info/METADATA,sha256=UJaikwtrjEvTIYzOZpeYA1-nP6LlQpBQf_Fc9wzHO2M,17183
|
|
28
|
+
kicad_sch_api-0.2.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
29
|
+
kicad_sch_api-0.2.1.dist-info/entry_points.txt,sha256=VWKsFi2Jv7G_tmio3cNVhhIBfv_OZFaKa-T_ED84lc8,57
|
|
30
|
+
kicad_sch_api-0.2.1.dist-info/top_level.txt,sha256=n0ex4gOJ1b_fARowcGqRzyOGZcHRhc5LZa6_vVgGxcI,14
|
|
31
|
+
kicad_sch_api-0.2.1.dist-info/RECORD,,
|