kicad-sch-api 0.0.1__tar.gz → 0.1.0__tar.gz

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.

Potentially problematic release.


This version of kicad-sch-api might be problematic. Click here for more details.

Files changed (78) hide show
  1. {kicad_sch_api-0.0.1 → kicad_sch_api-0.1.0}/.claude/commands/dev/review-implementation.md +2 -2
  2. kicad_sch_api-0.1.0/.claude/commands/dev/update-memory-bank.md +33 -0
  3. {kicad_sch_api-0.0.1 → kicad_sch_api-0.1.0}/MANIFEST.in +7 -7
  4. {kicad_sch_api-0.0.1 → kicad_sch_api-0.1.0}/PKG-INFO +14 -33
  5. {kicad_sch_api-0.0.1 → kicad_sch_api-0.1.0}/README.md +11 -27
  6. kicad_sch_api-0.1.0/examples/advanced_usage.py +292 -0
  7. kicad_sch_api-0.1.0/examples/basic_usage.py +184 -0
  8. kicad_sch_api-0.1.0/examples/mcp_integration.py +337 -0
  9. {kicad_sch_api-0.0.1/python → kicad_sch_api-0.1.0}/kicad_sch_api/__init__.py +2 -2
  10. {kicad_sch_api-0.0.1/python → kicad_sch_api-0.1.0}/kicad_sch_api/core/components.py +69 -2
  11. {kicad_sch_api-0.0.1/python → kicad_sch_api-0.1.0}/kicad_sch_api/core/formatter.py +56 -11
  12. kicad_sch_api-0.1.0/kicad_sch_api/core/ic_manager.py +187 -0
  13. kicad_sch_api-0.1.0/kicad_sch_api/core/junctions.py +206 -0
  14. kicad_sch_api-0.1.0/kicad_sch_api/core/parser.py +1036 -0
  15. kicad_sch_api-0.1.0/kicad_sch_api/core/schematic.py +1209 -0
  16. {kicad_sch_api-0.0.1/python → kicad_sch_api-0.1.0}/kicad_sch_api/core/types.py +102 -7
  17. kicad_sch_api-0.1.0/kicad_sch_api/core/wires.py +248 -0
  18. {kicad_sch_api-0.0.1/python → kicad_sch_api-0.1.0}/kicad_sch_api/library/cache.py +321 -10
  19. {kicad_sch_api-0.0.1/python → kicad_sch_api-0.1.0}/kicad_sch_api/utils/validation.py +3 -3
  20. {kicad_sch_api-0.0.1/python → kicad_sch_api-0.1.0}/kicad_sch_api.egg-info/PKG-INFO +14 -33
  21. kicad_sch_api-0.1.0/kicad_sch_api.egg-info/SOURCES.txt +63 -0
  22. {kicad_sch_api-0.0.1/python → kicad_sch_api-0.1.0}/kicad_sch_api.egg-info/requires.txt +0 -3
  23. {kicad_sch_api-0.0.1 → kicad_sch_api-0.1.0}/pyproject.toml +19 -18
  24. kicad_sch_api-0.1.0/tests/reference_tests/reference_kicad_projects/multi_unit_7400/multi_unit_7400.kicad_pro +417 -0
  25. kicad_sch_api-0.1.0/tests/reference_tests/reference_kicad_projects/multi_unit_7400/multi_unit_7400.kicad_sch +1506 -0
  26. kicad_sch_api-0.1.0/tests/reference_tests/reference_kicad_projects/power_symbols/power_symbols.kicad_pro +417 -0
  27. kicad_sch_api-0.1.0/tests/reference_tests/reference_kicad_projects/power_symbols/power_symbols.kicad_sch +564 -0
  28. kicad_sch_api-0.1.0/tests/reference_tests/reference_kicad_projects/single_extended_component/single_extended_component.kicad_pro +417 -0
  29. kicad_sch_api-0.1.0/tests/reference_tests/reference_kicad_projects/single_extended_component/single_extended_component.kicad_sch +450 -0
  30. {kicad_sch_api-0.0.1/python/tests → kicad_sch_api-0.1.0/tests/reference_tests}/reference_kicad_projects/single_hierarchical_sheet/single_hierarchical_sheet.kicad_sch +40 -0
  31. kicad_sch_api-0.1.0/tests/reference_tests/reference_kicad_projects/single_hierarchical_sheet/subcircuit1.kicad_sch +52 -0
  32. kicad_sch_api-0.0.1/CHANGELOG.md +0 -77
  33. kicad_sch_api-0.0.1/CONTRIBUTING.md +0 -306
  34. kicad_sch_api-0.0.1/mcp-server/package.json +0 -58
  35. kicad_sch_api-0.0.1/mcp-server/src/index.ts +0 -160
  36. kicad_sch_api-0.0.1/mcp-server/src/python-bridge.ts +0 -242
  37. kicad_sch_api-0.0.1/mcp-server/src/schematic-tools.ts +0 -420
  38. kicad_sch_api-0.0.1/mcp-server/tsconfig.json +0 -31
  39. kicad_sch_api-0.0.1/python/kicad_sch_api/core/parser.py +0 -434
  40. kicad_sch_api-0.0.1/python/kicad_sch_api/core/schematic.py +0 -478
  41. kicad_sch_api-0.0.1/python/kicad_sch_api/mcp/__init__.py +0 -5
  42. kicad_sch_api-0.0.1/python/kicad_sch_api/mcp/server.py +0 -500
  43. kicad_sch_api-0.0.1/python/kicad_sch_api.egg-info/SOURCES.txt +0 -59
  44. kicad_sch_api-0.0.1/python/tests/reference_kicad_projects/single_hierarchical_sheet/subcircuit1.kicad_sch +0 -8
  45. {kicad_sch_api-0.0.1 → kicad_sch_api-0.1.0}/.claude/commands/dev/dead-code-analysis.md +0 -0
  46. {kicad_sch_api-0.0.1 → kicad_sch_api-0.1.0}/.claude/commands/dev/publish-pypi.md +0 -0
  47. {kicad_sch_api-0.0.1 → kicad_sch_api-0.1.0}/.claude/commands/dev/run-tests.md +0 -0
  48. {kicad_sch_api-0.0.1 → kicad_sch_api-0.1.0}/.claude/commands/dev/update-and-commit.md +0 -0
  49. {kicad_sch_api-0.0.1 → kicad_sch_api-0.1.0}/.claude/commands/test/run-reference-tests.md +0 -0
  50. {kicad_sch_api-0.0.1 → kicad_sch_api-0.1.0}/LICENSE +0 -0
  51. {kicad_sch_api-0.0.1/python → kicad_sch_api-0.1.0}/kicad_sch_api/core/__init__.py +0 -0
  52. {kicad_sch_api-0.0.1/python → kicad_sch_api-0.1.0}/kicad_sch_api/library/__init__.py +0 -0
  53. {kicad_sch_api-0.0.1/python → kicad_sch_api-0.1.0}/kicad_sch_api/py.typed +0 -0
  54. {kicad_sch_api-0.0.1/python → kicad_sch_api-0.1.0}/kicad_sch_api/utils/__init__.py +0 -0
  55. {kicad_sch_api-0.0.1/python → kicad_sch_api-0.1.0}/kicad_sch_api.egg-info/dependency_links.txt +0 -0
  56. {kicad_sch_api-0.0.1/python → kicad_sch_api-0.1.0}/kicad_sch_api.egg-info/entry_points.txt +0 -0
  57. {kicad_sch_api-0.0.1/python → kicad_sch_api-0.1.0}/kicad_sch_api.egg-info/top_level.txt +0 -0
  58. {kicad_sch_api-0.0.1 → kicad_sch_api-0.1.0}/setup.cfg +0 -0
  59. {kicad_sch_api-0.0.1/python/tests → kicad_sch_api-0.1.0/tests/reference_tests}/reference_kicad_projects/README.md +0 -0
  60. {kicad_sch_api-0.0.1/python/tests → kicad_sch_api-0.1.0/tests/reference_tests}/reference_kicad_projects/blank_schematic/blank_schematic.kicad_pro +0 -0
  61. {kicad_sch_api-0.0.1/python/tests → kicad_sch_api-0.1.0/tests/reference_tests}/reference_kicad_projects/blank_schematic/blank_schematic.kicad_sch +0 -0
  62. {kicad_sch_api-0.0.1/python/tests → kicad_sch_api-0.1.0/tests/reference_tests}/reference_kicad_projects/resistor_divider/resistor_divider.kicad_pro +0 -0
  63. {kicad_sch_api-0.0.1/python/tests → kicad_sch_api-0.1.0/tests/reference_tests}/reference_kicad_projects/resistor_divider/resistor_divider.kicad_sch +0 -0
  64. {kicad_sch_api-0.0.1/python/tests → kicad_sch_api-0.1.0/tests/reference_tests}/reference_kicad_projects/single_hierarchical_sheet/single_hierarchical_sheet.kicad_pro +0 -0
  65. {kicad_sch_api-0.0.1/python/tests → kicad_sch_api-0.1.0/tests/reference_tests}/reference_kicad_projects/single_label/single_label.kicad_pro +0 -0
  66. {kicad_sch_api-0.0.1/python/tests → kicad_sch_api-0.1.0/tests/reference_tests}/reference_kicad_projects/single_label/single_label.kicad_sch +0 -0
  67. {kicad_sch_api-0.0.1/python/tests → kicad_sch_api-0.1.0/tests/reference_tests}/reference_kicad_projects/single_label_hierarchical/single_label_hierarchical.kicad_pro +0 -0
  68. {kicad_sch_api-0.0.1/python/tests → kicad_sch_api-0.1.0/tests/reference_tests}/reference_kicad_projects/single_label_hierarchical/single_label_hierarchical.kicad_sch +0 -0
  69. {kicad_sch_api-0.0.1/python/tests → kicad_sch_api-0.1.0/tests/reference_tests}/reference_kicad_projects/single_resistor/single_resistor.kicad_pro +0 -0
  70. {kicad_sch_api-0.0.1/python/tests → kicad_sch_api-0.1.0/tests/reference_tests}/reference_kicad_projects/single_resistor/single_resistor.kicad_sch +0 -0
  71. {kicad_sch_api-0.0.1/python/tests → kicad_sch_api-0.1.0/tests/reference_tests}/reference_kicad_projects/single_text/single_text.kicad_pro +0 -0
  72. {kicad_sch_api-0.0.1/python/tests → kicad_sch_api-0.1.0/tests/reference_tests}/reference_kicad_projects/single_text/single_text.kicad_sch +0 -0
  73. {kicad_sch_api-0.0.1/python/tests → kicad_sch_api-0.1.0/tests/reference_tests}/reference_kicad_projects/single_text_box/single_text_box.kicad_pro +0 -0
  74. {kicad_sch_api-0.0.1/python/tests → kicad_sch_api-0.1.0/tests/reference_tests}/reference_kicad_projects/single_text_box/single_text_box.kicad_sch +0 -0
  75. {kicad_sch_api-0.0.1/python/tests → kicad_sch_api-0.1.0/tests/reference_tests}/reference_kicad_projects/single_wire/single_wire.kicad_pro +0 -0
  76. {kicad_sch_api-0.0.1/python/tests → kicad_sch_api-0.1.0/tests/reference_tests}/reference_kicad_projects/single_wire/single_wire.kicad_sch +0 -0
  77. {kicad_sch_api-0.0.1/python/tests → kicad_sch_api-0.1.0/tests/reference_tests}/reference_kicad_projects/two_resistors/two_resistors.kicad_pro +0 -0
  78. {kicad_sch_api-0.0.1/python/tests → kicad_sch_api-0.1.0/tests/reference_tests}/reference_kicad_projects/two_resistors/two_resistors.kicad_sch +0 -0
