kicad-tools 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.
Files changed (126) hide show
  1. kicad_tools-0.1.0/.github/workflows/ci.yml +44 -0
  2. kicad_tools-0.1.0/.github/workflows/publish.yml +47 -0
  3. kicad_tools-0.1.0/.gitignore +48 -0
  4. kicad_tools-0.1.0/CHANGELOG.md +38 -0
  5. kicad_tools-0.1.0/LICENSE +21 -0
  6. kicad_tools-0.1.0/PKG-INFO +198 -0
  7. kicad_tools-0.1.0/README.md +165 -0
  8. kicad_tools-0.1.0/ROADMAP.md +298 -0
  9. kicad_tools-0.1.0/pyproject.toml +110 -0
  10. kicad_tools-0.1.0/src/kicad_tools/__init__.py +39 -0
  11. kicad_tools-0.1.0/src/kicad_tools/cli/__init__.py +504 -0
  12. kicad_tools-0.1.0/src/kicad_tools/cli/__main__.py +8 -0
  13. kicad_tools-0.1.0/src/kicad_tools/cli/bom_cmd.py +241 -0
  14. kicad_tools-0.1.0/src/kicad_tools/cli/check_parts.py +336 -0
  15. kicad_tools-0.1.0/src/kicad_tools/cli/drc_cmd.py +529 -0
  16. kicad_tools-0.1.0/src/kicad_tools/cli/erc_cmd.py +382 -0
  17. kicad_tools-0.1.0/src/kicad_tools/cli/export_gerbers.py +368 -0
  18. kicad_tools-0.1.0/src/kicad_tools/cli/export_netlist.py +630 -0
  19. kicad_tools-0.1.0/src/kicad_tools/cli/fetch_seeed_opl.py +269 -0
  20. kicad_tools-0.1.0/src/kicad_tools/cli/generate_bom.py +933 -0
  21. kicad_tools-0.1.0/src/kicad_tools/cli/lib_list_symbols.py +131 -0
  22. kicad_tools-0.1.0/src/kicad_tools/cli/mfr.py +369 -0
  23. kicad_tools-0.1.0/src/kicad_tools/cli/modify_schematic.py +752 -0
  24. kicad_tools-0.1.0/src/kicad_tools/cli/nets.py +222 -0
  25. kicad_tools-0.1.0/src/kicad_tools/cli/pcb_modify.py +347 -0
  26. kicad_tools-0.1.0/src/kicad_tools/cli/pcb_query.py +499 -0
  27. kicad_tools-0.1.0/src/kicad_tools/cli/pin_mapper.py +567 -0
  28. kicad_tools-0.1.0/src/kicad_tools/cli/query_schematic.py +907 -0
  29. kicad_tools-0.1.0/src/kicad_tools/cli/query_symbols.py +633 -0
  30. kicad_tools-0.1.0/src/kicad_tools/cli/runner.py +307 -0
  31. kicad_tools-0.1.0/src/kicad_tools/cli/sch_check_connections.py +320 -0
  32. kicad_tools-0.1.0/src/kicad_tools/cli/sch_find_unconnected.py +310 -0
  33. kicad_tools-0.1.0/src/kicad_tools/cli/sch_generate_bom.py +255 -0
  34. kicad_tools-0.1.0/src/kicad_tools/cli/sch_hierarchy.py +350 -0
  35. kicad_tools-0.1.0/src/kicad_tools/cli/sch_list_labels.py +184 -0
  36. kicad_tools-0.1.0/src/kicad_tools/cli/sch_list_symbols.py +166 -0
  37. kicad_tools-0.1.0/src/kicad_tools/cli/sch_list_wires.py +170 -0
  38. kicad_tools-0.1.0/src/kicad_tools/cli/sch_pin_positions.py +159 -0
  39. kicad_tools-0.1.0/src/kicad_tools/cli/sch_replace_symbol.py +112 -0
  40. kicad_tools-0.1.0/src/kicad_tools/cli/sch_run_erc.py +347 -0
  41. kicad_tools-0.1.0/src/kicad_tools/cli/sch_summary.py +251 -0
  42. kicad_tools-0.1.0/src/kicad_tools/cli/sch_symbol_info.py +129 -0
  43. kicad_tools-0.1.0/src/kicad_tools/cli/sch_trace_nets.py +229 -0
  44. kicad_tools-0.1.0/src/kicad_tools/cli/sch_validate.py +400 -0
  45. kicad_tools-0.1.0/src/kicad_tools/cli/symbols.py +167 -0
  46. kicad_tools-0.1.0/src/kicad_tools/cli/validate_drc.py +423 -0
  47. kicad_tools-0.1.0/src/kicad_tools/cli/validate_erc.py +551 -0
  48. kicad_tools-0.1.0/src/kicad_tools/core/__init__.py +20 -0
  49. kicad_tools-0.1.0/src/kicad_tools/core/sexp.py +422 -0
  50. kicad_tools-0.1.0/src/kicad_tools/core/sexp_file.py +143 -0
  51. kicad_tools-0.1.0/src/kicad_tools/drc/__init__.py +45 -0
  52. kicad_tools-0.1.0/src/kicad_tools/drc/checker.py +262 -0
  53. kicad_tools-0.1.0/src/kicad_tools/drc/report.py +355 -0
  54. kicad_tools-0.1.0/src/kicad_tools/drc/violation.py +215 -0
  55. kicad_tools-0.1.0/src/kicad_tools/erc/__init__.py +38 -0
  56. kicad_tools-0.1.0/src/kicad_tools/erc/report.py +292 -0
  57. kicad_tools-0.1.0/src/kicad_tools/erc/violation.py +245 -0
  58. kicad_tools-0.1.0/src/kicad_tools/footprints/__init__.py +111 -0
  59. kicad_tools-0.1.0/src/kicad_tools/manufacturers/__init__.py +189 -0
  60. kicad_tools-0.1.0/src/kicad_tools/manufacturers/base.py +227 -0
  61. kicad_tools-0.1.0/src/kicad_tools/manufacturers/jlcpcb.py +224 -0
  62. kicad_tools-0.1.0/src/kicad_tools/manufacturers/oshpark.py +120 -0
  63. kicad_tools-0.1.0/src/kicad_tools/manufacturers/pcbway.py +198 -0
  64. kicad_tools-0.1.0/src/kicad_tools/manufacturers/rules/jlcpcb-4layer-1oz.kicad_dru +17 -0
  65. kicad_tools-0.1.0/src/kicad_tools/manufacturers/rules/jlcpcb-4layer-2oz.kicad_dru +17 -0
  66. kicad_tools-0.1.0/src/kicad_tools/manufacturers/rules/oshpark-4layer-1oz.kicad_dru +17 -0
  67. kicad_tools-0.1.0/src/kicad_tools/manufacturers/rules/pcbway-4layer-1oz.kicad_dru +17 -0
  68. kicad_tools-0.1.0/src/kicad_tools/manufacturers/rules/seeed-4layer-1oz.kicad_dru +17 -0
  69. kicad_tools-0.1.0/src/kicad_tools/manufacturers/seeed.py +194 -0
  70. kicad_tools-0.1.0/src/kicad_tools/operations/__init__.py +67 -0
  71. kicad_tools-0.1.0/src/kicad_tools/operations/net_ops.py +267 -0
  72. kicad_tools-0.1.0/src/kicad_tools/operations/netlist.py +443 -0
  73. kicad_tools-0.1.0/src/kicad_tools/operations/pinmap.py +420 -0
  74. kicad_tools-0.1.0/src/kicad_tools/operations/symbol_ops.py +286 -0
  75. kicad_tools-0.1.0/src/kicad_tools/optim/__init__.py +68 -0
  76. kicad_tools-0.1.0/src/kicad_tools/pcb/__init__.py +43 -0
  77. kicad_tools-0.1.0/src/kicad_tools/pcb/blocks.py +1343 -0
  78. kicad_tools-0.1.0/src/kicad_tools/pcb/editor.py +552 -0
  79. kicad_tools-0.1.0/src/kicad_tools/pcb/footprints.py +424 -0
  80. kicad_tools-0.1.0/src/kicad_tools/py.typed +0 -0
  81. kicad_tools-0.1.0/src/kicad_tools/router/__init__.py +104 -0
  82. kicad_tools-0.1.0/src/kicad_tools/router/core.py +1083 -0
  83. kicad_tools-0.1.0/src/kicad_tools/router/grid.py +565 -0
  84. kicad_tools-0.1.0/src/kicad_tools/router/heuristics.py +339 -0
  85. kicad_tools-0.1.0/src/kicad_tools/router/io.py +301 -0
  86. kicad_tools-0.1.0/src/kicad_tools/router/layers.py +403 -0
  87. kicad_tools-0.1.0/src/kicad_tools/router/pathfinder.py +486 -0
  88. kicad_tools-0.1.0/src/kicad_tools/router/primitives.py +173 -0
  89. kicad_tools-0.1.0/src/kicad_tools/router/rules.py +173 -0
  90. kicad_tools-0.1.0/src/kicad_tools/schema/__init__.py +66 -0
  91. kicad_tools-0.1.0/src/kicad_tools/schema/bom.py +279 -0
  92. kicad_tools-0.1.0/src/kicad_tools/schema/hierarchy.py +360 -0
  93. kicad_tools-0.1.0/src/kicad_tools/schema/label.py +176 -0
  94. kicad_tools-0.1.0/src/kicad_tools/schema/library.py +318 -0
  95. kicad_tools-0.1.0/src/kicad_tools/schema/pcb.py +568 -0
  96. kicad_tools-0.1.0/src/kicad_tools/schema/schematic.py +285 -0
  97. kicad_tools-0.1.0/src/kicad_tools/schema/symbol.py +190 -0
  98. kicad_tools-0.1.0/src/kicad_tools/schema/wire.py +154 -0
  99. kicad_tools-0.1.0/src/kicad_tools/schematic/__init__.py +53 -0
  100. kicad_tools-0.1.0/src/kicad_tools/schematic/blocks.py +648 -0
  101. kicad_tools-0.1.0/src/kicad_tools/schematic/helper.py +3472 -0
  102. kicad_tools-0.1.0/src/kicad_tools/schematic/registry.py +643 -0
  103. kicad_tools-0.1.0/src/kicad_tools/schematic/symbol_generator.py +917 -0
  104. kicad_tools-0.1.0/src/kicad_tools/sexp/__init__.py +36 -0
  105. kicad_tools-0.1.0/src/kicad_tools/sexp/builders.py +439 -0
  106. kicad_tools-0.1.0/src/kicad_tools/sexp/parser.py +809 -0
  107. kicad_tools-0.1.0/tests/__init__.py +1 -0
  108. kicad_tools-0.1.0/tests/conftest.py +146 -0
  109. kicad_tools-0.1.0/tests/fixtures/sample_drc.rpt +27 -0
  110. kicad_tools-0.1.0/tests/fixtures/sample_erc.json +91 -0
  111. kicad_tools-0.1.0/tests/fixtures/simple_rc.kicad_sch +182 -0
  112. kicad_tools-0.1.0/tests/test_cli.py +402 -0
  113. kicad_tools-0.1.0/tests/test_drc.py +286 -0
  114. kicad_tools-0.1.0/tests/test_erc.py +259 -0
  115. kicad_tools-0.1.0/tests/test_mfr.py +176 -0
  116. kicad_tools-0.1.0/tests/test_operations.py +719 -0
  117. kicad_tools-0.1.0/tests/test_pcb.py +59 -0
  118. kicad_tools-0.1.0/tests/test_router.py +697 -0
  119. kicad_tools-0.1.0/tests/test_schema.py +1050 -0
  120. kicad_tools-0.1.0/tests/test_schematic.py +46 -0
  121. kicad_tools-0.1.0/tests/test_schematic_blocks.py +535 -0
  122. kicad_tools-0.1.0/tests/test_schematic_helpers.py +479 -0
  123. kicad_tools-0.1.0/tests/test_schematic_registry.py +517 -0
  124. kicad_tools-0.1.0/tests/test_sexp.py +391 -0
  125. kicad_tools-0.1.0/tests/test_sexp_builders.py +501 -0
  126. kicad_tools-0.1.0/uv.lock +595 -0
