mc9py
Script Micro-Cap 9 from Python.
Open or describe a circuit, run analyses, get the numbers, and take screenshots that are MC9's own pictures.
Linux (sandboxed Wine) · Windows · AI-ready (MCP)
Why
Micro-Cap 9 is a fast, capable circuit simulator that many universities still teach with - but it has no scripting interface:
every lab means clicking through the same dialogs, reading values off cursors and pasting screenshots. mc9py automates exactly
that, using MC9 itself, so results and pictures are the ones your teacher expects.
- 📷 Native pictures. Plots and schematics are screenshots of MC9 - its grid, fonts, cursor tables and voltage boxes. Nothing is re-plotted.
- 🔢 Real numbers. Every value is parsed from MC9's own numeric output: operating points, AC / transient / DC tables, THD, Rin, Rout ...
- ✏️ Circuits from code. Describe a circuit like a SPICE netlist and get a placed, routed, collision-free MC9 schematic; or place parts by hand.
- 🛡️ 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.
- 🪟 Windows and Linux. Native Win32 driver on Windows, sandboxed Wine on Linux. One API.
- 🤖 AI-ready. A built-in MCP server lets an assistant build, simulate and photograph circuits for you.
A 60-second tour
import mc9
from mc9 import Netlist, measure, sources
n = Netlist() # 1. describe a circuit
n.V("V1", "in", "0", sources.sine(0.1, 1e3))
n.R("R1", "in", "out", "1k")
n.C("C1", "out", "0", "159.155n") # RC low-pass, fc = 1 kHz
c = n.build("rc") # placed + routed + written for MC9
print(c.op().nodes) # 2. DC operating point
r = c.ac(10, 1e5, 401, ["db(v(out))"]) # 3. AC sweep -> numbers
bw = measure.bandwidth(c, "db(v(out))", cursors=True) # 4. -3 dB point, MC9's cursors placed on it
print(f"{bw.f_high:.1f} Hz") # 998 Hz
c.shot("rc_ac.png") # 5. MC9's own plot, cursor table included
c.dynamic_dc(25); c.shot("rc_dc.png", "schematic") # 6. schematic with node voltages
Working on an existing lab file? c = mc9.open("my_lab/amplifier.cir") copies it into the work folder; then c.parts(),
c.set("R2", "RESISTANCE", "180k"), c.ac(...), c.cursors(...), c.shot(...), c.export(...) (writes a new file).
Install
Step 1 - install the Python package
You need Python 3.10 or newer and git. pip is Python's package installer; it comes with Python. Use a virtual environment, a private folder for
Python packages that keeps your system clean:
Linux / macOS
python3 -m venv ~/mc9-env # create the environment once
source ~/mc9-env/bin/activate # activate it (repeat in every new terminal)
pip install mc9py
mc9 doctor # prints what is installed and what is missing
Windows (PowerShell)
py -m venv $HOME\mc9-env # create the environment once
& $HOME\mc9-env\Scripts\Activate.ps1 # activate it (repeat in every new terminal)
pip install mc9py
mc9 doctor
Want mc9 available in every terminal without activating anything? Use pipx instead:
pipx install mc9py.
For development: git clone https://github.com/DontforgetAntaiku/mc9py && cd mc9py && pip install -e ".[dev]".
Step 2 - connect MC9
Linux (MC9 runs in a sandbox: Wine + virtual display)
# 1. system packages: wine, bubblewrap, Xvfb, xdotool, ImageMagick (package names for Arch / Debian / Fedora: see the docs)
# 2. install MC9 once into a Wine prefix (the default ~/.wine is fine)
WINEPREFIX=~/.wine wine /path/to/mc9-setup.exe
# 3. create the sandbox snapshot (links to your home folders are removed from the copy)
mc9 setup ~/.wine
mc9 doctor # everything should say [ok]
Windows (MC9 is driven natively)
mc9 doctor finds mc9.exe in the usual install folders. If yours is elsewhere, tell the library once at the top of your script:
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.
More in the Windows page.
What it can do
| Area | Features |
|---|---|
| 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) |
| Analyses | operating point · AC (log sweep) · transient (steady-state windows) · DC sweep (temperature lists, several runs) · Distortion window · Dynamic DC · Dynamic AC phasors |
| 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 |
| 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 |
| 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) |
| 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 |
| 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 |
| Platforms | Linux: sandboxed Wine + Xvfb · Windows: Win32 API (language independent) |
| AI | MCP server with 24 tools (files, analyses, cursors, screenshots, measurements, build_netlist, build_schematic) |
| 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 |
Automatic placement in one picture
n = mc9.library.ce_amplifier().build("amp") # a common-emitter stage from the starter library
# or write your own:
n = Netlist()
n.V("V1", "src", "0", sources.sine(3.5e-3, 2224)); n.R("R1", "src", "ue", "200"); n.C("C1", "ue", "b", "3.47u")
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")
n.C("C3", "col", "ua", "553n"); n.R("R4", "ua", "0", "1.2k"); n.VB("V2", "vcc", "0", "18")
c = n.build("amp") # VB = 0.695 V, VC = 9.5 V, IC = 7.09 mA - as in the textbook calculation
How the placer works, in short: classify nodes → lay the signal backbone left to right → hang branches to ground (down) and rails (up) → draw buses → if wires would cross, that net falls back to named labels (MC9 joins equally named nodes) → check collisions with MC9's voltage boxes and re-space. Every generated drawing is verified to have exactly the nets of your netlist.
Use it from an AI assistant
This is optional. It lets an AI assistant such as Claude Code or Claude Desktop drive MC9 through
the library. You need the mcp extra, and the assistant must be able to start the mc9 program:
# 1. install with the extra (inside your activated environment from Step 1)
pip install "mc9py[mcp]"
# 2. find out where the mc9 program lives - you will paste this path below
which mc9 # Windows PowerShell: (Get-Command mc9).Source
# e.g. /home/you/mc9-env/bin/mc9 or C:\Users\you\mc9-env\Scripts\mc9.exe
Claude Code - run this once in an ordinary terminal (not inside Python), using the path from step 2:
claude mcp add microcap9 -- /home/you/mc9-env/bin/mc9 mcp
claude mcp list # microcap9 should be listed; start `claude` and ask away
(If mc9 is on your PATH, e.g. after pipx install, plain claude mcp add microcap9 -- mc9 mcp works.)
Claude Desktop and other MCP clients - add this to the client's config file (Claude Desktop: Settings -> Developer -> Edit Config;
file ~/.config/Claude/claude_desktop_config.json on Linux, %APPDATA%\Claude\claude_desktop_config.json on Windows), with the path
from step 2, then restart the client:
{ "mcpServers": { "microcap9": { "command": "/home/you/mc9-env/bin/mc9", "args": ["mcp"] } } }
"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."
More: MCP guide.
How it works
your script / AI ─▶ mc9.Circuit · Schematic · Netlist · measure (pure Python)
│
circuit-file editor ── numeric-output parser
│
ui flows (run, cursors, capture, error screenshots)
│
Driver ─┬─ Linux : bubblewrap + Wine + Xvfb + xdotool
└─ Windows: Win32 API (ctypes)
│
MC9 (mc9.exe) ⇄ files in the work folder
MC9 has no automation interface, so the library configures everything in the circuit file, starts MC9 on it, presses the few remaining buttons, reads MC9's numeric-output files and screenshots its window. Details: architecture.
Status and honesty
- Linux/Wine is the best-tested path: developed and verified against the Russian GUAP Edition of MC9 9.0.3. Other editions/languages need a one-time calibration of the button positions.
- Windows driver is language independent (keyboard accelerators + dialog classes). It is exercised by running Windows Python under Wine against MC9 (same Win32 calls); testers on real Windows are very welcome.
- Validated on real analyses: divider, RC filter (−3.01 dB at fc), inverting op-amp (20.00 dB), a BF420 common-emitter stage (VC = 9.500 V, IC = 7.089 mA, Rin = 635 Ω, Rout = 1119 Ω, THD 8.6 % at 35 mV) - matching hand calculations.
- A run takes ~15–30 s (MC9 has to start and simulate); sweeps/solvers take minutes.
- Auto-placement targets teaching circuits (filters, clippers, single-stage amplifiers, op-amp stages); odd topologies fall back to labels.
Documentation
Full guide, API reference, internals and FAQ: https://DontforgetAntaiku.github.io/mc9py/ (sources in docs/).
Contributing
Bug reports with mc9 doctor output, calibrations for other MC9 editions, Windows test reports, new measurements, catalog parts and
circuits the placer handles badly are all welcome - see CONTRIBUTING.md and the Code of Conduct.
Please never commit MC9 binaries, licence keys, decompiled code or other people's circuits.
License
MIT © 2026 DontforgetAntaiku.
mc9py is an independent project. Micro-Cap® is a trademark of Spectrum Software; this project is not affiliated with, endorsed
by or sponsored by Spectrum Software, and it does not contain or distribute MC9 - you need your own licensed copy and must follow its
license terms. The circuit template bundled with the package holds only the small shape and pin descriptions that MC9 itself writes into
every circuit it saves. Third-party libraries: Pillow (HPND), mcp
(MIT, optional), MkDocs Material (MIT, docs only).
Metadata
Release files for mc9py 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mc9py-0.2.1.tar.gz | 235.0 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mc9py-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 304.8 kB
Release files / mc9py-0.2.1.tar.gz
| Download URL | mc9py-0.2.1.tar.gz |
|---|---|
| Size | 235.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9c1a0d4e7c78502fc30d5187be096e6773beb5fb2e58dcc45d2f89344010fabc
|
|
BLAKE2b-256 checksum How to use checksums |
828ff83d0b8bc118a03b67f744187203222b0414ca372ef584c43af6b9aca81b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.
Transparency logRelease files / mc9py-0.2.1-py3-none-any.whl
| Download URL | mc9py-0.2.1-py3-none-any.whl |
|---|---|
| Size | 69.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0d4379b2ea4ac56b1e8ba8114fccd1eb5713f8394f056881516137a8ba54bd59
|
|
BLAKE2b-256 checksum How to use checksums |
6e15c132efe70c4ee3a5dcaf07208fad2a32a6b85467e9ba471c447a9db91903
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.
Transparency logSecurity for mc9py 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for mc9py-0.2.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.