@@ -29,7 +29,7 @@ Performs comprehensive code review and analysis of kicad-sch-api implementation,
29
29
  - **Error handling** comprehensiveness and clarity
30
30
 
31
31
  **Key Questions**:
32
- - Does the API feel intuitive compared to kicad-skip?
32
+ - Does the API feel intuitive and pythonic?
33
33
  - Are bulk operations efficient for large schematics?
34
34
  - Is format preservation truly exact?
35
35
  - Do validation errors provide actionable feedback?
@@ -167,6 +167,6 @@ The review generates:
167
167
  - **Performance benchmarks** vs. targets
168
168
  - **API usability** assessment
169
169
  - **Improvement recommendations** prioritized by impact
170
- - **Comparison analysis** vs. kicad-skip and other alternatives
170
+ - **Comparison analysis** vs. other schematic manipulation solutions
171
171
 
172
172
  This ensures kicad-sch-api maintains professional quality standards while providing superior functionality to existing solutions.
@@ -0,0 +1,33 @@
1
+ # Update Memory Bank (UMB)
2
+
3
+ Update the memory bank with current development context and decisions.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ # Command: /umb
9
+ ```
10
+
11
+ Updates the following memory bank files:
12
+ - `.memory_bank/activeContext.md` - Current session state and focus areas
13
+ - `.memory_bank/decisionLog.md` - New technical decisions and architectural choices
14
+ - `.memory_bank/progress.md` - Milestone updates and current tasks
15
+ - `.memory_bank/productContext.md` - Project overview refinements
16
+
17
+ ## When to Use
18
+
19
+ - After completing major features or milestones
20
+ - When making significant architectural decisions
21
+ - At the end of development sessions
22
+ - Before switching development focus areas
23
+ - After resolving complex technical issues
24
+
25
+ ## What Gets Updated
26
+
27
+ The memory bank captures:
28
+ - **Development Context**: Current focus, active files, session goals
29
+ - **Technical Decisions**: API choices, architecture patterns, trade-offs
30
+ - **Progress Tracking**: Completed tasks, next priorities, metrics
31
+ - **Knowledge Patterns**: Reusable solutions, lessons learned
32
+
33
+ This enables AI assistants to maintain rich context about the library's development patterns and architectural evolution.
@@ -10,15 +10,15 @@ include LICENSE
10
10
  include pyproject.toml
11
11
 
12
12
  # Include Python package data
13
- recursive-include python/kicad_sch_api *.py
14
- recursive-include python/kicad_sch_api *.json
15
- recursive-include python/kicad_sch_api *.yaml
16
- recursive-include python/kicad_sch_api *.yml
13
+ recursive-include kicad_sch_api *.py
14
+ recursive-include kicad_sch_api *.json
15
+ recursive-include kicad_sch_api *.yaml
16
+ recursive-include kicad_sch_api *.yml
17
17
 
18
18
  # Include test data (for validation)
19
- recursive-include python/tests/reference_kicad_projects *.kicad_sch
20
- recursive-include python/tests/reference_kicad_projects *.kicad_pro
21
- recursive-include python/tests/reference_kicad_projects *.md
19
+ recursive-include tests/reference_tests/reference_kicad_projects *.kicad_sch
20
+ recursive-include tests/reference_tests/reference_kicad_projects *.kicad_pro
21
+ recursive-include tests/reference_tests/reference_kicad_projects *.md
22
22
 
23
23
  # Include MCP server as documentation/examples
24
24
  recursive-include mcp-server/src *.ts
@@ -1,21 +1,20 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kicad-sch-api
3
- Version: 0.0.1
3
+ Version: 0.1.0
4
4
  Summary: Professional KiCAD schematic manipulation library with exact format preservation and AI agent integration
5
5
  Author-email: Circuit-Synth <info@circuit-synth.com>
6
6
  Maintainer-email: Circuit-Synth <info@circuit-synth.com>
7
- License: MIT
7
+ License-Expression: MIT
8
8
  Project-URL: Homepage, https://github.com/circuit-synth/kicad-sch-api
9
9
  Project-URL: Documentation, https://circuit-synth.github.io/kicad-sch-api/
10
10
  Project-URL: Repository, https://github.com/circuit-synth/kicad-sch-api.git
11
11
  Project-URL: Bug Reports, https://github.com/circuit-synth/kicad-sch-api/issues
12
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,mcp,automation,pcb
13
+ Keywords: kicad,schematic,eda,electronics,circuit-design,ai,automation,pcb
14
14
  Classifier: Development Status :: 4 - Beta
15
15
  Classifier: Intended Audience :: Developers
16
16
  Classifier: Intended Audience :: Science/Research
17
17
  Classifier: Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)
18
- Classifier: License :: OSI Approved :: MIT License
19
18
  Classifier: Programming Language :: Python :: 3
20
19
  Classifier: Programming Language :: Python :: 3.8
21
20
  Classifier: Programming Language :: Python :: 3.9
@@ -28,8 +27,6 @@ Description-Content-Type: text/markdown
28
27
  License-File: LICENSE
29
28
  Requires-Dist: sexpdata>=0.0.3
30
29
  Requires-Dist: typing-extensions>=4.0.0; python_version < "3.11"
31
- Provides-Extra: mcp
32
- Requires-Dist: mcp>=0.1.0; extra == "mcp"
33
30
  Provides-Extra: dev
34
31
  Requires-Dist: pytest>=7.0.0; extra == "dev"
35
32
  Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
@@ -49,13 +46,11 @@ Dynamic: license-file
49
46
 
50
47
  **Professional KiCAD Schematic Manipulation Library with AI Agent Integration**
51
48
 
52
- A modern, high-performance Python library for programmatic manipulation of KiCAD schematic files (.kicad_sch) with exact format preservation, enhanced component management, and native AI agent support via Model Context Protocol (MCP).
53
49
 
54
50
  ## 🚀 Key Features
55
51
 
56
52
  - **📋 Exact Format Preservation**: Output matches KiCAD's native formatting exactly
57
53
  - **⚡ High Performance**: Optimized for large schematics with symbol caching
58
- - **🤖 AI Agent Integration**: Native MCP server for seamless AI agent interaction
59
54
  - **🔧 Enhanced API**: Intuitive object-oriented interface with bulk operations
60
55
  - **📚 Advanced Library Management**: Multi-source symbol lookup and caching
61
56
  - **✅ Professional Validation**: Comprehensive error collection and reporting
@@ -63,14 +58,13 @@ A modern, high-performance Python library for programmatic manipulation of KiCAD
63
58
 
64
59
  ## 🆚 vs. Existing Solutions
65
60
 
66
- | Feature | kicad-sch-api | kicad-skip | KiCAD Official API |
67
- |---------|---------------|------------|-------------------|
68
- | **Schematic Support** | ✅ Full | Full | ❌ PCB Only |
61
+ | Feature | kicad-sch-api | Other Solutions | KiCAD Official API |
62
+ |---------|---------------|-----------------|-------------------|
63
+ | **Schematic Support** | ✅ Full | ⚠️ Varies | ❌ PCB Only |
69
64
  | **Format Preservation** | ✅ Exact | ❌ Basic | N/A |
70
65
  | **Performance** | ✅ Optimized | ⚠️ Basic | N/A |
71
- | **AI Integration** | ✅ Native MCP | None | None |
72
- | **Library Management** | Advanced | ⚠️ Basic | N/A |
73
- | **Runtime Dependencies** | ❌ None | ❌ None | ✅ KiCAD Required |
66
+ | **Library Management** | ✅ Advanced | ⚠️ Limited | N/A |
67
+ | **Runtime Dependencies** | None | ⚠️ Varies | KiCAD Required |
74
68
 
75
69
  ## 📦 Installation
76
70
 
@@ -83,8 +77,6 @@ git clone https://github.com/circuit-synth/kicad-sch-api.git
83
77
  cd kicad-sch-api/python
84
78
  pip install -e .
85
79
 
86
- # For AI agent integration (MCP server)
87
- cd ../mcp-server
88
80
  npm install
89
81
  npm run build
90
82
  ```
