mc9py 0.2.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 (71) hide show
  1. mc9py-0.2.0/.gitignore +25 -0
  2. mc9py-0.2.0/CHANGELOG.md +12 -0
  3. mc9py-0.2.0/LICENSE +21 -0
  4. mc9py-0.2.0/PKG-INFO +276 -0
  5. mc9py-0.2.0/README.md +235 -0
  6. mc9py-0.2.0/docs/assets/ce_ac_cursors.png +0 -0
  7. mc9py-0.2.0/docs/assets/ce_distortion.png +0 -0
  8. mc9py-0.2.0/docs/assets/ce_schematic_ac.png +0 -0
  9. mc9py-0.2.0/docs/assets/ce_schematic_dc.png +0 -0
  10. mc9py-0.2.0/docs/assets/ce_transient.png +0 -0
  11. mc9py-0.2.0/docs/assets/clipper_transient.png +0 -0
  12. mc9py-0.2.0/docs/assets/inverting_schematic.png +0 -0
  13. mc9py-0.2.0/docs/changelog.md +1 -0
  14. mc9py-0.2.0/docs/contributing.md +1 -0
  15. mc9py-0.2.0/docs/faq.md +35 -0
  16. mc9py-0.2.0/docs/getting-started/install-linux.md +64 -0
  17. mc9py-0.2.0/docs/getting-started/install-windows.md +39 -0
  18. mc9py-0.2.0/docs/getting-started/quickstart.md +64 -0
  19. mc9py-0.2.0/docs/guide/analyses.md +34 -0
  20. mc9py-0.2.0/docs/guide/autoplace.md +69 -0
  21. mc9py-0.2.0/docs/guide/circuits.md +38 -0
  22. mc9py-0.2.0/docs/guide/configuration.md +43 -0
  23. mc9py-0.2.0/docs/guide/cookbook.md +120 -0
  24. mc9py-0.2.0/docs/guide/mcp.md +52 -0
  25. mc9py-0.2.0/docs/guide/measurements.md +39 -0
  26. mc9py-0.2.0/docs/guide/results.md +55 -0
  27. mc9py-0.2.0/docs/guide/schematics.md +65 -0
  28. mc9py-0.2.0/docs/guide/screenshots.md +54 -0
  29. mc9py-0.2.0/docs/index.md +52 -0
  30. mc9py-0.2.0/docs/internals/architecture.md +47 -0
  31. mc9py-0.2.0/docs/internals/calibration.md +19 -0
  32. mc9py-0.2.0/docs/internals/mc9-notes.md +38 -0
  33. mc9py-0.2.0/docs/internals/windows-backend.md +31 -0
  34. mc9py-0.2.0/docs/reference/api.md +49 -0
  35. mc9py-0.2.0/docs/reference/cli.md +11 -0
  36. mc9py-0.2.0/examples/analyze_cir.py +31 -0
  37. mc9py-0.2.0/examples/build_ce_amp.py +48 -0
  38. mc9py-0.2.0/examples/build_inverting_amp.py +43 -0
  39. mc9py-0.2.0/examples/netlist_gallery.py +25 -0
  40. mc9py-0.2.0/examples/quickstart.py +19 -0
  41. mc9py-0.2.0/mkdocs.yml +71 -0
  42. mc9py-0.2.0/pyproject.toml +70 -0
  43. mc9py-0.2.0/src/mc9/__init__.py +15 -0
  44. mc9py-0.2.0/src/mc9/__main__.py +6 -0
  45. mc9py-0.2.0/src/mc9/api.py +504 -0
  46. mc9py-0.2.0/src/mc9/autoplace.py +522 -0
  47. mc9py-0.2.0/src/mc9/backends/__init__.py +20 -0
  48. mc9py-0.2.0/src/mc9/backends/base.py +62 -0
  49. mc9py-0.2.0/src/mc9/backends/linux_wine.py +188 -0
  50. mc9py-0.2.0/src/mc9/backends/windows.py +292 -0
  51. mc9py-0.2.0/src/mc9/catalog.py +101 -0
  52. mc9py-0.2.0/src/mc9/cir.py +156 -0
  53. mc9py-0.2.0/src/mc9/cli.py +126 -0
  54. mc9py-0.2.0/src/mc9/config.py +19 -0
  55. mc9py-0.2.0/src/mc9/layout.py +41 -0
  56. mc9py-0.2.0/src/mc9/library.py +142 -0
  57. mc9py-0.2.0/src/mc9/measure.py +153 -0
  58. mc9py-0.2.0/src/mc9/netlist.py +102 -0
  59. mc9py-0.2.0/src/mc9/results.py +101 -0
  60. mc9py-0.2.0/src/mc9/schematic.py +505 -0
  61. mc9py-0.2.0/src/mc9/server.py +262 -0
  62. mc9py-0.2.0/src/mc9/sources.py +26 -0
  63. mc9py-0.2.0/src/mc9/templates/base.cir +1609 -0
  64. mc9py-0.2.0/src/mc9/ui.py +86 -0
  65. mc9py-0.2.0/src/mc9/workspace.py +57 -0
  66. mc9py-0.2.0/tests/conftest.py +12 -0
  67. mc9py-0.2.0/tests/test_api_numeric.py +51 -0
  68. mc9py-0.2.0/tests/test_autoplace.py +66 -0
  69. mc9py-0.2.0/tests/test_cir_results.py +71 -0
  70. mc9py-0.2.0/tests/test_integration.py +72 -0
  71. mc9py-0.2.0/tests/test_schematic.py +147 -0
