> For the complete documentation index, see [llms.txt](https://www.opal-rt.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.opal-rt.com/docs/rt-lab/automation-api-and-scripting/python-ephasorsim-api.md).

# ePHASORSIM API

## Overview

The **ePHASORSIM** solver provides a Python Application Programming Interface (API) that enables programmatic interaction with a running simulation. It offers a simple and accessible way to perform key actions such as **setting component parameters** and **retrieving computed results**, similar to the functionality of the ePHASORSIM Solver block pins.

All interactions are handled through two Python classes: **Network** and **Test**. These classes are defined in the **opal.ephasorsim package**, within the network and test modules, respectively.

{% code overflow="wrap" lineNumbers="true" %}

```python
from opal.ephasorsim import Network, Test
```

{% endcode %}

## Example

Examples **phasor13\_AUTOMATE** and **phasor15\_IEEE\_EURO\_LV** are available in the folder: C:\OPAL-RT\RT-LAB\<version>\Examples\ePhasorsim, where version is the currently installed version of RT-LAB.

The following script demonstrates how to use several API routines. To execute it, first enable the **“Use post-init script”** option in the **Scripting** tab of the Solver block, and specify the `.py` file containing the API commands. When the simulation starts, the script is executed automatically.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-70f647ffec7feb25e4743ebfa196d0d829f4b244%2Fephasorsim-solver-block.png?alt=media" alt="" width="475"><figcaption></figcaption></figure>

Alternatively, the same commands can be run interactively while the simulation is running using the **RT-LAB Python console**. For example, load the phasor01\_IEEE39 model onto a target in RT-LAB, then open the Python console (**Tools → Python → Open Console**). Start the simulation and execute the commands step by step, observing the results in a Simulink scope.

{% code overflow="wrap" lineNumbers="true" %}

```python
from opal.ephasorsim import Network, Test
my_network = Network('phasor01_IEEE39')
# Set up a test sequence where a fault is applied to bus 30, 1 second into the
# test execution. The fault is cleared 0.08s thereafter.
my_test = Test(my_network)
my_test.set(
 ('30', 'active3PGFault', 1, True), 
 ('30', 'active3PGFault', 1.08, False))
my_test.execute()
```

{% endcode %}

{% hint style="info" %}
Before running the simulations, make sure that the file **simulations.json** does not exist in the directory: %LOCALAPPDATA%\ePHASORSIM
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.opal-rt.com/docs/rt-lab/automation-api-and-scripting/python-ephasorsim-api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
