Skip to main content

PSIM Python API Documentation

File: Psim_Class.py
Author: Altair Engineering Inc.
Requires: PSIM 2026.0 or above (some functions available from earlier versions as noted)


Table of Contents

  1. Overview
  2. Installation & Setup
  3. Data Classes
  4. PSIM Class — Main API
  5. Version Compatibility Reference
  6. Usage Examples

Overview

Psim_Class.py is a Python wrapper around PSIM's native DLL (psim2.dll on Windows, psim2.so on Linux). It allows you to automate PSIM simulations, manipulate schematics, read/write graph files, run scripts, and more — all from Python.


Installation & Setup

Requirements

  • Python 3.x
  • PSIM 2026.0 or above installed (some features work with 2023.1+)
  • Windows or Linux

Importing

from Psim_Class import PSIM, PSIM_SimulateData

Creating the PSIM object

# Auto-detect PSIM path from Windows registry
psim = PSIM("")

# Or specify path explicitly
psim = PSIM(r"C:\Altair\PSIM2026\")

# With a custom stdout callback
def my_callback(message, msg_type, thread_id):
print(f"[{thread_id}] {message.decode()}")

psim = PSIM(r"C:\Altair\PSIM2026\", callback_func1=my_callback)

Note: On Windows, if PsimPath is empty (""), the path is read automatically from the registry key HKCU\SOFTWARE\POWERSIM\Folders64\LASTPATH.


Data Classes

PSIM_curve

Represents a single simulation curve (waveform).

AttributeTypeDescription
NamestrName of the curve/probe
RowsintNumber of data points
Valuesctypes pointerRaw array of double values
Validatectypes pointerValidity flags per sample (0=missing, 1=valid, 2=invalid)

Accessing values:

curve = result.Graph[0] # by index
curve = result.Graph['V_out'] # by name
value = curve[10] # 10th sample value
is_valid = curve.is_valid(10) # check validity
count = len(curve) # number of samples

PSIM_Graph

Container for all curves from a simulation or graph file.

AttributeTypeDescription
curveslist[PSIM_curve]Ordered list of all curves
ResultintResult code
IsErrorintError flag
ErrorMessagestrError description

Accessing curves:

graph = result.Graph
curve0 = graph[0] # by position
curve = graph['Ia'] # by name
exists = 'Vbus' in graph # membership check
val = graph.get_value('Ia', 5, require_valid=True)

PSIM_result

Returned by all simulation and graph-reading functions.

AttributeTypeDescription
Resultint1 = success, 0 = failure
IsErrorint1 if an error occurred
ErrorMessagestrError text if IsError == 1
GraphPSIM_GraphGraph data (populated on success)
result = psim.PsimSimulate("circuit.psimsch", "output.smv")
if result.IsError == 0:
time_curve = result.Graph['Time']
v_out = result.Graph['V_out']

PSIM_Element & PSIM_param

Returned by PsimGetElementList.

PSIM_Element attributes:

AttributeTypeDescription
TypestrElement type (e.g., "Resistor", "Simulation Control")
NamestrElement instance name
IndexintElement index within the schematic
Paramslist[PSIM_param]List of parameters

PSIM_param attributes:

AttributeTypeDescription
NamestrParameter name
ValuestrParameter value (as string)

PSIM_schematic

A handle to an open schematic file. Returned by PsimFileOpen and PsimFileNew. Automatically closes the file when garbage collected.

sch = psim.PsimFileOpen("circuit.psimsch")
# ... use sch with other functions ...
sch.free() # explicitly close (optional)

PSIM_SimulateData

A data container used to describe one simulation job for PsimASimulate (asynchronous batch simulation).

sd = PSIM_SimulateData(
SchFilePath="circuit.psimsch",
GraphFilePath="output.smv",
SimviewFlag=1, # 0=write+open simview, 1=write only, 5=don't write
NameValueList=["R1", "10", "C1", "1e-6"]
)

You can also build it from helper methods on the PSIM object:

sd = psim.SimulateData_from_dict("circuit.psimsch", "output.smv", {"R1": 10, "simview": 0})
sd = psim.SimulateData_from_kwargs("circuit.psimsch", "output.smv", R1=10, simview=0)

PSIM Class — Main API

Constructor

PSIM(PsimPath: str, callback_func1=None)
ParameterTypeDescription
PsimPathstrPath to PSIM installation folder. Pass "" to auto-detect on Windows.
callback_func1callable or NoneOptional callback for DLL stdout messages. Signature: (bytes, int, int) -> None.

Returns: A PSIM instance. Call psim.IsValid() to confirm loading succeeded.


Version Functions

get_psim_version()

Returns the PSIM version as a tuple.

version = psim.get_psim_version()
# Returns: (major, minor, patch, build) e.g. (2026, 0, 0, 0)

get_psim_version2()

Like get_psim_version() but also returns the vertical (platform) code.

ver = psim.get_psim_version2()
# Returns: (major, minor, patch, build, vertical)
# vertical: 564=Windows GUI, 864=Windows Solver, 800=Linux Solver

get_psim_version_name()

Returns a human-readable version string.

name = psim.get_psim_version_name()
# e.g. "PSIMSolver 2026.0.0.0 (Windows)"

Simulation Functions

PsimSimulate(schFilePath_or_Obj, graphFilePath, **kwargs) -> PSIM_result

Runs a PSIM simulation.

ParameterTypeDescription
schFilePath_or_Objstr or PSIM_schematicPath to .psimsch file or an open schematic handle
graphFilePathstrPath for the output graph file (.smv)
**kwargsOptional parameter overrides and Simview flag

Special kwargs:

KwargValueMeaning
simview1 (default)Write graph and launch Simview
simview0Write graph, do not launch Simview
simview-1Do not write graph, do not launch Simview
Any other keystring/numberOverrides a schematic parameter by name
result = psim.PsimSimulate("boost.psimsch", "boost.smv", simview=0, L1="1e-3", C1="100e-6")
if result.IsError == 0:
print("Simulation OK")
print(result.Graph['V_out'][100])

PsimSimulate_HyperSpice(schFilePath_or_Obj, graphFilePath, **kwargs) -> PSIM_result

Same as PsimSimulate but uses the HyperSpice engine.

result = psim.PsimSimulate_HyperSpice("circuit.psimsch", "output.smv", simview=0)

PsimSimulate_LTSpice(schFilePath_or_Obj, graphFilePath, **kwargs) -> PSIM_result

Same as PsimSimulate but uses the LTSpice engine.

result = psim.PsimSimulate_LTSpice("circuit.psimsch", "output.smv", simview=0)

PsimASimulate(maxThread, simList) -> list[PSIM_result]

Runs multiple simulations asynchronously (in parallel). Useful for parameter sweeps.

ParameterTypeDescription
maxThreadintMaximum number of concurrent simulation threads. 0 or greater than len(simList) means all run concurrently.
simListlist[PSIM_SimulateData]List of simulation jobs to run

Returns: A list of PSIM_result objects in the same order as simList.

jobs = [
PSIM_SimulateData("circuit.psimsch", "out1.smv", 1, ["R1", "10"]),
PSIM_SimulateData("circuit.psimsch", "out2.smv", 1, ["R1", "20"]),
PSIM_SimulateData("circuit.psimsch", "out3.smv", 1, ["R1", "30"]),
]
results = psim.PsimASimulate(maxThread=2, simList=jobs)
for i, r in enumerate(results):
print(f"Job {i}: {'OK' if r.IsError == 0 else r.ErrorMessage}")

Graph File Functions

PsimReadGraphFile(graphFilePath) -> PSIM_result

Reads an existing PSIM graph file (.smv, .txt, etc.) and returns all curves.

result = psim.PsimReadGraphFile("output.smv")
if result.IsError == 0:
for curve in result.Graph.curves:
print(curve.Name, curve.Rows)

PsimWriteGraphFile(graphFilePath, ColCount, RowCount, Names, Curves) -> int

Writes data curves to a PSIM graph file.

ParameterTypeDescription
graphFilePathstrOutput file path
ColCountintNumber of columns (curves)
RowCountintNumber of rows (samples) per curve
Nameslist[str]Curve name for each column
CurveslistData for each column: list, PSIM_curve, or ctypes double pointer

Returns: 1 on success, 0 on failure.

import numpy as np
t = list(np.linspace(0, 0.01, 1000))
v = [np.sin(2 * np.pi * 50 * ti) for ti in t]
psim.PsimWriteGraphFile("sine.smv", 2, 1000, ["Time", "V_out"], [t, v])

Schematic File Functions

PsimFileOpen(SchematicFilePath) -> PSIM_schematic

Opens a schematic file and returns a handle.

sch = psim.PsimFileOpen("circuit.psimsch")

If SchematicFilePath is None or "", a new empty schematic is created (equivalent to PsimFileNew).


PsimFileNew() -> PSIM_schematic

Creates a new empty schematic.

sch = psim.PsimFileNew()

PsimFileSave(SchematicObj, New_SchematicFilePath) -> int

Saves the schematic to a file.

ParameterTypeDescription
SchematicObjPSIM_schematicOpen schematic handle
New_SchematicFilePathstrDestination .psimsch path

Returns: 1 on success, 0 on failure.

psim.PsimFileSave(sch, "modified_circuit.psimsch")

PsimIsSubcircuit(schFilePath_or_Obj) -> int

Checks if the schematic is a subcircuit.

Returns: 1 if subcircuit, 0 otherwise.

is_sub = psim.PsimIsSubcircuit("my_block.psimsch")

Element Manipulation Functions

PsimGetElementList(SchematicObj, flag) -> list[PSIM_Element]

Returns a list of all elements in the schematic. The "Simulation Control" element is always placed first in the list.

ParameterTypeDescription
SchematicObjPSIM_schematicOpen schematic handle
flagintFilter flag (0 = all elements)
sch = psim.PsimFileOpen("circuit.psimsch")
elements = psim.PsimGetElementList(sch, 0)
for elm in elements:
print(elm.Type, elm.Name)
for p in elm.Params:
print(f" {p.Name} = {p.Value}")

PsimSetElmValue(SchematicObj, psimElm, varName, varValue) -> bool

Sets a parameter value on an element identified by a PSIM_Element object.

ParameterTypeDescription
SchematicObjPSIM_schematicOpen schematic handle
psimElmPSIM_Element or NoneTarget element (pass None to match by variable name alone)
varNamestrParameter name
varValuestrNew value
elements = psim.PsimGetElementList(sch, 0)
r1 = next(e for e in elements if e.Name == "R1")
psim.PsimSetElmValue(sch, r1, "Resistance", "47")

PsimSetElmValue2(SchematicObj, ElmType, ElmName, varName, varValue) -> bool

Sets a parameter value using the element type and name strings directly.

psim.PsimSetElmValue2(sch, "Resistor", "R1", "Resistance", "47")

PsimSetElmValue3(SchematicObj, ElmIndex, varName, varValue) -> bool

Sets a parameter value using the element's integer index (from PSIM_Element.Index).

psim.PsimSetElmValue3(sch, 5, "Resistance", "100")

PsimEnableElm(SchematicObj, psimElm, enable) -> bool

Enables or disables an element using a PSIM_Element object.

ParameterTypeDescription
enableint1 = enable, 0 = disable
psim.PsimEnableElm(sch, r1, 0) # disable R1

PsimEnableElm2(SchematicObj, ElmType, ElmName, enable) -> bool

Enables or disables an element by type and name strings.

psim.PsimEnableElm2(sch, "Resistor", "R1", 0)

PsimEnableElm3(SchematicObj, ElmIndex, enable) -> bool

Enables or disables an element by its integer index.

psim.PsimEnableElm3(sch, 5, 0)

PsimCreateNewElement(SchematicObj, szType, szName, **kwargs) -> int

Creates a new element in the schematic.

ParameterTypeDescription
SchematicObjPSIM_schematicOpen schematic handle
szTypestrElement type name
szNamestrInstance name to assign
**kwargsParameter name/value pairs

Returns: Element index on success, -1 on failure.

Note: The .FILE parameter cannot be set with this function; use PsimSetElmValue2 instead.

idx = psim.PsimCreateNewElement(sch, "Resistor", "R5", Resistance="100", x="200", y="300")

PsimConvertToPython(SchematicFilePath, PythonFilePath) -> int

(Requires PSIM 2024 or above)

Converts a schematic file to a Python script.

psim.PsimConvertToPython("circuit.psimsch", "circuit_script.py")

Design Suite (DS) Functions

These functions work with Design Suite schematics and require PSIM 2025 or above.

Psim_DS_UpdateParameters(schFilePath_or_Obj, parameters) -> (int, str)

Updates Design Suite parameters in a schematic.

ParameterTypeDescription
schFilePath_or_Objstr or PSIM_schematicSchematic path or handle
parametersdict, str, or listParameters to update

Returns: (result, error_message)result is 1 on success, 0 on failure.

res, err = psim.Psim_DS_UpdateParameters("design.psimsch", {"Kp": "0.5", "Ki": "10"})

The parameters argument can be:

  • a dict: {"Kp": "0.5", "Ki": "10"}
  • a str: "Kp = 0.5;\nKi = 10;\n"
  • a list: ["Kp = 0.5", "Ki = 10"]

Psim_DS_GetParameters(schFilePath_or_Obj) -> (int, str, int, str)

Retrieves Design Suite parameters from a schematic.

Returns: (result, parameters_string, param_count, error_message)

res, params_str, count, err = psim.Psim_DS_GetParameters("design.psimsch")
print(params_str) # "Kp=0.5\nKi=10\n..."

Psim_DS_RunScript(schFilePath_or_Obj, ScriptIndex, parameters) -> (int, str)

Runs a Design Suite script by index.

ParameterTypeDescription
ScriptIndexintZero-based index of the script to run
parametersdict, str, or listInput parameters

Returns: (result, error_message)

res, err = psim.Psim_DS_RunScript("design.psimsch", 0, {"x": "1.5"})

Psim_GetUndefinedParameters(schFilePath_or_Obj) -> (int, str, int, str)

Returns a list of parameters that are used in the schematic but not yet defined.

Returns: (result, parameters_string, param_count, error_message)

res, params, count, err = psim.Psim_GetUndefinedParameters("circuit.psimsch")

Script Functions

These functions require PSIM 2026 or above.

Psim_RunScriptFile(strFilePath, dictIn=None) -> (dict, str)

Runs a PSIM script from a file.

ParameterTypeDescription
strFilePathstrPath to the script file
dictIndict or NoneInput variables passed to the script

Returns: (dictOut, error_message) where dictOut is a dict of output variables from the script.

outputs, err = psim.Psim_RunScriptFile("my_script.txt", {"R": "10", "L": "1e-3"})
print(outputs) # e.g. {"Vout": "24.5"}

Psim_RunScript(strScriptText, dictIn=None) -> (dict, str)

Runs a PSIM script from a string.

script = "Vout = Vin * (R2 / (R1 + R2));"
outputs, err = psim.Psim_RunScript(script, {"Vin": "12", "R1": "10", "R2": "20"})

Psim_RunScriptInfo(strScriptText, dictIn=None) -> (dict, str, int, int)

Runs a script and also returns type and status information.

Returns: (dictOut, error_message, scriptType, returnValue)

ReturnDescription
dictOutOutput variables
error_messageError string (empty if OK)
scriptTypeBitmask of features used
returnValue1=success, -1=error, 10=depends on external objects

scriptType bitmask:

BitHexMeaning
00x01Assignments
10x02Arithmetic (+, -, *, /, pow)
20x04Basic math functions (sin, cos, log, …)
30x08Control flow (if, while)
40x10Function or Formula
50x20Conditional
80x100Advanced functions (ReadGraph, ReadFile, …)
dictOut, err, stype, retval = psim.Psim_RunScriptInfo("x = sin(a);", {"a": "1.57"})
print(f"returnValue={retval}, scriptType=0x{stype:02X}")

Probe Functions

Psim_GetProbes(schFilePath_or_Obj) -> (int, str, int, str)

(Requires PSIM 2026 or above)

Returns the list of probe names in a schematic.

Returns: (result, probe_names_string, probe_count, error_message)

res, probes_str, count, err = psim.Psim_GetProbes("circuit.psimsch")
print(f"{count} probes: {probes_str}")

Simview Function

RunSimview(szGraphFilePath, *colNames, **name_value_pairs)

Opens Simview with a graph file and optionally selects curves to display.

ParameterTypeDescription
szGraphFilePathstrPath to the .smv graph file
*colNamesstrCurve names to display
**name_value_pairsAdditional name/value display options
psim.RunSimview("output.smv", "V_out", "I_L")

Version Compatibility Reference

FunctionMin PSIM Version
get_psim_version, PsimSimulate, PsimASimulate, PsimReadGraphFile, PsimWriteGraphFile, PsimFileOpen, PsimFileSave, PsimFileNew, PsimIsSubcircuit, PsimGetElementList, PsimSetElmValue, PsimSetElmValue2, PsimEnableElm, PsimEnableElm2, PsimCreateNewElement, RunSimview, PsimSimulate_HyperSpice, PsimSimulate_LTSpicePSIM 2023.1
PsimConvertToPython, PsimEnableElm3, PsimSetElmValue3PSIM 2024
Psim_DS_UpdateParameters, Psim_DS_GetParameters, Psim_DS_RunScript, Psim_GetUndefinedParametersPSIM 2025
Psim_GetProbes, Psim_RunScriptFile, Psim_RunScript, Psim_RunScriptInfo, get_psim_version_namePSIM 2026

Usage Examples

Basic Simulation

from Psim_Class import PSIM

psim = PSIM("")
if not psim.IsValid():
raise RuntimeError("PSIM failed to load")

result = psim.PsimSimulate("boost_converter.psimsch", "boost_output.smv", simview=0)
if result.IsError == 0:
time = result.Graph['Time']
v_out = result.Graph['V_out']
print(f"Final Vout = {v_out[v_out.Rows - 1]:.3f} V")
else:
print("Error:", result.ErrorMessage)

Parameter Sweep with Async Simulation

from Psim_Class import PSIM, PSIM_SimulateData

psim = PSIM("")
jobs = []
for r_val in [10, 20, 50, 100]:
sd = PSIM_SimulateData(
SchFilePath="circuit.psimsch",
GraphFilePath=f"output_R{r_val}.smv",
SimviewFlag=1,
NameValueList=["R_load", str(r_val)]
)
jobs.append(sd)

results = psim.PsimASimulate(maxThread=2, simList=jobs)
for i, r in enumerate(results):
if r.IsError == 0:
v = r.Graph['V_out']
print(f"R={[10,20,50,100][i]}: Vout_final = {v[v.Rows-1]:.3f}")

Modifying a Schematic and Simulating

from Psim_Class import PSIM

psim = PSIM("")
sch = psim.PsimFileOpen("filter.psimsch")

# Change component values
psim.PsimSetElmValue2(sch, "Resistor", "R1", "Resistance", "1000")
psim.PsimSetElmValue2(sch, "Capacitor", "C1", "Capacitance", "10e-6")

# Save modified schematic
psim.PsimFileSave(sch, "filter_modified.psimsch")

# Simulate
result = psim.PsimSimulate(sch, "filter_output.smv", simview=0)

Running a Script

from Psim_Class import PSIM

psim = PSIM("")

script = """
omega = 2 * 3.14159 * f;
Xc = 1 / (omega * C);
Vout = Vin * Xc / sqrt(R*R + Xc*Xc);
"""

result, err = psim.Psim_RunScript(script, {"f": "1000", "C": "10e-6", "R": "100", "Vin": "12"})
print(f"Vout = {result.get('Vout', 'N/A')}")
if err:
print("Error:", err)

Reading an Existing Graph File

from Psim_Class import PSIM

psim = PSIM("")
result = psim.PsimReadGraphFile("previous_sim.smv")
if result.IsError == 0:
print(f"Number of curves: {len(result.Graph)}")
for curve in result.Graph.curves:
print(f" {curve.Name}: {curve.Rows} points")