mc9py-0.2.0/.gitignore ADDED
@@ -0,0 +1,25 @@
1
+ .venv/
2
+ __pycache__/
3
+ sandbox/prefix-pristine/
4
+ sandbox/prefix-work/
5
+ sandbox/exchange/
6
+ re/*.exe
7
+ re/work/
8
+ re/*.strings.txt
9
+ re/.venv-re/
10
+ re/ghidra-proj/
11
+ re/ghidramcp-dl/
12
+ re/decomp/
13
+ re/test/
14
+ re/*.log
15
+
16
+ # never publish: proprietary binaries / decompiled code / local setup
17
+ re/
18
+ tools/winpy-dl/
19
+ .mcp.json
20
+ sandbox/
21
+ *.exe
22
+ *.dll
23
+ *.packed.exe
24
+ site/
25
+ dist/
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0 - 2026-10-25
4
+ - Windows backend (Win32 API via ctypes), tested by running Windows Python under Wine.
5
+ - Automatic placement: `Netlist` -> placed and routed `Schematic` (backbone + branches, buses, label fallback), verified net-for-net.
6
+ - `Schematic.pin_nets()`, `audit()`, label-aware connectivity (`nets()` joins equal names and all grounds).
7
+ - One package `mc9`; `workspace` paths; `Driver` abstraction; CLI (`mc9 setup | doctor | reset | mcp`).
8
+ - MCP tools `build_netlist` and others; documentation site; CI.
9
+
10
+ ## 0.1.0
11
+ - First version: Linux/Wine sandbox, circuit editing, analyses with numeric results, cursors, native screenshots, `Schematic` builder,
12
+ measurements (bandwidth, Rin, Rout, THD, solver), MCP server.
mc9py-0.2.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DontforgetAntaiku
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.
mc9py-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,276 @@
1
+ Metadata-Version: 2.5
2
+ Name: mc9py
3
+ Version: 0.2.0
4
+ Summary: Python scripting layer for Micro-Cap 9: run analyses, read results, take native screenshots and build schematics from code (Linux + Wine, Windows).
5
+ Project-URL: Homepage, https://github.com/DontforgetAntaiku/mc9py
6
+ Project-URL: Documentation, https://DontforgetAntaiku.github.io/mc9py/
7
+ Project-URL: Issues, https://github.com/DontforgetAntaiku/mc9py/issues
8
+ Project-URL: Changelog, https://github.com/DontforgetAntaiku/mc9py/blob/main/CHANGELOG.md
9
+ Author: DontforgetAntaiku
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: automation,circuit-simulation,education,electronics,mc9,mcp,micro-cap,microcap,spice
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Education
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: Microsoft :: Windows
18
+ Classifier: Operating System :: POSIX :: Linux
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Topic :: Education
25
+ Classifier: Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)
26
+ Requires-Python: >=3.10
27
+ Requires-Dist: pillow>=10.0
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=8; extra == 'dev'
30
+ Requires-Dist: ruff>=0.6; extra == 'dev'
31
+ Provides-Extra: docs
32
+ Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
33
+ Requires-Dist: mkdocs<2,>=1.6; extra == 'docs'
34
+ Requires-Dist: mkdocstrings[python]>=0.26; extra == 'docs'
35
+ Provides-Extra: mcp
36
+ Requires-Dist: mcp>=2.3; extra == 'mcp'
37
+ Provides-Extra: tools
38
+ Requires-Dist: numpy; extra == 'tools'
39
+ Requires-Dist: scipy; extra == 'tools'
40
+ Description-Content-Type: text/markdown
41
+
42
+ <h1 align="center">mc9py</h1>
43
+
44
+ <p align="center">
45
+ <b>Script Micro-Cap 9 from Python.</b><br>
46
+ Open or <i>describe</i> a circuit, run analyses, get the numbers, and take screenshots that are <b>MC9's own pictures</b>.<br>
47
+ Linux (sandboxed Wine) · Windows · AI-ready (MCP)
48
+ </p>
49
+
50
+ <p align="center">
51
+ <a href="https://github.com/DontforgetAntaiku/mc9py/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/DontforgetAntaiku/mc9py/actions/workflows/ci.yml/badge.svg"></a>
52
+ <a href="https://DontforgetAntaiku.github.io/mc9py/"><img alt="docs" src="https://img.shields.io/badge/docs-GitHub%20Pages-blue"></a>
53
+ <a href="https://pypi.org/project/mc9py/"><img alt="PyPI" src="https://img.shields.io/pypi/v/mc9py"></a>
54
+ <img alt="Python" src="https://img.shields.io/badge/python-3.10%E2%80%933.13-blue">
55
+ <a href="LICENSE"><img alt="MIT" src="https://img.shields.io/badge/license-MIT-green"></a>
56
+ </p>
57
+
58
+ <p align="center">
59
+ <img src="docs/assets/ce_schematic_dc.png" width="48%" alt="common-emitter stage, drawn by mc9 and simulated by MC9">
60
+ <img src="docs/assets/ce_ac_cursors.png" width="48%" alt="MC9's own AC plot with cursors on the band edges">
61
+ </p>
62
+
63
+ ---
64
+
65
+ ## Why
66
+
67
+ Micro-Cap 9 is a fast, capable circuit simulator that many universities still teach with - but it has **no scripting interface**:
68
+ every lab means clicking through the same dialogs, reading values off cursors and pasting screenshots. `mc9py` automates exactly
69
+ that, **using MC9 itself**, so results and pictures are the ones your teacher expects.
70
+
71
+ - 📷 **Native pictures.** Plots and schematics are screenshots of MC9 - its grid, fonts, cursor tables and voltage boxes. Nothing is re-plotted.
72
+ - 🔢 **Real numbers.** Every value is parsed from MC9's own numeric output: operating points, AC / transient / DC tables, THD, Rin, Rout ...
73
+ - ✏️ **Circuits from code.** Describe a circuit like a SPICE netlist and get a *placed, routed, collision-free* MC9 schematic; or place parts by hand.
74
+ - 🛡️ **Safe by design.** On Linux MC9 runs in a bubblewrap sandbox: no network, no access to your files. Your circuits are copied in, never modified.
75
+ - 🪟 **Windows and Linux.** Native Win32 driver on Windows, sandboxed Wine on Linux. One API.
76
+ - 🤖 **AI-ready.** A built-in [MCP](https://modelcontextprotocol.io) server lets an assistant build, simulate and photograph circuits for you.
77
+
78
+ ## A 60-second tour
79
+
80
+ ```python
81
+ import mc9
82
+ from mc9 import Netlist, measure, sources
83
+
84
+ n = Netlist() # 1. describe a circuit
85
+ n.V("V1", "in", "0", sources.sine(0.1, 1e3))
86
+ n.R("R1", "in", "out", "1k")
87
+ n.C("C1", "out", "0", "159.155n") # RC low-pass, fc = 1 kHz
88
+ c = n.build("rc") # placed + routed + written for MC9
89
+
90
+ print(c.op().nodes) # 2. DC operating point
91
+ r = c.ac(10, 1e5, 401, ["db(v(out))"]) # 3. AC sweep -> numbers
92
+ bw = measure.bandwidth(c, "db(v(out))", cursors=True) # 4. -3 dB point, MC9's cursors placed on it
93
+ print(f"{bw.f_high:.1f} Hz") # 998 Hz
94
+
95
+ c.shot("rc_ac.png") # 5. MC9's own plot, cursor table included
96
+ c.dynamic_dc(25); c.shot("rc_dc.png", "schematic") # 6. schematic with node voltages
97
+ ```
98
+
99
+ Working on an existing lab file? `c = mc9.open("my_lab/amplifier.cir")` copies it into the work folder; then `c.parts()`,
100
+ `c.set("R2", "RESISTANCE", "180k")`, `c.ac(...)`, `c.cursors(...)`, `c.shot(...)`, `c.export(...)` (writes a *new* file).
101
+
102
+ ## Install
103
+
104
+ ### Step 1 - install the Python package
105
+
106
+ You need **Python 3.10 or newer** and **git**. `pip` is Python's package installer; it comes with Python. mc9py is **not on PyPI yet**
107
+ (so `pip install mc9py` does not work yet) - install it straight from GitHub. Use a *virtual environment*, a private folder for
108
+ Python packages that keeps your system clean:
109
+
110
+ <details open><summary><b>Linux / macOS</b></summary>
111
+
112
+ ```bash
113
+ python3 -m venv ~/mc9-env # create the environment once
114
+ source ~/mc9-env/bin/activate # activate it (repeat in every new terminal)
115
+ pip install "git+https://github.com/DontforgetAntaiku/mc9py.git"
116
+ mc9 doctor # prints what is installed and what is missing
117
+ ```
118
+ </details>
119
+
120
+ <details><summary><b>Windows (PowerShell)</b></summary>
121
+
122
+ ```powershell
123
+ py -m venv $HOME\mc9-env # create the environment once
124
+ & $HOME\mc9-env\Scripts\Activate.ps1 # activate it (repeat in every new terminal)
125
+ pip install "git+https://github.com/DontforgetAntaiku/mc9py.git"
126
+ mc9 doctor
127
+ ```
128
+ </details>
129
+
130
+ Want `mc9` available in every terminal without activating anything? Use [pipx](https://pipx.pypa.io) instead:
131
+ `pipx install "git+https://github.com/DontforgetAntaiku/mc9py.git"`.
132
+ For development: `git clone https://github.com/DontforgetAntaiku/mc9py && cd mc9py && pip install -e ".[dev]"`.
133
+ Once the project is published on PyPI, `pip install mc9py` will do the same.
134
+
135
+ ### Step 2 - connect MC9
136
+
137
+ <details open><summary><b>Linux</b> (MC9 runs in a sandbox: Wine + virtual display)</summary>
138
+
139
+ ```bash
140
+ # 1. system packages: wine, bubblewrap, Xvfb, xdotool, ImageMagick (package names for Arch / Debian / Fedora: see the docs)
141
+ # 2. install MC9 once into a Wine prefix (the default ~/.wine is fine)
142
+ WINEPREFIX=~/.wine wine /path/to/mc9-setup.exe
143
+ # 3. create the sandbox snapshot (links to your home folders are removed from the copy)
144
+ mc9 setup ~/.wine
145
+ mc9 doctor # everything should say [ok]
146
+ ```
147
+ </details>
148
+
149
+ <details><summary><b>Windows</b> (MC9 is driven natively)</summary>
150
+
151
+ `mc9 doctor` finds `mc9.exe` in the usual install folders. If yours is elsewhere, tell the library once at the top of your script:
152
+ `mc9.config.mc9_exe = r"D:\Tools\MC9\mc9.exe"`. Use 100 % display scaling and keep the keyboard and mouse free while a script runs.
153
+ More in the [Windows page](https://dontforgetantaiku.github.io/mc9py/getting-started/install-windows/).
154
+ </details>
155
+
156
+ ## What it can do
157
+
158
+ | Area | Features |
159
+ |---|---|
160
+ | **Circuits** | open (copy) `.cir` files · list / get / set part values · raw `[Limits]` and curve editing · export to a *new* file · display toggles (voltages/currents/power) |
161
+ | **Analyses** | operating point · AC (log sweep) · transient (steady-state windows) · DC sweep (temperature lists, several runs) · Distortion window · Dynamic DC · Dynamic AC phasors |
162
+ | **Data** | `Result`/`Run`/`OP`: `value_at`, `cross`, `peak`, `trough`, `amplitude`, `mean`, CSV export · device tables (`IC`, `GM`, `RPI`, power ...) · SI-suffix parsing, `N/A` handling |
163
+ | **Pictures** | plot / schematic / window screenshots · tight automatic crops · cursors placed at exact X values with MC9's own cursor table · maximized plot windows · failure screenshots with MC9's error dialog |
164
+ | **Measurements** | `bandwidth` (-3 dB, low/high/band-pass) · `gain_at` · `rin` · `rout` (load removal) · `thd` (steady-state DFT) · `solve` (find the part value that hits a target) |
165
+ | **Schematics** | `Schematic` builder (catalog: R C L V VB I D Q QP M OPAMP GND) · automatic label placement · `check()` / `audit()` / `pin_nets()` · auto centre & zoom · T-junction and node-name handling |
166
+ | **Auto-placement** | SPICE-like `Netlist` → backbone + branches + rail/ground buses, label fallback to avoid crossings · verified net-for-net against your netlist · starter circuits in `mc9.library` |
167
+ | **Platforms** | Linux: sandboxed Wine + Xvfb · Windows: Win32 API (language independent) |
168
+ | **AI** | MCP server with 24 tools (files, analyses, cursors, screenshots, measurements, `build_netlist`, `build_schematic`) |
169
+ | **Tooling** | `mc9 setup / doctor / reset / mcp` · 37 offline tests (run on Linux, Windows, macOS CI) · opt-in MC9 integration tests · MkDocs site · GitHub Actions CI |
170
+
171
+ <p align="center">
172
+ <img src="docs/assets/ce_schematic_ac.png" width="49%" alt="Dynamic AC phasors">
173
+ <img src="docs/assets/inverting_schematic.png" width="49%" alt="inverting op-amp stage placed automatically">
174
+ </p>
175
+ <p align="center">
176
+ <img src="docs/assets/ce_transient.png" width="49%" alt="transient plot">
177
+ <img src="docs/assets/ce_distortion.png" width="49%" alt="MC9 distortion window">
178
+ </p>
179
+
180
+ ## Automatic placement in one picture
181
+
182
+ ```python
183
+ n = mc9.library.ce_amplifier().build("amp") # a common-emitter stage from the starter library
184
+ # or write your own:
185
+ n = Netlist()
186
+ n.V("V1", "src", "0", sources.sine(3.5e-3, 2224)); n.R("R1", "src", "ue", "200"); n.C("C1", "ue", "b", "3.47u")
187
+ n.R("R2", "vcc", "b", "233.2k"); n.Q("Q1", c="col", b="b", e="0", model="BF420"); n.R("R3", "vcc", "col", "1.2k")
188
+ n.C("C3", "col", "ua", "553n"); n.R("R4", "ua", "0", "1.2k"); n.VB("V2", "vcc", "0", "18")
189
+ c = n.build("amp") # VB = 0.695 V, VC = 9.5 V, IC = 7.09 mA - as in the textbook calculation
190
+ ```
191
+
192
+ How the placer works, in short: classify nodes → lay the **signal backbone** left to right → hang **branches** to ground (down) and
193
+ rails (up) → draw **buses** → if wires would cross, that net falls back to **named labels** (MC9 joins equally named nodes) → check
194
+ collisions with MC9's voltage boxes and re-space. Every generated drawing is verified to have exactly the nets of your netlist.
195
+
196
+ ## Use it from an AI assistant
197
+
198
+ This is optional. It lets an AI assistant such as [Claude Code](https://claude.com/claude-code) or Claude Desktop drive MC9 through
199
+ the library. You need the `mcp` extra, and the assistant must be able to *start the `mc9` program*:
200
+
201
+ ```bash
202
+ # 1. install with the extra (inside your activated environment from Step 1)
203
+ pip install "mc9py[mcp] @ git+https://github.com/DontforgetAntaiku/mc9py.git"
204
+
205
+ # 2. find out where the mc9 program lives - you will paste this path below
206
+ which mc9 # Windows PowerShell: (Get-Command mc9).Source
207
+ # e.g. /home/you/mc9-env/bin/mc9 or C:\Users\you\mc9-env\Scripts\mc9.exe
208
+ ```
209
+
210
+ **Claude Code** - run this once in an ordinary terminal (not inside Python), using the path from step 2:
211
+
212
+ ```bash
213
+ claude mcp add microcap9 -- /home/you/mc9-env/bin/mc9 mcp
214
+ claude mcp list # microcap9 should be listed; start `claude` and ask away
215
+ ```
216
+ (If `mc9` is on your `PATH`, e.g. after `pipx install`, plain `claude mcp add microcap9 -- mc9 mcp` works.)
217
+
218
+ **Claude Desktop and other MCP clients** - add this to the client's config file (Claude Desktop: *Settings -> Developer -> Edit Config*;
219
+ file `~/.config/Claude/claude_desktop_config.json` on Linux, `%APPDATA%\Claude\claude_desktop_config.json` on Windows), with the path
220
+ from step 2, then restart the client:
221
+
222
+ ```json
223
+ { "mcpServers": { "microcap9": { "command": "/home/you/mc9-env/bin/mc9", "args": ["mcp"] } } }
224
+ ```
225
+
226
+ > "Build a common-emitter amplifier with a 12 V supply, find its −3 dB band and show me the AC plot with the cursors on the edges."
227
+
228
+ More: [MCP guide](https://dontforgetantaiku.github.io/mc9py/guide/mcp/).
229
+
230
+ ## How it works
231
+
232
+ ```
233
+ your script / AI ─▶ mc9.Circuit · Schematic · Netlist · measure (pure Python)
234
+ │
235
+ circuit-file editor ── numeric-output parser
236
+ │
237
+ ui flows (run, cursors, capture, error screenshots)
238
+ │
239
+ Driver ─┬─ Linux : bubblewrap + Wine + Xvfb + xdotool
240
+ └─ Windows: Win32 API (ctypes)
241
+ │
242
+ MC9 (mc9.exe) ⇄ files in the work folder
243
+ ```
244
+ MC9 has no automation interface, so the library configures everything **in the circuit file**, starts MC9 on it, presses the few
245
+ remaining buttons, reads MC9's numeric-output files and screenshots its window. Details: [architecture](https://DontforgetAntaiku.github.io/mc9py/internals/architecture/).
246
+
247
+ ## Status and honesty
248
+
249
+ - **Linux/Wine** is the best-tested path: developed and verified against the Russian *GUAP Edition* of MC9 9.0.3.
250
+ Other editions/languages need a one-time [calibration](https://DontforgetAntaiku.github.io/mc9py/internals/calibration/) of the button positions.
251
+ - **Windows** driver is language independent (keyboard accelerators + dialog classes). It is exercised by running Windows Python
252
+ under Wine against MC9 (same Win32 calls); **testers on real Windows are very welcome**.
253
+ - Validated on real analyses: divider, RC filter (−3.01 dB at fc), inverting op-amp (20.00 dB), a BF420 common-emitter stage
254
+ (VC = 9.500 V, IC = 7.089 mA, Rin = 635 Ω, Rout = 1119 Ω, THD 8.6 % at 35 mV) - matching hand calculations.
255
+ - A run takes ~15–30 s (MC9 has to start and simulate); sweeps/solvers take minutes.
256
+ - Auto-placement targets teaching circuits (filters, clippers, single-stage amplifiers, op-amp stages); odd topologies fall back to labels.
257
+
258
+ ## Documentation
259
+
260
+ Full guide, API reference, internals and FAQ: **<https://DontforgetAntaiku.github.io/mc9py/>** (sources in [`docs/`](docs/)).
261
+
262
+ ## Contributing
263
+
264
+ Bug reports with `mc9 doctor` output, calibrations for other MC9 editions, Windows test reports, new measurements, catalog parts and
265
+ circuits the placer handles badly are all welcome - see [CONTRIBUTING.md](CONTRIBUTING.md) and the [Code of Conduct](CODE_OF_CONDUCT.md).
266
+ Please **never** commit MC9 binaries, licence keys, decompiled code or other people's circuits.
267
+
268
+ ## License
269
+
270
+ [MIT](LICENSE) © 2026 DontforgetAntaiku.
271
+
272
+ `mc9py` is an independent project. **Micro-Cap® is a trademark of Spectrum Software**; this project is not affiliated with, endorsed
273
+ by or sponsored by Spectrum Software, and it **does not contain or distribute MC9** - you need your own licensed copy and must follow its
274
+ license terms. The circuit template bundled with the package holds only the small shape and pin descriptions that MC9 itself writes into
275
+ every circuit it saves. Third-party libraries: [Pillow](https://python-pillow.org) (HPND), [`mcp`](https://github.com/modelcontextprotocol/python-sdk)
276
+ (MIT, optional), MkDocs Material (MIT, docs only).
mc9py-0.2.0/README.md ADDED
@@ -0,0 +1,235 @@
1
+ <h1 align="center">mc9py</h1>
2
+
3
+ <p align="center">
4
+ <b>Script Micro-Cap 9 from Python.</b><br>
5
+ Open or <i>describe</i> a circuit, run analyses, get the numbers, and take screenshots that are <b>MC9's own pictures</b>.<br>
6
+ Linux (sandboxed Wine) · Windows · AI-ready (MCP)
7
+ </p>
8
+
9
+ <p align="center">
10
+ <a href="https://github.com/DontforgetAntaiku/mc9py/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/DontforgetAntaiku/mc9py/actions/workflows/ci.yml/badge.svg"></a>
11
+ <a href="https://DontforgetAntaiku.github.io/mc9py/"><img alt="docs" src="https://img.shields.io/badge/docs-GitHub%20Pages-blue"></a>
12
+ <a href="https://pypi.org/project/mc9py/"><img alt="PyPI" src="https://img.shields.io/pypi/v/mc9py"></a>
13
+ <img alt="Python" src="https://img.shields.io/badge/python-3.10%E2%80%933.13-blue">
14
+ <a href="LICENSE"><img alt="MIT" src="https://img.shields.io/badge/license-MIT-green"></a>
15
+ </p>
16
+
17
+ <p align="center">
18
+ <img src="docs/assets/ce_schematic_dc.png" width="48%" alt="common-emitter stage, drawn by mc9 and simulated by MC9">
19
+ <img src="docs/assets/ce_ac_cursors.png" width="48%" alt="MC9's own AC plot with cursors on the band edges">
20
+ </p>
21
+
22
+ ---
23
+
24
+ ## Why
25
+
26
+ Micro-Cap 9 is a fast, capable circuit simulator that many universities still teach with - but it has **no scripting interface**:
27
+ every lab means clicking through the same dialogs, reading values off cursors and pasting screenshots. `mc9py` automates exactly
28
+ that, **using MC9 itself**, so results and pictures are the ones your teacher expects.
29
+
30
+ - 📷 **Native pictures.** Plots and schematics are screenshots of MC9 - its grid, fonts, cursor tables and voltage boxes. Nothing is re-plotted.
31
+ - 🔢 **Real numbers.** Every value is parsed from MC9's own numeric output: operating points, AC / transient / DC tables, THD, Rin, Rout ...
32
+ - ✏️ **Circuits from code.** Describe a circuit like a SPICE netlist and get a *placed, routed, collision-free* MC9 schematic; or place parts by hand.
33
+ - 🛡️ **Safe by design.** On Linux MC9 runs in a bubblewrap sandbox: no network, no access to your files. Your circuits are copied in, never modified.
34
+ - 🪟 **Windows and Linux.** Native Win32 driver on Windows, sandboxed Wine on Linux. One API.
35
+ - 🤖 **AI-ready.** A built-in [MCP](https://modelcontextprotocol.io) server lets an assistant build, simulate and photograph circuits for you.
36
+
37
+ ## A 60-second tour
38
+
39
+ ```python
40
+ import mc9
41
+ from mc9 import Netlist, measure, sources
42
+
43
+ n = Netlist() # 1. describe a circuit
44
+ n.V("V1", "in", "0", sources.sine(0.1, 1e3))
45
+ n.R("R1", "in", "out", "1k")
46
+ n.C("C1", "out", "0", "159.155n") # RC low-pass, fc = 1 kHz
47
+ c = n.build("rc") # placed + routed + written for MC9
48
+
49
+ print(c.op().nodes) # 2. DC operating point
50
+ r = c.ac(10, 1e5, 401, ["db(v(out))"]) # 3. AC sweep -> numbers
51
+ bw = measure.bandwidth(c, "db(v(out))", cursors=True) # 4. -3 dB point, MC9's cursors placed on it
52
+ print(f"{bw.f_high:.1f} Hz") # 998 Hz
53
+
54
+ c.shot("rc_ac.png") # 5. MC9's own plot, cursor table included
55
+ c.dynamic_dc(25); c.shot("rc_dc.png", "schematic") # 6. schematic with node voltages
56
+ ```
57
+
58
+ Working on an existing lab file? `c = mc9.open("my_lab/amplifier.cir")` copies it into the work folder; then `c.parts()`,
59
+ `c.set("R2", "RESISTANCE", "180k")`, `c.ac(...)`, `c.cursors(...)`, `c.shot(...)`, `c.export(...)` (writes a *new* file).
60
+
61
+ ## Install
62
+
63
+ ### Step 1 - install the Python package
64
+
65
+ You need **Python 3.10 or newer** and **git**. `pip` is Python's package installer; it comes with Python. mc9py is **not on PyPI yet**
66
+ (so `pip install mc9py` does not work yet) - install it straight from GitHub. Use a *virtual environment*, a private folder for
67
+ Python packages that keeps your system clean:
68
+
69
+ <details open><summary><b>Linux / macOS</b></summary>
70
+
71
+ ```bash
72
+ python3 -m venv ~/mc9-env # create the environment once
73
+ source ~/mc9-env/bin/activate # activate it (repeat in every new terminal)
74
+ pip install "git+https://github.com/DontforgetAntaiku/mc9py.git"
75
+ mc9 doctor # prints what is installed and what is missing
76
+ ```
77
+ </details>
78
+
79
+ <details><summary><b>Windows (PowerShell)</b></summary>
80
+
81
+ ```powershell
82
+ py -m venv $HOME\mc9-env # create the environment once
83
+ & $HOME\mc9-env\Scripts\Activate.ps1 # activate it (repeat in every new terminal)
84
+ pip install "git+https://github.com/DontforgetAntaiku/mc9py.git"
85
+ mc9 doctor
86
+ ```
87
+ </details>
88
+
89
+ Want `mc9` available in every terminal without activating anything? Use [pipx](https://pipx.pypa.io) instead:
90
+ `pipx install "git+https://github.com/DontforgetAntaiku/mc9py.git"`.
91
+ For development: `git clone https://github.com/DontforgetAntaiku/mc9py && cd mc9py && pip install -e ".[dev]"`.
92
+ Once the project is published on PyPI, `pip install mc9py` will do the same.
93
+
94
+ ### Step 2 - connect MC9
95
+
96
+ <details open><summary><b>Linux</b> (MC9 runs in a sandbox: Wine + virtual display)</summary>
97
+
98
+ ```bash
99
+ # 1. system packages: wine, bubblewrap, Xvfb, xdotool, ImageMagick (package names for Arch / Debian / Fedora: see the docs)
100
+ # 2. install MC9 once into a Wine prefix (the default ~/.wine is fine)
101
+ WINEPREFIX=~/.wine wine /path/to/mc9-setup.exe
102
+ # 3. create the sandbox snapshot (links to your home folders are removed from the copy)
103
+ mc9 setup ~/.wine
104
+ mc9 doctor # everything should say [ok]
105
+ ```
106
+ </details>
107
+
108
+ <details><summary><b>Windows</b> (MC9 is driven natively)</summary>
109
+
110
+ `mc9 doctor` finds `mc9.exe` in the usual install folders. If yours is elsewhere, tell the library once at the top of your script:
111
+ `mc9.config.mc9_exe = r"D:\Tools\MC9\mc9.exe"`. Use 100 % display scaling and keep the keyboard and mouse free while a script runs.
112
+ More in the [Windows page](https://dontforgetantaiku.github.io/mc9py/getting-started/install-windows/).
113
+ </details>
114
+
115
+ ## What it can do
116
+
117
+ | Area | Features |
118
+ |---|---|
119
+ | **Circuits** | open (copy) `.cir` files · list / get / set part values · raw `[Limits]` and curve editing · export to a *new* file · display toggles (voltages/currents/power) |
120
+ | **Analyses** | operating point · AC (log sweep) · transient (steady-state windows) · DC sweep (temperature lists, several runs) · Distortion window · Dynamic DC · Dynamic AC phasors |
121
+ | **Data** | `Result`/`Run`/`OP`: `value_at`, `cross`, `peak`, `trough`, `amplitude`, `mean`, CSV export · device tables (`IC`, `GM`, `RPI`, power ...) · SI-suffix parsing, `N/A` handling |
122
+ | **Pictures** | plot / schematic / window screenshots · tight automatic crops · cursors placed at exact X values with MC9's own cursor table · maximized plot windows · failure screenshots with MC9's error dialog |
123
+ | **Measurements** | `bandwidth` (-3 dB, low/high/band-pass) · `gain_at` · `rin` · `rout` (load removal) · `thd` (steady-state DFT) · `solve` (find the part value that hits a target) |
124
+ | **Schematics** | `Schematic` builder (catalog: R C L V VB I D Q QP M OPAMP GND) · automatic label placement · `check()` / `audit()` / `pin_nets()` · auto centre & zoom · T-junction and node-name handling |
125
+ | **Auto-placement** | SPICE-like `Netlist` → backbone + branches + rail/ground buses, label fallback to avoid crossings · verified net-for-net against your netlist · starter circuits in `mc9.library` |
126
+ | **Platforms** | Linux: sandboxed Wine + Xvfb · Windows: Win32 API (language independent) |
127
+ | **AI** | MCP server with 24 tools (files, analyses, cursors, screenshots, measurements, `build_netlist`, `build_schematic`) |
128
+ | **Tooling** | `mc9 setup / doctor / reset / mcp` · 37 offline tests (run on Linux, Windows, macOS CI) · opt-in MC9 integration tests · MkDocs site · GitHub Actions CI |
129
+
130
+ <p align="center">
131
+ <img src="docs/assets/ce_schematic_ac.png" width="49%" alt="Dynamic AC phasors">
132
+ <img src="docs/assets/inverting_schematic.png" width="49%" alt="inverting op-amp stage placed automatically">
133
+ </p>
134
+ <p align="center">
135
+ <img src="docs/assets/ce_transient.png" width="49%" alt="transient plot">
136
+ <img src="docs/assets/ce_distortion.png" width="49%" alt="MC9 distortion window">
137
+ </p>
138
+
139
+ ## Automatic placement in one picture
140
+
141
+ ```python
142
+ n = mc9.library.ce_amplifier().build("amp") # a common-emitter stage from the starter library
143
+ # or write your own:
144
+ n = Netlist()
145
+ n.V("V1", "src", "0", sources.sine(3.5e-3, 2224)); n.R("R1", "src", "ue", "200"); n.C("C1", "ue", "b", "3.47u")
146
+ n.R("R2", "vcc", "b", "233.2k"); n.Q("Q1", c="col", b="b", e="0", model="BF420"); n.R("R3", "vcc", "col", "1.2k")
147
+ n.C("C3", "col", "ua", "553n"); n.R("R4", "ua", "0", "1.2k"); n.VB("V2", "vcc", "0", "18")
148
+ c = n.build("amp") # VB = 0.695 V, VC = 9.5 V, IC = 7.09 mA - as in the textbook calculation
149
+ ```
150
+
151
+ How the placer works, in short: classify nodes → lay the **signal backbone** left to right → hang **branches** to ground (down) and
152
+ rails (up) → draw **buses** → if wires would cross, that net falls back to **named labels** (MC9 joins equally named nodes) → check
153
+ collisions with MC9's voltage boxes and re-space. Every generated drawing is verified to have exactly the nets of your netlist.
154
+
155
+ ## Use it from an AI assistant
156
+
157
+ This is optional. It lets an AI assistant such as [Claude Code](https://claude.com/claude-code) or Claude Desktop drive MC9 through
158
+ the library. You need the `mcp` extra, and the assistant must be able to *start the `mc9` program*:
159
+
160
+ ```bash
161
+ # 1. install with the extra (inside your activated environment from Step 1)
162
+ pip install "mc9py[mcp] @ git+https://github.com/DontforgetAntaiku/mc9py.git"
163
+
164
+ # 2. find out where the mc9 program lives - you will paste this path below
165
+ which mc9 # Windows PowerShell: (Get-Command mc9).Source
166
+ # e.g. /home/you/mc9-env/bin/mc9 or C:\Users\you\mc9-env\Scripts\mc9.exe
167
+ ```
168
+
169
+ **Claude Code** - run this once in an ordinary terminal (not inside Python), using the path from step 2:
170
+
171
+ ```bash
172
+ claude mcp add microcap9 -- /home/you/mc9-env/bin/mc9 mcp
173
+ claude mcp list # microcap9 should be listed; start `claude` and ask away
174
+ ```
175
+ (If `mc9` is on your `PATH`, e.g. after `pipx install`, plain `claude mcp add microcap9 -- mc9 mcp` works.)
176
+
177
+ **Claude Desktop and other MCP clients** - add this to the client's config file (Claude Desktop: *Settings -> Developer -> Edit Config*;
178
+ file `~/.config/Claude/claude_desktop_config.json` on Linux, `%APPDATA%\Claude\claude_desktop_config.json` on Windows), with the path
179
+ from step 2, then restart the client:
180
+
181
+ ```json
182
+ { "mcpServers": { "microcap9": { "command": "/home/you/mc9-env/bin/mc9", "args": ["mcp"] } } }
183
+ ```
184
+
185
+ > "Build a common-emitter amplifier with a 12 V supply, find its −3 dB band and show me the AC plot with the cursors on the edges."
186
+
187
+ More: [MCP guide](https://dontforgetantaiku.github.io/mc9py/guide/mcp/).
188
+
189
+ ## How it works
190
+
191
+ ```
192
+ your script / AI ─▶ mc9.Circuit · Schematic · Netlist · measure (pure Python)
193
+ │
194
+ circuit-file editor ── numeric-output parser
195
+ │
196
+ ui flows (run, cursors, capture, error screenshots)
197
+ │
198
+ Driver ─┬─ Linux : bubblewrap + Wine + Xvfb + xdotool
199
+ └─ Windows: Win32 API (ctypes)
200
+ │
201
+ MC9 (mc9.exe) ⇄ files in the work folder
202
+ ```
203
+ MC9 has no automation interface, so the library configures everything **in the circuit file**, starts MC9 on it, presses the few
204
+ remaining buttons, reads MC9's numeric-output files and screenshots its window. Details: [architecture](https://DontforgetAntaiku.github.io/mc9py/internals/architecture/).
205
+
206
+ ## Status and honesty
207
+
208
+ - **Linux/Wine** is the best-tested path: developed and verified against the Russian *GUAP Edition* of MC9 9.0.3.
209
+ Other editions/languages need a one-time [calibration](https://DontforgetAntaiku.github.io/mc9py/internals/calibration/) of the button positions.
210
+ - **Windows** driver is language independent (keyboard accelerators + dialog classes). It is exercised by running Windows Python
211
+ under Wine against MC9 (same Win32 calls); **testers on real Windows are very welcome**.
212
+ - Validated on real analyses: divider, RC filter (−3.01 dB at fc), inverting op-amp (20.00 dB), a BF420 common-emitter stage
213
+ (VC = 9.500 V, IC = 7.089 mA, Rin = 635 Ω, Rout = 1119 Ω, THD 8.6 % at 35 mV) - matching hand calculations.
214
+ - A run takes ~15–30 s (MC9 has to start and simulate); sweeps/solvers take minutes.
215
+ - Auto-placement targets teaching circuits (filters, clippers, single-stage amplifiers, op-amp stages); odd topologies fall back to labels.
216
+
217
+ ## Documentation
218
+
219
+ Full guide, API reference, internals and FAQ: **<https://DontforgetAntaiku.github.io/mc9py/>** (sources in [`docs/`](docs/)).
220
+
221
+ ## Contributing
222
+
223
+ Bug reports with `mc9 doctor` output, calibrations for other MC9 editions, Windows test reports, new measurements, catalog parts and
224
+ circuits the placer handles badly are all welcome - see [CONTRIBUTING.md](CONTRIBUTING.md) and the [Code of Conduct](CODE_OF_CONDUCT.md).
225
+ Please **never** commit MC9 binaries, licence keys, decompiled code or other people's circuits.
226
+
227
+ ## License
228
+
229
+ [MIT](LICENSE) © 2026 DontforgetAntaiku.
230
+
231
+ `mc9py` is an independent project. **Micro-Cap® is a trademark of Spectrum Software**; this project is not affiliated with, endorsed
232
+ by or sponsored by Spectrum Software, and it **does not contain or distribute MC9** - you need your own licensed copy and must follow its
233
+ license terms. The circuit template bundled with the package holds only the small shape and pin descriptions that MC9 itself writes into
234
+ every circuit it saves. Third-party libraries: [Pillow](https://python-pillow.org) (HPND), [`mcp`](https://github.com/modelcontextprotocol/python-sdk)
235
+ (MIT, optional), MkDocs Material (MIT, docs only).
Binary file
@@ -0,0 +1 @@
1
+ --8<-- "CHANGELOG.md"
@@ -0,0 +1 @@
1
+ --8<-- "CONTRIBUTING.md"
@@ -0,0 +1,35 @@
1
+ # FAQ and gotchas
2
+
3
+ ## Does it modify my circuits?
4
+ No. `mc9.open()` copies the file into the work folder; `Circuit.export()` writes to a new path and refuses to overwrite.
5
+
6
+ ## My band edge differs from what I read with MC9's cursors.
7
+ With MC9's default AC `Sweep type = Auto` the numeric table is coarse and linear, and cursors interpolate between its points - band
8
+ edges can be off by more than 10 %. `mc9` always sweeps logarithmically with 401+ points. Double `points` to confirm convergence.
9
+
10
+ ## "Node has no DC path to ground" / "label not found" / "model missing"
11
+ These are MC9's own error dialogs. When a run fails the library saves `<circuit>_<analysis>_FAILED.png`; read the dialog in it.
12
+ Typical causes: a node connected only through capacitors; a curve like `v(Out)` for a node that is not named; a model name that
13
+ is not in MC9's library.
14
+
15
+ ## Why are voltage boxes overlapping each other in my schematic screenshot?
16
+ MC9 draws them (centred on a pin of each node) and AC boxes are ~12 grid units wide. Space voltage nodes >= 14 grid units apart and
17
+ build with `labels="ac"`. `Schematic.audit("ac")` lists the collisions before you run anything.
18
+
19
+ ## Why is THD computed by a DFT and not taken from MC9's Distortion analysis?
20
+ MC9's distortion *numeric* table is a corrupted FFT buffer under Wine. The Distortion *window* is fine, so `c.distortion()` plus
21
+ `c.shot()` gives MC9's own figure, while `measure.thd` gives numbers.
22
+
23
+ ## Cursor tables are cut off at the bottom.
24
+ MC9 clips the lowest table when plots are stacked. Use one plot per page for figures with cursors.
25
+
26
+ ## Can I use it without a display / on a server?
27
+ On Linux yes - the display is virtual (Xvfb). On Windows MC9 needs a desktop session.
28
+
29
+ ## Does it work with the standard English MC9?
30
+ The Windows backend does not depend on the language. The Linux backend needs a one-time calibration for editions other than the
31
+ Russian GUAP build; see [Supporting other MC9 editions](internals/calibration.md). Reports are welcome.
32
+
33
+ ## Is it legal to automate MC9?
34
+ `mc9py` only drives your own licensed copy through its normal user interface and files. It contains no MC9 code or binaries.
35
+ The component definitions in `mc9/templates/base.cir` are the small shape/pin descriptions that MC9 itself writes into every circuit it saves.