Python for Power Systems

A blog for power systems engineers to learn Python.

Find Your PSSE Path, Young Grasshopper

PSSE doesn’t make it easy to import and start using its Python API, psspy. We covered how and why it is beneficial to use Python to drive PSSE , but the implementation had a few limitations. To be specific, the necessary code to get it all working is a bit of black magic for the uninitiated and the PSSE install location is hard coded into the script. We discuss here a new method to get it to work on any setup with a single line of code. Best of all, it is free and and open source.

The following lines of code are the black magic which we aim to address:

1
2
3
4
import os, sys
sys.path.append(r"C:\Program Files\PTI\PSSE32\PSSBIN")
os.environ['PATH'] = (r"C:\Program Files\PTI\PSSE32\PSSBIN;"
                        + os.environ['PATH'])

The above code only works on systems where the PSSBIN folder is located at "C:\Program Files\PTI\PSSE32\PSSBIN". If you were to share this script with a colleague who was running on 64 bit install of windows ("C:\Program Files x86\PTI\PSSE32\PSSBIN") or a different version of PSSE ("C:\Program Files\PTI\PSSE33\PSSBIN"), then the script would fail to run.

pssepath solves this problem by automatically configuring these settings with a single line of code. The project is hosted on github and based on an idea proposed by chip in our Python for power systems engineers Q&A site (the answer that started it all). The goal is to be able to setup and import psspy on any computer with three simple lines of code:

1
import pssepath
1
2
pssepath.add_pssepath()
import psspy

Thats it! Now you can share your code with anyone and get back to doing productive work!

To use pssepath, download the zip from the pssepath download, extract the pssepath.py file and place it in the same folder as the script you want to run. We are working to make installation global (so you won’t have to place it in every folder) and much easier, so check back soon for developments.

The code is licensed to be compatible for use within a commercial environment. If you have any problems using pssepath, let us know about your difficulty and we will work with you to get it fixed for everyone. Alternatively, as the project is open source, you are free to take our code and do whatever you want with it (but if you do something really cool, please share it with the rest of us :)