@@ -0,0 +1,44 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ${{ matrix.os }}
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ os: [ubuntu-latest, macos-latest]
16
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
17
+
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+
21
+ - name: Set up Python ${{ matrix.python-version }}
22
+ uses: actions/setup-python@v5
23
+ with:
24
+ python-version: ${{ matrix.python-version }}
25
+
26
+ - name: Install dependencies
27
+ run: |
28
+ python -m pip install --upgrade pip
29
+ pip install -e ".[dev]"
30
+
31
+ - name: Lint with ruff
32
+ run: |
33
+ ruff check src/
34
+
35
+ - name: Test with pytest
36
+ run: |
37
+ pytest tests/ -v --cov=kicad_tools --cov-report=xml
38
+
39
+ - name: Upload coverage
40
+ uses: codecov/codecov-action@v4
41
+ if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'
42
+ with:
43
+ files: ./coverage.xml
44
+ fail_ci_if_error: false
@@ -0,0 +1,47 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+
13
+ - name: Set up Python
14
+ uses: actions/setup-python@v5
15
+ with:
16
+ python-version: "3.12"
17
+
18
+ - name: Install build dependencies
19
+ run: |
20
+ python -m pip install --upgrade pip
21
+ pip install build
22
+
23
+ - name: Build package
24
+ run: python -m build
25
+
26
+ - name: Upload artifacts
27
+ uses: actions/upload-artifact@v4
28
+ with:
29
+ name: dist
30
+ path: dist/
31
+
32
+ publish:
33
+ needs: build
34
+ runs-on: ubuntu-latest
35
+ environment: pypi
36
+ permissions:
37
+ id-token: write # Required for trusted publishing
38
+
39
+ steps:
40
+ - name: Download artifacts
41
+ uses: actions/download-artifact@v4
42
+ with:
43
+ name: dist
44
+ path: dist/
45
+
46
+ - name: Publish to PyPI
47
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,48 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ *.egg-info/
20
+ .installed.cfg
21
+ *.egg
22
+
23
+ # Virtual environments
24
+ .venv/
25
+ venv/
26
+ ENV/
27
+
28
+ # IDE
29
+ .idea/
30
+ .vscode/
31
+ *.swp
32
+ *.swo
33
+ *~
34
+
35
+ # Testing
36
+ .pytest_cache/
37
+ .coverage
38
+ htmlcov/
39
+ coverage.xml
40
+ *.cover
41
+
42
+ # Build
43
+ *.whl
44
+ *.tar.gz
45
+
46
+ # OS
47
+ .DS_Store
48
+ Thumbs.db
@@ -0,0 +1,38 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.0] - 2024-12-29
9
+
10
+ ### Added
11
+
12
+ - **Core S-expression parser** with round-trip editing support
13
+ - **Schematic parsing** - symbols, wires, labels, hierarchy traversal
14
+ - **PCB parsing** - footprints, nets, traces, vias, zones
15
+ - **Symbol library parsing** - read and query KiCad symbol libraries
16
+ - **ERC report parsing** - parse KiCad Electrical Rules Check reports
17
+ - **DRC report parsing** - parse KiCad Design Rules Check reports
18
+ - **Manufacturer profiles** - design rules for JLCPCB, OSHPark, PCBWay, Seeed
19
+ - **PCB autorouter** - A* pathfinding with pluggable heuristics
20
+ - Net class awareness (power, clock, audio, digital)
21
+ - Multi-layer support with via management
22
+ - Congestion-aware routing
23
+ - **Unified CLI** (`kct` or `kicad-tools`) with subcommands:
24
+ - `kct symbols` - list symbols in schematics
25
+ - `kct nets` - trace and analyze nets
26
+ - `kct bom` - generate bill of materials
27
+ - `kct erc` - run/parse ERC reports
28
+ - `kct drc` - run/parse DRC reports with manufacturer rules
29
+ - **PCB tools** - `kicad-pcb-query` and `kicad-pcb-modify`
30
+ - **Library tools** - `kicad-lib-symbols`
31
+ - JSON output for all CLI commands
32
+
33
+ ### Dependencies
34
+
35
+ - Python 3.10+
36
+ - numpy >= 1.20
37
+
38
+ [0.1.0]: https://github.com/rjwalters/kicad-tools/releases/tag/v0.1.0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 RJ Walters
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,198 @@
1
+ Metadata-Version: 2.4
2
+ Name: kicad-tools
3
+ Version: 0.1.0
4
+ Summary: Standalone Python tools for parsing and manipulating KiCad schematic and PCB files
5
+ Project-URL: Homepage, https://github.com/rjwalters/kicad-tools
6
+ Project-URL: Repository, https://github.com/rjwalters/kicad-tools
7
+ Project-URL: Issues, https://github.com/rjwalters/kicad-tools/issues
8
+ Author: RJ Walters
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: automation,drc,eda,electronics,erc,hardware,kicad,pcb,schematic
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Manufacturing
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)
24
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
25
+ Requires-Python: >=3.10
26
+ Requires-Dist: numpy>=1.20
27
+ Provides-Extra: dev
28
+ Requires-Dist: mypy>=1.0; extra == 'dev'
29
+ Requires-Dist: pytest-cov>=4.0; extra == 'dev'
30
+ Requires-Dist: pytest>=7.0; extra == 'dev'
31
+ Requires-Dist: ruff>=0.1.0; extra == 'dev'
32
+ Description-Content-Type: text/markdown
33
+
34
+ # kicad-tools
35
+
36
+ [![PyPI version](https://badge.fury.io/py/kicad-tools.svg)](https://pypi.org/project/kicad-tools/)
37
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
38
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
39
+
40
+ Standalone Python tools for parsing and manipulating KiCad schematic and PCB files.
41
+
42
+ **No running KiCad instance required** - works directly with `.kicad_sch` and `.kicad_pcb` files.
43
+
44
+ ## Installation
45
+
46
+ ```bash
47
+ pip install kicad-tools
48
+ ```
49
+
50
+ ## Quick Start
51
+
52
+ ### Command Line (`kct`)
53
+
54
+ ```bash
55
+ # List symbols in a schematic
56
+ kct symbols project.kicad_sch
57
+ kct symbols project.kicad_sch --format json
58
+
59
+ # Trace nets
60
+ kct nets project.kicad_sch
61
+ kct nets project.kicad_sch --net VCC
62
+
63
+ # Generate bill of materials
64
+ kct bom project.kicad_sch
65
+ kct bom project.kicad_sch --format csv --group
66
+
67
+ # Run ERC (requires kicad-cli)
68
+ kct erc project.kicad_sch
69
+ kct erc project.kicad_sch --strict
70
+
71
+ # Run DRC with manufacturer rules
72
+ kct drc board.kicad_pcb
73
+ kct drc board.kicad_pcb --mfr jlcpcb
74
+ kct drc --compare # Compare manufacturer rules
75
+ ```
76
+
77
+ ### Python API
78
+
79
+ ```python
80
+ from kicad_tools import load_schematic, Schematic
81
+
82
+ # Load and parse a schematic
83
+ doc = load_schematic("project.kicad_sch")
84
+ sch = Schematic(doc)
85
+
86
+ # Access symbols
87
+ for symbol in sch.symbols:
88
+ print(f"{symbol.reference}: {symbol.value}")
89
+
90
+ # Access hierarchy
91
+ for sheet in sch.sheets:
92
+ print(f"Sheet: {sheet.name}")
93
+ ```
94
+
95
+ ### PCB Autorouter
96
+
97
+ ```python
98
+ from kicad_tools.router import Autorouter, DesignRules
99
+
100
+ # Configure design rules
101
+ rules = DesignRules(
102
+ grid_resolution=0.25, # mm
103
+ trace_width=0.2, # mm
104
+ clearance=0.15, # mm
105
+ )
106
+
107
+ # Create router and add components
108
+ router = Autorouter(width=100, height=80, rules=rules)
109
+ router.add_component("U1", pads=[...])
110
+
111
+ # Route all nets
112
+ result = router.route_all()
113
+ print(f"Routed {result.routed_nets}/{result.total_nets} nets")
114
+ ```
115
+
116
+ ## CLI Commands
117
+
118
+ ### Unified CLI (`kct` or `kicad-tools`)
119
+
120
+ | Command | Description |
121
+ |---------|-------------|
122
+ | `kct symbols <schematic>` | List symbols with filtering |
123
+ | `kct nets <schematic>` | Trace and analyze nets |
124
+ | `kct bom <schematic>` | Generate bill of materials |
125
+ | `kct erc <schematic>` | Run electrical rules check |
126
+ | `kct drc <pcb>` | Run design rules check |
127
+
128
+ All commands support `--format json` for machine-readable output.
129
+
130
+ ### PCB Tools
131
+
132
+ | Command | Description |
133
+ |---------|-------------|
134
+ | `kicad-pcb-query summary` | Board overview |
135
+ | `kicad-pcb-query footprints` | List footprints |
136
+ | `kicad-pcb-query nets` | List all nets |
137
+ | `kicad-pcb-query traces` | Trace statistics |
138
+ | `kicad-pcb-modify move` | Move component |
139
+ | `kicad-pcb-modify rotate` | Rotate component |
140
+
141
+ ### Library Tools
142
+
143
+ | Command | Description |
144
+ |---------|-------------|
145
+ | `kicad-lib-symbols` | List symbols in library |
146
+
147
+ ## Modules
148
+
149
+ | Module | Description |
150
+ |--------|-------------|
151
+ | `core` | S-expression parsing and file I/O |
152
+ | `schema` | Data models (Schematic, PCB, Symbol, Wire, Label) |
153
+ | `drc` | Design Rule Check report parsing |
154
+ | `erc` | Electrical Rule Check report parsing |
155
+ | `manufacturers` | PCB fab profiles (JLCPCB, OSHPark, PCBWay, Seeed) |
156
+ | `operations` | Schematic operations (net tracing, symbol replacement) |
157
+ | `router` | A* PCB autorouter with pluggable heuristics |
158
+
159
+ ## Features
160
+
161
+ - **Pure Python parsing** - No KiCad installation needed
162
+ - **Round-trip editing** - Parse, modify, and save files preserving formatting
163
+ - **Full S-expression support** - Handles all KiCad 8.0+ file formats
164
+ - **Schematic analysis** - Symbols, wires, labels, hierarchy traversal
165
+ - **PCB analysis** - Footprints, nets, traces, vias, zones
166
+ - **Manufacturer rules** - JLCPCB, PCBWay, OSHPark, Seeed design rules
167
+ - **PCB autorouter** - A* pathfinding with net class awareness
168
+ - **JSON output** - Machine-readable output for automation
169
+
170
+ ## Requirements
171
+
172
+ - Python 3.10+
173
+ - numpy (for router module)
174
+ - KiCad 8+ (optional) - for running ERC/DRC via `kicad-cli`
175
+
176
+ ## Development
177
+
178
+ ```bash
179
+ # Clone repository
180
+ git clone https://github.com/rjwalters/kicad-tools.git
181
+ cd kicad-tools
182
+
183
+ # Install with dev dependencies
184
+ pip install -e ".[dev]"
185
+
186
+ # Run tests
187
+ pytest tests/ -v
188
+
189
+ # Run linter
190
+ ruff check src/
191
+
192
+ # Format code
193
+ ruff format src/
194
+ ```
195
+
196
+ ## License
197
+
198
+ MIT
@@ -0,0 +1,165 @@
1
+ # kicad-tools
2
+
3
+ [![PyPI version](https://badge.fury.io/py/kicad-tools.svg)](https://pypi.org/project/kicad-tools/)
4
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ Standalone Python tools for parsing and manipulating KiCad schematic and PCB files.
8
+
9
+ **No running KiCad instance required** - works directly with `.kicad_sch` and `.kicad_pcb` files.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ pip install kicad-tools
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ### Command Line (`kct`)
20
+
21
+ ```bash
22
+ # List symbols in a schematic
23
+ kct symbols project.kicad_sch
24
+ kct symbols project.kicad_sch --format json
25
+
26
+ # Trace nets
27
+ kct nets project.kicad_sch
28
+ kct nets project.kicad_sch --net VCC
29
+
30
+ # Generate bill of materials
31
+ kct bom project.kicad_sch
32
+ kct bom project.kicad_sch --format csv --group
33
+
34
+ # Run ERC (requires kicad-cli)
35
+ kct erc project.kicad_sch
36
+ kct erc project.kicad_sch --strict
37
+
38
+ # Run DRC with manufacturer rules
39
+ kct drc board.kicad_pcb
40
+ kct drc board.kicad_pcb --mfr jlcpcb
41
+ kct drc --compare # Compare manufacturer rules
42
+ ```
43
+
44
+ ### Python API
45
+
46
+ ```python
47
+ from kicad_tools import load_schematic, Schematic
48
+
49
+ # Load and parse a schematic
50
+ doc = load_schematic("project.kicad_sch")
51
+ sch = Schematic(doc)
52
+
53
+ # Access symbols
54
+ for symbol in sch.symbols:
55
+ print(f"{symbol.reference}: {symbol.value}")
56
+
57
+ # Access hierarchy
58
+ for sheet in sch.sheets:
59
+ print(f"Sheet: {sheet.name}")
60
+ ```
61
+
62
+ ### PCB Autorouter
63
+
64
+ ```python
65
+ from kicad_tools.router import Autorouter, DesignRules
66
+
67
+ # Configure design rules
68
+ rules = DesignRules(
69
+ grid_resolution=0.25, # mm
70
+ trace_width=0.2, # mm
71
+ clearance=0.15, # mm
72
+ )
73
+
74
+ # Create router and add components
75
+ router = Autorouter(width=100, height=80, rules=rules)
76
+ router.add_component("U1", pads=[...])
77
+
78
+ # Route all nets
79
+ result = router.route_all()
80
+ print(f"Routed {result.routed_nets}/{result.total_nets} nets")
81
+ ```
82
+
83
+ ## CLI Commands
84
+
85
+ ### Unified CLI (`kct` or `kicad-tools`)
86
+
87
+ | Command | Description |
88
+ |---------|-------------|
89
+ | `kct symbols <schematic>` | List symbols with filtering |
90
+ | `kct nets <schematic>` | Trace and analyze nets |
91
+ | `kct bom <schematic>` | Generate bill of materials |
92
+ | `kct erc <schematic>` | Run electrical rules check |
93
+ | `kct drc <pcb>` | Run design rules check |
94
+
95
+ All commands support `--format json` for machine-readable output.
96
+
97
+ ### PCB Tools
98
+
99
+ | Command | Description |
100
+ |---------|-------------|
101
+ | `kicad-pcb-query summary` | Board overview |
102
+ | `kicad-pcb-query footprints` | List footprints |
103
+ | `kicad-pcb-query nets` | List all nets |
104
+ | `kicad-pcb-query traces` | Trace statistics |
105
+ | `kicad-pcb-modify move` | Move component |
106
+ | `kicad-pcb-modify rotate` | Rotate component |
107
+
108
+ ### Library Tools
109
+
110
+ | Command | Description |
111
+ |---------|-------------|
112
+ | `kicad-lib-symbols` | List symbols in library |
113
+
114
+ ## Modules
115
+
116
+ | Module | Description |
117
+ |--------|-------------|
118
+ | `core` | S-expression parsing and file I/O |
119
+ | `schema` | Data models (Schematic, PCB, Symbol, Wire, Label) |
120
+ | `drc` | Design Rule Check report parsing |
121
+ | `erc` | Electrical Rule Check report parsing |
122
+ | `manufacturers` | PCB fab profiles (JLCPCB, OSHPark, PCBWay, Seeed) |
123
+ | `operations` | Schematic operations (net tracing, symbol replacement) |
124
+ | `router` | A* PCB autorouter with pluggable heuristics |
125
+
126
+ ## Features
127
+
128
+ - **Pure Python parsing** - No KiCad installation needed
129
+ - **Round-trip editing** - Parse, modify, and save files preserving formatting
130
+ - **Full S-expression support** - Handles all KiCad 8.0+ file formats
131
+ - **Schematic analysis** - Symbols, wires, labels, hierarchy traversal
132
+ - **PCB analysis** - Footprints, nets, traces, vias, zones
133
+ - **Manufacturer rules** - JLCPCB, PCBWay, OSHPark, Seeed design rules
134
+ - **PCB autorouter** - A* pathfinding with net class awareness
135
+ - **JSON output** - Machine-readable output for automation
136
+
137
+ ## Requirements
138
+
139
+ - Python 3.10+
140
+ - numpy (for router module)
141
+ - KiCad 8+ (optional) - for running ERC/DRC via `kicad-cli`
142
+
143
+ ## Development
144
+
145
+ ```bash
146
+ # Clone repository
147
+ git clone https://github.com/rjwalters/kicad-tools.git
148
+ cd kicad-tools
149
+
150
+ # Install with dev dependencies
151
+ pip install -e ".[dev]"
152
+
153
+ # Run tests
154
+ pytest tests/ -v
155
+
156
+ # Run linter
157
+ ruff check src/
158
+
159
+ # Format code
160
+ ruff format src/
161
+ ```
162
+
163
+ ## License
164
+
165
+ MIT