Skip to main content

netlistmod

netlistmod is a source-preserving SPICE netlist editing library. Its goal is to make permitted value and directive edits while preserving the original text and circuit topology.

Supported dialects

The caller always selects the dialect; there is no default and no detection.

Dialect Dialect Input Elements Reference Validated on
ngspice NGSPICE .cir, .sp, .net, KiCad exports R, C, L, K, V, I, D, X, Q, M, J, Z, E, F, G, H, S, W, B, T, O, U (URC), Y, P, A (code models) and N (OSDI), with the expression, TABLE, POLY, FREQ and gate forms ngspice manual ngspice 47
LTspice LTSPICE .net, .cir (an .asc schematic is exported first) R, C, L, K, V, I, D, X, Q, M, J, Z, E, F, G, H, S, W, B, T, O, U, A (special functions), @ and &, with the expression, table=, POLY and Laplace= forms ltspice-reference LTspice 26.1.1, Windows

Where a solver and the library differ, the file is docs/grammars/<dialect>/discrepancies.md. Every device letter is supported. Two constructs are out of scope for v1 and raise UnsupportedConstruct: the ngspice digital U (a U line that is not a URC line), whose libraries need PSpice compatibility mode, and LTspice's .machine (decision 0020).

Quick start

pip install netlistmod

To work on the library itself, clone it and run uv sync.

>>> from pathlib import Path
>>> from tempfile import TemporaryDirectory
>>> from netlistmod import Dialect, Netlist
>>> folder = TemporaryDirectory()
>>> path = Path(folder.name) / "divider.cir"
>>> _ = path.write_bytes(b"divider\nV1 in 0 DC 3\nR1 in out 1k ; top\nR2 out 0 1k\n.op\n.end\n")

>>> netlist = Netlist.load(path, dialect=Dialect.NGSPICE)
>>> edited = netlist.set_value("R2", "3k").directives.set(".tran 1u 5u")
>>> edited.save()
>>> print(path.read_text(), end="")
divider
V1 in 0 DC 3
R1 in out 1k ; top
R2 out 0 3k
.op
.tran 1u 5u
.end
>>> folder.cleanup()

Every edit returns a new netlist that has been re-parsed and checked against the topology of the original. save() changes only the edited text: comments, spacing, line endings and encoding stay as they were. For the whole cycle with a solver, see edit_and_simulate.py.

Import everything from netlistmod (netlistmod.__all__ is the public API); its submodules are internal.

What it does and does not do

  • Reads titles, comments, every device letter of both dialects, .param, .model, .subckt, .global, the analysis, option and output directives, and LTspice's .step, into typed nodes with exact source spans. It answers queries about lines, references, nets and connections.
  • Edits values, formulas and behavioural expressions (set_value, set_formula, set_expression, remove_value); instance and model parameters (set_param, set_instance_param, set_model_param, remove_param, remove_model_param); an element's model (set_model); a source's DC and AC values and its function (set_dc, set_ac, set_stimulus, set_stimulus_arg, remove_stimulus); a coupling (set_coupling), a table (set_table), POLY coefficients (set_poly_coefficients) and a switch's state (set_switch_state); .param lines (params) and directives (directives); and adds an .include (add_include).
  • Preserves other ngspice dot-commands verbatim. On ngspice, .control, .if, .include and .lib are opaque: their contents are not read. On LTspice, .include and .lib are opaque, and the dot-commands are a closed list: any other, .control and .if among them, is a ParseError.
  • Never changes topology (elements, nodes, subcircuit ports), evaluates a value, or launches a solver.
  • Refuses loudly. A line outside the grammar is an error, not a guess. A construct outside v1 (the ngspice digital U, LTspice .machine) raises UnsupportedConstruct.

Status

The library is feature complete for v1: every device letter of both dialects is supported, and both dialects are validated on their solvers. The current release is 1.0.0, and from it the project follows SemVer. The public API is the names in netlistmod.__all__; what SemVer covers and how a name is deprecated are in compatibility and versioning.

Supported platforms are Linux and Windows, with Python 3.13 or newer. LTspice validation runs on Windows. macOS is not tested.

Metadata

Release files for netlistmod 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for netlistmod 1.0.0
File Size Uploaded Provenance Actions
netlistmod-1.0.0.tar.gz 148.6 kB With provenance Details for netlistmod-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for netlistmod 1.0.0
File Interpreter ABI Platform Actions
netlistmod-1.0.0-py3-none-any.whl Python 3 none any Details for netlistmod-1.0.0-py3-none-any.whl

Total release size: 332.0 kB

Release files / netlistmod-1.0.0.tar.gz

Download URL netlistmod-1.0.0.tar.gz
Size 148.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b0e96f89ca64a8f51d9476340c543c5ba01449c9f75865552412f12d938dbc81
BLAKE2b-256 checksum
How to use checksums
20ce3360d97a74ce8574d7a0e4c20c4474de409090b6408b389bf28715852e07
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 Nov 15, 2026.

Transparency log

Release files / netlistmod-1.0.0-py3-none-any.whl

Download URL netlistmod-1.0.0-py3-none-any.whl
Size 183.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
297d2111c6379a1bdd1dbdcace0026a6e6e68476cbddbd7fd0bf5f2716d815ce
BLAKE2b-256 checksum
How to use checksums
5a9eb87d64b2de9571f9ca6a477161e1a4b27a482b4a2bf38e6c06aba7333eaa
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 Nov 15, 2026.

Transparency log

Security for netlistmod 1.0.0

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for netlistmod-1.0.0.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 Nov 15, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page