SpiceSharpParser parses SPICE netlists and translates them into ordinary SpiceSharp circuits and simulations. It supports broad SPICE, PSpice, and LTspice syntax for .NET Standard 2.0 and .NET 8.0.
Current release: 3.4.1 is a hardening-only release for experimental
LTspice A-device integration. It adds fixes and regression coverage without
adding new A-device families.
For the complete feature and API reference, see the detailed project guide.
- Parse
.AC,.DC,.TRAN,.OP, and.NOISEanalyses. - Translate netlists into normal SpiceSharp circuits and simulation objects.
- Load recursive
.INCLUDE/.LIBdependencies with source-located diagnostics. - Use
.SAVE,.PRINT,.PLOT,.MEAS, and.FOURresults from the netlist. - Load reusable
.SUBCKTlibraries into programmatically assembled circuits. - Opt into LTspice A-devices, ideal diodes, nonlinear passives, digital logic, analog functional models, and a functional 555 with the companion package.
Install the core parser:
dotnet add package SpiceSharp-ParserInstall the optional models only when they are needed:
dotnet add package SpiceSharpParser.CustomComponents| Requirement | Package |
|---|---|
| Parse and simulate ordinary SPICE netlists | SpiceSharp-Parser |
Load user-authored .SUBCKT libraries |
SpiceSharp-Parser |
| Parse supported LTspice A-devices and ideal/nonlinear devices | SpiceSharpParser.CustomComponents |
| Use packaged digital, analog, and functional 555 models | SpiceSharpParser.CustomComponents |
See the CustomComponents README for setup, model explanations, examples, and compatibility limits.
The original API exposes parsing, translation, and simulation as separate steps:
using System;
using System.Linq;
using SpiceSharpParser;
using SpiceSharpParser.Common;
var netlist = string.Join(Environment.NewLine,
"Low-pass RC filter",
"V1 IN 0 AC 1",
"R1 IN OUT 1k",
"C1 OUT 0 1u",
".AC DEC 10 1 1MEG",
".SAVE V(OUT)",
".END");
// Parse the SPICE text.
var parser = new SpiceNetlistParser();
var parsed = parser.ParseNetlist(netlist);
// Translate it into SpiceSharp objects.
var reader = new SpiceSharpReader();
var model = reader.Read(parsed.FinalModel);
// Run the analysis and read the requested export.
var simulation = model.Simulations.Single();
var output = model.Exports.Find(export => export.Name == "V(OUT)");
simulation.EventExportData += (_, _) => Console.WriteLine(output.Extract());
simulation.Execute(model.Circuit);| Goal | API |
|---|---|
| Direct control over an in-memory netlist | SpiceNetlistParser, then SpiceSharpReader |
| Compile user or vendor files with stable diagnostics | SpiceCompiler.CompileFile(...) |
Load selected .SUBCKT definitions into a circuit |
SpiceSubcircuitLibrary.LoadFile(...) or LoadText(...) |
| Enable optional netlist components in the original API | reader.Settings.UseCustomComponents() before Read() |
Enable optional components with SpiceCompiler |
SpiceCompileOptions.ConfigureReader |
SpiceCompiler adds recursive dependency loading, recovery, compatibility
classification, structural linting, and JSON/SARIF diagnostic output. See the
detailed project guide and
diagnostic reference.
SpiceSharpParser.CustomComponents supports these native eight-terminal
A-device families:
| Digital | Analog and mixed-signal |
|---|---|
SRFLOP, DFLOP, PHASEDET, COUNTER |
SAMPLEHOLD, OTA, VARISTOR, MODULATOR/MODULATE |
Terminal 8 is common. A terminal is unused only when it repeats that common
node; if common is not ground, a literal 0 remains an active global-ground
connection. Unused outputs are detached, and an unused MODULATOR amplitude
input selects the native amplitude of 1.
Complete netlists, .SAVE/.PLOT waveforms, .MEAS checks, and guides are in
the runnable A-device example pack.
The Circuit Cookbook turns parser features into complete, practical designs. Every recipe includes a runnable netlist, named measurements, design calculations, an accessible generated schematic, a response summary, suggested experiments, and automated regression coverage.
| Difficulty | Circuit | Main lesson |
|---|---|---|
| Simple | PWM digital-to-analog converter | Duty-cycle averaging, ripple attenuation, and settling |
| Simple | RC sensor filter and input protector | Sensor bandwidth, noise attenuation, rail clamping, and fault current |
| Simple | BJT relay driver | Inductive-load switching, saturation, flyback, and release decay |
| Simple | Loaded voltage divider and emitter-follower buffer | Source loading, Thevenin resistance, transistor buffering, and output impedance |
| Simple | Diode peak detector and AM envelope follower | Diode-drop error, RC attack/release, carrier ripple, and envelope recovery |
| Simple | Two-transistor astable LED flasher | Cross-coupled feedback, RC timing, transistor switching, and free-running oscillation |
| Medium | Rectifier power supply | Rectification, reservoir ripple, Zener regulation, and load response |
| Medium | BJT audio preamplifier | Biasing, AC gain, bandwidth, coupling, loading, and distortion |
| Medium | Active anti-alias filter | Buffered poles, stopband attenuation, settling, and ADC loading |
| Medium | Ideal-diode redundant power input | Supply OR-ing, automatic failover, handback, and reverse-current blocking |
| Difficult | Simple phase-locked loop | Phase detection, loop filtering, voltage-controlled oscillation, and lock behavior |
| Difficult | Transmission-line termination | Propagation delay, reflections, ringing, and impedance matching |
Cookbook schematics are generated from reviewable schematic.toml files with
the repository-local SchemDraw renderer. The cookbook report verifies recipe
structure, netlist/layout consistency, SVG accessibility, and generated-asset
freshness:
.\tools\cookbook-schematic\.venv\Scripts\cookbook-reportRun the simulation and measurement regressions separately:
dotnet test src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj `
--filter 'FullyQualifiedName~CircuitCookbookTests'The former long README reference is split across these focused documents:
| Topic | Document |
|---|---|
| Full project reference | Detailed Project Guide |
| Practical, measured designs | Circuit Cookbook |
| Documentation by statement and device | Documentation Index |
| Parser introduction | Introduction |
| Compiler diagnostics | Diagnostic Reference |
| LTspice compatibility status | Compatibility Matrix |
| Programmatic subcircuit libraries | Subcircuit Library Guide |
| LTspice A-devices | A-device Guide |
| Digital logic and functional 555 | Digital Subcircuits |
| Analog special functions | Analog Subcircuits |
| LTspice-style ideal diode | Ideal Diode |
| Nonlinear capacitors and inductors | Nonlinear Passives |
| Measurements and output | .MEAS, .PRINT, .PLOT |
git clone https://github.com/SpiceSharp/SpiceSharpParser.git
cd SpiceSharpParser
dotnet restore src/SpiceSharp-Parser.sln
dotnet build src/SpiceSharp-Parser.sln
dotnet test src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj
dotnet test src/SpiceSharpParser.IntegrationTests/SpiceSharpParser.IntegrationTests.csprojSpiceSharpParser is licensed under the MIT License.