@@ -96,22 +88,19 @@ npm run build
96
88
  ```python
97
89
  import kicad_sch_api as ksa
98
90
 
99
- # Load existing schematic
100
- sch = ksa.load_schematic('my_circuit.kicad_sch')
91
+ # Create new schematic
92
+ sch = ksa.create_schematic('My Circuit')
101
93
 
102
94
  # Add components
103
- resistor = sch.components.add('Device:R', ref='R1', value='10k', pos=(100, 100))
104
- capacitor = sch.components.add('Device:C', ref='C1', value='0.1uF', pos=(150, 100))
95
+ resistor = sch.components.add('Device:R', reference='R1', value='10k', position=(100, 100))
96
+ capacitor = sch.components.add('Device:C', reference='C1', value='0.1uF', position=(150, 100))
105
97
 
106
98
  # Update properties
107
99
  resistor.footprint = 'Resistor_SMD:R_0603_1608Metric'
108
100
  resistor.set_property('MPN', 'RC0603FR-0710KL')
109
101
 
110
- # Connect components
111
- sch.add_wire(resistor.get_pin_position('2'), capacitor.get_pin_position('1'))
112
-
113
102
  # Save with exact format preservation
114
- sch.save() # Preserves original formatting exactly
103
+ sch.save('my_circuit.kicad_sch')
115
104
  ```
116
105
 
117
106
  ### Advanced Operations
@@ -141,15 +130,12 @@ stats = sch.get_performance_stats()
141
130
  print(f"Cache hit rate: {stats['symbol_cache']['hit_rate_percent']}%")
142
131
  ```
143
132
 
144
- ### AI Agent Integration (MCP)
145
133
 
146
- Configure in Claude Desktop or compatible MCP client:
147
134
 
148
135
  ```json
149
136
  {
150
137
  "kicad-sch": {
151
138
  "command": "node",
152
- "args": ["/path/to/kicad-sch-api/mcp-server/dist/index.js"],
153
139
  "env": {
154
140
  "PYTHON_PATH": "python3",
155
141
  "KICAD_SCH_API_PATH": "/path/to/kicad-sch-api/python"
@@ -165,7 +151,6 @@ User: "Create a voltage divider circuit with two 10k resistors"
165
151
 
166
152
  Claude: I'll create a voltage divider circuit for you.
167
153
 
168
- [Agent automatically uses MCP tools to:]
169
154
  1. Create new schematic
170
155
  2. Add R1 (10k resistor) at (100, 100)
171
156
  3. Add R2 (10k resistor) at (100, 150)
@@ -187,8 +172,6 @@ The library consists of two main components:
187
172
  - **Symbol Caching**: High-performance library symbol management
188
173
  - **Comprehensive Validation**: Error collection and professional reporting
189
174
 
190
- ### MCP Server (AI Integration)
191
- - **TypeScript MCP Server**: Implements Anthropic's MCP specification
192
175
  - **Python Bridge**: Reliable subprocess communication
193
176
  - **Comprehensive Tools**: 15+ tools for complete schematic manipulation
194
177
  - **Professional Error Handling**: Detailed error context for AI agents
@@ -200,8 +183,6 @@ The library consists of two main components:
200
183
  cd python
201
184
  python -m pytest tests/ -v --cov=kicad_sch_api
202
185
 
203
- # MCP server tests
204
- cd mcp-server
205
186
  npm test
206
187
 
207
188
  # Format preservation tests
@@ -219,7 +200,7 @@ MIT License - see [LICENSE](LICENSE) for details.
219
200
  ## 🔗 Related Projects
220
201
 
221
202
  - **[circuit-synth](https://github.com/circuit-synth/circuit-synth)**: Comprehensive circuit design automation
222
- - **[kicad-skip](https://github.com/psychogenic/kicad-skip)**: Foundation S-expression parser
203
+ - **[sexpdata](https://github.com/jd-boyd/sexpdata)**: S-expression parsing library
223
204
 
224
205
  ---
225
206
 
@@ -2,13 +2,11 @@
2
2
 
3
3
  **Professional KiCAD Schematic Manipulation Library with AI Agent Integration**
4
4
 
5
- A modern, high-performance Python library for programmatic manipulation of KiCAD schematic files (.kicad_sch) with exact format preservation, enhanced component management, and native AI agent support via Model Context Protocol (MCP).
6
5
 
7
6
  ## 🚀 Key Features
8
7
 
9
8
  - **📋 Exact Format Preservation**: Output matches KiCAD's native formatting exactly
10
9
  - **⚡ High Performance**: Optimized for large schematics with symbol caching
11
- - **🤖 AI Agent Integration**: Native MCP server for seamless AI agent interaction
12
10
  - **🔧 Enhanced API**: Intuitive object-oriented interface with bulk operations
13
11
  - **📚 Advanced Library Management**: Multi-source symbol lookup and caching
14
12
  - **✅ Professional Validation**: Comprehensive error collection and reporting
@@ -16,14 +14,13 @@ A modern, high-performance Python library for programmatic manipulation of KiCAD
16
14
 
17
15
  ## 🆚 vs. Existing Solutions
18
16
 
19
- | Feature | kicad-sch-api | kicad-skip | KiCAD Official API |
20
- |---------|---------------|------------|-------------------|
21
- | **Schematic Support** | ✅ Full | Full | ❌ PCB Only |
17
+ | Feature | kicad-sch-api | Other Solutions | KiCAD Official API |
18
+ |---------|---------------|-----------------|-------------------|
19
+ | **Schematic Support** | ✅ Full | ⚠️ Varies | ❌ PCB Only |
22
20
  | **Format Preservation** | ✅ Exact | ❌ Basic | N/A |
23
21
  | **Performance** | ✅ Optimized | ⚠️ Basic | N/A |
24
- | **AI Integration** | ✅ Native MCP | None | None |
25
- | **Library Management** | Advanced | ⚠️ Basic | N/A |
26
- | **Runtime Dependencies** | ❌ None | ❌ None | ✅ KiCAD Required |
22
+ | **Library Management** | ✅ Advanced | ⚠️ Limited | N/A |
23
+ | **Runtime Dependencies** | None | ⚠️ Varies | KiCAD Required |
27
24
 
28
25
  ## 📦 Installation
29
26
 
@@ -36,8 +33,6 @@ git clone https://github.com/circuit-synth/kicad-sch-api.git
36
33
  cd kicad-sch-api/python
37
34
  pip install -e .
38
35
 
39
- # For AI agent integration (MCP server)
40
- cd ../mcp-server
41
36
  npm install
42
37
  npm run build
43
38
  ```
@@ -49,22 +44,19 @@ npm run build
49
44
  ```python
50
45
  import kicad_sch_api as ksa
51
46
 
52
- # Load existing schematic
53
- sch = ksa.load_schematic('my_circuit.kicad_sch')
47
+ # Create new schematic
48
+ sch = ksa.create_schematic('My Circuit')
54
49
 
55
50
  # Add components
56
- resistor = sch.components.add('Device:R', ref='R1', value='10k', pos=(100, 100))
57
- capacitor = sch.components.add('Device:C', ref='C1', value='0.1uF', pos=(150, 100))
51
+ resistor = sch.components.add('Device:R', reference='R1', value='10k', position=(100, 100))
52
+ capacitor = sch.components.add('Device:C', reference='C1', value='0.1uF', position=(150, 100))
58
53
 
59
54
  # Update properties
60
55
  resistor.footprint = 'Resistor_SMD:R_0603_1608Metric'
61
56
  resistor.set_property('MPN', 'RC0603FR-0710KL')
62
57
 
63
- # Connect components
64
- sch.add_wire(resistor.get_pin_position('2'), capacitor.get_pin_position('1'))
65
-
66
58
  # Save with exact format preservation
67
- sch.save() # Preserves original formatting exactly
59
+ sch.save('my_circuit.kicad_sch')
68
60
  ```
69
61
 
70
62
  ### Advanced Operations
@@ -94,15 +86,12 @@ stats = sch.get_performance_stats()
94
86
  print(f"Cache hit rate: {stats['symbol_cache']['hit_rate_percent']}%")
95
87
  ```
96
88
 
97
- ### AI Agent Integration (MCP)
98
89
 
99
- Configure in Claude Desktop or compatible MCP client:
100
90
 
101
91
  ```json
102
92
  {
103
93
  "kicad-sch": {
104
94
  "command": "node",
105
- "args": ["/path/to/kicad-sch-api/mcp-server/dist/index.js"],
106
95
  "env": {
107
96
  "PYTHON_PATH": "python3",
108
97
  "KICAD_SCH_API_PATH": "/path/to/kicad-sch-api/python"
@@ -118,7 +107,6 @@ User: "Create a voltage divider circuit with two 10k resistors"
118
107
 
119
108
  Claude: I'll create a voltage divider circuit for you.
120
109
 
121
- [Agent automatically uses MCP tools to:]
122
110
  1. Create new schematic
123
111
  2. Add R1 (10k resistor) at (100, 100)
124
112
  3. Add R2 (10k resistor) at (100, 150)
@@ -140,8 +128,6 @@ The library consists of two main components:
140
128
  - **Symbol Caching**: High-performance library symbol management
141
129
  - **Comprehensive Validation**: Error collection and professional reporting
142
130
 
143
- ### MCP Server (AI Integration)
144
- - **TypeScript MCP Server**: Implements Anthropic's MCP specification
145
131
  - **Python Bridge**: Reliable subprocess communication
146
132
  - **Comprehensive Tools**: 15+ tools for complete schematic manipulation
147
133
  - **Professional Error Handling**: Detailed error context for AI agents
@@ -153,8 +139,6 @@ The library consists of two main components:
153
139
  cd python
154
140
  python -m pytest tests/ -v --cov=kicad_sch_api
155
141
 
156
- # MCP server tests
157
- cd mcp-server
158
142
  npm test
159
143
 
160
144
  # Format preservation tests
@@ -172,7 +156,7 @@ MIT License - see [LICENSE](LICENSE) for details.
172
156
  ## 🔗 Related Projects
173
157
 
174
158
  - **[circuit-synth](https://github.com/circuit-synth/circuit-synth)**: Comprehensive circuit design automation
175
- - **[kicad-skip](https://github.com/psychogenic/kicad-skip)**: Foundation S-expression parser
159
+ - **[sexpdata](https://github.com/jd-boyd/sexpdata)**: S-expression parsing library
176
160
 
177
161
  ---
178
162
 
@@ -0,0 +1,292 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Advanced usage example for kicad-sch-api.
4
+
5
+ Demonstrates advanced features like bulk operations, filtering,
6
+ validation, and performance optimization for large schematics.
7
+ """
8
+
9
+ import time
10
+
11
+ import kicad_sch_api as ksa
12
+ from kicad_sch_api.core.types import Point
13
+
14
+
15
+ def create_resistor_network():
16
+ """Create a large resistor network to demonstrate performance."""
17
+ print("🏗️ Creating large resistor network...")
18
+
19
+ sch = ksa.create_schematic("Resistor Network")
20
+
21
+ # Create a 10x10 grid of resistors (100 total)
22
+ resistors = []
23
+ start_time = time.time()
24
+
25
+ for row in range(10):
26
+ for col in range(10):
27
+ ref = f"R{row*10 + col + 1}"
28
+ value = f"{(row + 1) * (col + 1)}k" # Varied values
29
+ position = (col * 15 + 50, row * 15 + 50) # 15mm spacing
30
+
31
+ resistor = sch.components.add(
32
+ lib_id="Device:R",
33
+ reference=ref,
34
+ value=value,
35
+ position=position,
36
+ footprint="Resistor_SMD:R_0603_1608Metric",
37
+ )
38
+ resistors.append(resistor)
39
+
40
+ creation_time = time.time() - start_time
41
+ print(f"✅ Created {len(resistors)} resistors in {creation_time:.3f}s")
42
+
43
+ return sch, resistors
44
+
45
+
46
+ def demonstrate_filtering():
47
+ """Demonstrate advanced component filtering capabilities."""
48
+ print("\n🔍 Advanced Component Filtering:")
49
+
50
+ sch, resistors = create_resistor_network()
51
+
52
+ # Filter by lib_id
53
+ all_resistors = sch.components.filter(lib_id="Device:R")
54
+ print(f" All resistors: {len(all_resistors)}")
55
+
56
+ # Filter by value pattern
57
+ high_value = sch.components.filter(value_pattern="k")
58
+ print(f" High value (k-ohm): {len(high_value)}")
59
+
60
+ # Filter by reference pattern
61
+ import re
62
+
63
+ top_row = sch.components.filter(reference_pattern=r"R[1-9]$") # R1-R9
64
+ print(f" Top row (R1-R9): {len(top_row)}")
65
+
66
+ # Spatial filtering
67
+ center_area = sch.components.in_area(80, 80, 120, 120)
68
+ print(f" Components in center area: {len(center_area)}")
69
+
70
+ # Proximity filtering
71
+ center_point = Point(100, 100)
72
+ nearby = sch.components.near_point(center_point, radius=30)
73
+ print(f" Components near center: {len(nearby)}")
74
+
75
+ return sch
76
+
77
+
78
+ def demonstrate_bulk_operations():
79
+ """Demonstrate bulk update operations for large schematics."""
80
+ print("\n⚡ Bulk Operations Performance:")
81
+
82
+ sch = demonstrate_filtering()
83
+
84
+ # Bulk update all resistors
85
+ start_time = time.time()
86
+
87
+ updated_count = sch.components.bulk_update(
88
+ criteria={"lib_id": "Device:R"},
89
+ updates={
90
+ "properties": {
91
+ "Tolerance": "1%",
92
+ "Power": "0.1W",
93
+ "Manufacturer": "Yageo",
94
+ "Temperature_Coefficient": "100ppm/K",
95
+ }
96
+ },
97
+ )
98
+
99
+ bulk_time = time.time() - start_time
100
+ print(f"✅ Bulk updated {updated_count} components in {bulk_time:.3f}s")
101
+ print(f" Performance: {bulk_time/updated_count*1000:.2f}ms per component")
102
+
103
+ # Verify updates applied
104
+ sample_resistor = sch.components.get("R1")
105
+ if sample_resistor:
106
+ print(f" Sample properties: {len(sample_resistor.properties)} properties set")
107
+ print(f" Tolerance: {sample_resistor.get_property('Tolerance')}")
108
+ print(f" Power: {sample_resistor.get_property('Power')}")
109
+
110
+ return sch
111
+
112
+
113
+ def demonstrate_performance_monitoring():
114
+ """Demonstrate performance monitoring and statistics."""
115
+ print("\n📊 Performance Monitoring:")
116
+
117
+ sch = demonstrate_bulk_operations()
118
+
119
+ # Get comprehensive performance statistics
120
+ stats = sch.get_performance_stats()
121
+
122
+ print(" Schematic Performance:")
123
+ schematic_stats = stats.get("schematic", {})
124
+ print(f" Operations: {schematic_stats.get('operation_count', 0)}")
125
+ print(f" Avg time: {schematic_stats.get('avg_operation_time_ms', 0):.2f}ms")
126
+
127
+ print(" Component Collection:")
128
+ component_stats = stats.get("components", {})
129
+ print(f" Total components: {component_stats.get('total_components', 0)}")
130
+ print(f" Unique references: {component_stats.get('unique_references', 0)}")
131
+ print(f" Libraries used: {component_stats.get('libraries_used', 0)}")
132
+
133
+ print(" Symbol Cache:")
134
+ cache_stats = stats.get("symbol_cache", {})
135
+ print(f" Cache hit rate: {cache_stats.get('hit_rate_percent', 0):.1f}%")
136
+ print(f" Symbols cached: {cache_stats.get('total_symbols_cached', 0)}")
137
+ print(f" Total load time: {cache_stats.get('total_load_time_ms', 0):.1f}ms")
138
+
139
+ return sch
140
+
141
+
142
+ def demonstrate_validation_and_error_handling():
143
+ """Demonstrate comprehensive validation and error handling."""
144
+ print("\n✅ Validation and Error Handling:")
145
+
146
+ sch = ksa.create_schematic("Validation Test")
147
+
148
+ # Add valid components
149
+ sch.components.add("Device:R", "R1", "10k", (100, 50))
150
+ sch.components.add("Device:C", "C1", "0.1uF", (150, 50))
151
+
152
+ # Test validation
153
+ issues = sch.validate()
154
+ print(f" Validation issues found: {len(issues)}")
155
+
156
+ # Categorize issues
157
+ errors = [issue for issue in issues if issue.level.value in ("error", "critical")]
158
+ warnings = [issue for issue in issues if issue.level.value == "warning"]
159
+
160
+ print(f" Errors: {len(errors)}")
161
+ print(f" Warnings: {len(warnings)}")
162
+
163
+ if issues:
164
+ print(" Issue details:")
165
+ for issue in issues[:3]: # Show first 3
166
+ print(f" {issue.level.value.upper()}: {issue.message}")
167
+
168
+ # Demonstrate error handling
169
+ print("\n🛡️ Error Handling Examples:")
170
+
171
+ try:
172
+ # Try to add component with invalid reference
173
+ sch.components.add("Device:R", "1R", "10k") # Invalid reference
174
+ except ksa.ValidationError as e:
175
+ print(f" ✅ Caught validation error: {e}")
176
+
177
+ try:
178
+ # Try to add duplicate reference
179
+ sch.components.add("Device:C", "R1", "22uF") # Duplicate reference
180
+ except ksa.ValidationError as e:
181
+ print(f" ✅ Caught duplicate reference: {e}")
182
+
183
+ try:
184
+ # Try invalid lib_id
185
+ sch.components.add("InvalidFormat", "R5", "10k") # Missing colon
186
+ except ksa.ValidationError as e:
187
+ print(f" ✅ Caught invalid lib_id: {e}")
188
+
189
+ return sch
190
+
191
+
192
+ def demonstrate_format_preservation():
193
+ """Demonstrate exact format preservation capabilities."""
194
+ print("\n💎 Format Preservation:")
195
+
196
+ sch = ksa.create_schematic("Format Test")
197
+ sch.components.add("Device:R", "R1", "10k", (100, 50))
198
+
199
+ import os
200
+ import tempfile
201
+
202
+ # Save with format preservation
203
+ with tempfile.NamedTemporaryFile(mode="w", suffix=".kicad_sch", delete=False) as f:
204
+ output_path = f.name
205
+
206
+ try:
207
+ start_time = time.time()
208
+ sch.save(output_path, preserve_format=True)
209
+ save_time = time.time() - start_time
210
+
211
+ print(f" ✅ Saved with format preservation in {save_time:.3f}s")
212
+
213
+ # Reload and verify
214
+ start_time = time.time()
215
+ sch2 = ksa.load_schematic(output_path)
216
+ load_time = time.time() - start_time
217
+
218
+ print(f" ✅ Reloaded in {load_time:.3f}s")
219
+ print(f" ✅ Component preservation: {len(sch2.components)} components")
220
+
221
+ # Verify component data preserved
222
+ r1_original = sch.components.get("R1")
223
+ r1_reloaded = sch2.components.get("R1")
224
+
225
+ if r1_original and r1_reloaded:
226
+ print(f" Reference: {r1_reloaded.reference} ✅")
227
+ print(f" Value: {r1_reloaded.value} ✅")
228
+ print(f" Position: {r1_reloaded.position} ✅")
229
+ print(f" Lib ID: {r1_reloaded.lib_id} ✅")
230
+
231
+ finally:
232
+ if os.path.exists(output_path):
233
+ os.unlink(output_path)
234
+
235
+
236
+ def demonstrate_library_integration():
237
+ """Demonstrate symbol library integration."""
238
+ print("\n📚 Symbol Library Integration:")
239
+
240
+ # Get global symbol cache
241
+ cache = ksa.get_symbol_cache()
242
+
243
+ # Library discovery
244
+ discovered = cache.discover_libraries()
245
+ print(f" Libraries discovered: {discovered}")
246
+
247
+ # Symbol search
248
+ symbols = cache.search_symbols("resistor", limit=5)
249
+ print(f" Resistor symbols found: {len(symbols)}")
250
+
251
+ for symbol in symbols[:3]: # Show first 3
252
+ print(f" {symbol.lib_id}: {symbol.description}")
253
+
254
+ # Cache performance
255
+ cache_stats = cache.get_performance_stats()
256
+ print(f" Cache performance:")
257
+ print(f" Hit rate: {cache_stats.get('hit_rate_percent', 0):.1f}%")
258
+ print(f" Total symbols: {cache_stats.get('total_symbols_cached', 0)}")
259
+
260
+
261
+ def main():
262
+ """Run all advanced usage examples."""
263
+ print("🚀 kicad-sch-api Advanced Usage Examples")
264
+ print("=" * 60)
265
+
266
+ try:
267
+ # Run all demonstrations
268
+ demonstrate_filtering()
269
+ demonstrate_bulk_operations()
270
+ demonstrate_performance_monitoring()
271
+ demonstrate_validation_and_error_handling()
272
+ demonstrate_format_preservation()
273
+ demonstrate_library_integration()
274
+
275
+ print("\n🎉 All advanced examples completed successfully!")
276
+ print("\nAdvanced features demonstrated:")
277
+ print(" ✅ High-performance component collections")
278
+ print(" ✅ Bulk operations for large schematics")
279
+ print(" ✅ Comprehensive validation and error handling")
280
+ print(" ✅ Exact format preservation")
281
+ print(" ✅ Symbol library caching and discovery")
282
+ print(" ✅ Performance monitoring and statistics")
283
+
284
+ except Exception as e:
285
+ print(f"\n❌ Example failed: {e}")
286
+ import traceback
287
+
288
+ traceback.print_exc()
289
+
290
+
291
+ if __name__ == "__main__":
292
+ main()