Skip to main content

OpenDSS bindings based on the DSS C-API project

Project description

dss_python: Unofficial bindings for EPRI's OpenDSS

Python bindings and misc tools for using OpenDSS (EPRI Distribution System Simulator). Based on CFFI and dss_capi, aiming for full COM compatibility on Windows and Linux.

If you are looking for the C API library, see dss_capi.

Version 0.9.8, based on OpenDSS revision 2246. This is a work-in-progress but it's deemed stable enough to be made public. Note that, while the interface with OpenDSS is stable (classic version), the OpenDSS-PM (actor-based parallel machine version) interface was integrated recently and is experimental.

This module mimics the COM structure (as exposed via win32com or comtypes), effectively enabling multi-platform compatibility at Python level. Most of the COM documentation can be used as-is, but instead of returning tuples or lists, this modules returns/accepts NumPy arrays for numeric data exchange.

This module depends on CFFI, NumPy and, optionally, SciPy.Sparse for reading the sparse system admittance matrix.

Recent changes

  • 2018-08-10 / version 0.9.8: Reorganize modules (v7 and v8), adds 8 missing methods and new backend methods for v0.3+. Integrates many fixes from DSS_CAPI and the upstream OpenDSS.
  • 2018-04-30 / version 0.9.7: Fix some of the setters that used array data.
  • 2018-04-05 / version 0.9.6: Adds missing ActiveCircuit.CktElements[index] (or ...CktElements(index)) and ActiveCircuit.Buses[index] (or ...Buses(index)).
  • 2018-03-07 / version 0.9.4: Allows using len on several classes, fixes DSSProperty, and includes COM helpstrings as docstrings. Contains changes up to OpenDSS revision 2152.
  • 2018-02-16 / version 0.9.3: Integrates COM interface fixes from revision 2136 (First Next iteration on some elements)
  • 2018-02-12 / version 0.9.2: Experimental support for OpenDSS-PM (at the moment, a custom patch is provided for FreePascal support) and port COM interface fixes (OpenDSS revision 2134)
  • 2018-02-08 / version 0.9.1: First public release (OpenDSS revision 2123)

Missing features and limitations

Most limitations are inherited from dss_capi, i.e.:

  • Only the 64-bit version of OpenDSS is built. A 32-bit version should be possible with a few changes.

  • Currently not implemented:

    • DSSEvents from DLL/ImplEvents.pas: seems too dependent on COM.
    • DSSProgress from DLL/ImplDSSProgress.pas: would need a reimplementation depending on the target UI (GUI, text, headless, etc.)
  • Although tests were successful on openSuse 42.3 (both CPython 3.6 and PyPy3.5 v5.10.1).

Extra features

Besides most of the COM methods, some of the unique DDLL methods are also exposed in adapted forms, namely the methods from DYMatrix.pas, especially GetCompressedYMatrix (check the source files for more information).

Since no GUI components are used in the FreePascal DLL, we are experimenting with different ways of handling OpenDSS errors. Currently, the DSS.Text.Command call checks for OpenDSS errors (through the DSS.Error interface) and converts those to Python exceptions. Ideally every error should be converted to Python exceptions, but that could negatively impact performance. You can manually trigger an error check by calling the function CheckForError() from the main module.


On Windows (Python 2.7, 3.6 and 3.7), you can install directly from pip:

pip install dss_python

If successful, you can then import the dss module from your Python interpreter.


Get this repository:

    git clone

Assuming you successfully built or downloaded the dss_capi (check its repository for instructions), keep the folder organization as follows:


Open a command prompt in the dss_python subfolder and run the build process:

python build
python install

Example usage

If you were using win32com in code like:

import win32com.client 
dss_engine = win32com.client.Dispatch("OpenDSSEngine.DSS")

or comtypes:

import comtypes.client
dss_engine = comtypes.client.CreateObject("OpenDSSEngine.DSS")

you can replace that fragment with:

import dss
dss_engine = dss.DSS

Assuming you have a DSS script named master.dss, you should be able to run it as shown below:

import dss
dss_engine = dss.DSS

dss_engine.Text.Command = "compile c:/dss_files/master.dss"
voltages = dss_engine.ActiveCircuit.AllBusVolts

for i in range(len(voltages) // 2):
    print('node %d: %f + j%f' % (i, voltages[2*i], voltages[2*i + 1]))

If you do not need the mixed-cased handling, you can omit the call to use_com_compat() and use the casing used in this project.

If you want to play with the experimental OpenDSS-PM interface, it is installed side-by-side and you can import it as:

dss_engine =


Since the DLL is built using FreePascal, which is not officially supported by EPRI, the results are validated running sample networks provided in the official OpenDSS distribution. The only modifications are done directly by the script, removing interactive features and some minor other minor issues.

The validation scripts is tests/ and requires the same folder structure as the building process. You need win32com to run it.

Currently, the following sample files from the official OpenDSS repository are used:

    Distrib/IEEETestCases/IEEE 30 Bus/Master.dss

On Windows 10, remember to set the compatibility layer to Windows 7 (set the environment variable __COMPAT_LAYER=WIN7RTM), otherwise you may encounter issues with COM due to ASLR on Python 3.6.

There is no validation on Linux yet, since we cannnot run the COM module there. The most likely solution will be to pickle the data on Windows and load them on Linux.


Besides bug fixes, the main funcionality of this library is mostly done. Notable desirable features that may be implemented are:

  • More and better documentation
  • Create wheels for Linux distributions, maybe using the Anaconda stack.
  • Create a more "Pythonic" API. This would break compatibility with COM, but may result in a more pleasant environment for using OpenDSS in Python.


If you have any question, feel free to open a ticket on Github or contact me through Twitter. Please allow me a few days to respond.

Credits / Acknowlegement

dss_python is based on EPRI's OpenDSS via the dss_capi project, check its licensing information.

This project is licensed under the (new) BSD, available in the LICENSE file. It's the same license OpenDSS uses (OPENDSS_LICENSE).

I thank my colleagues at the University of Campinas, Brazil, for providing feedback and helping me test this module.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
dss_python-0.9.8-cp27-cp27m-macosx_10_6_x86_64.whl (3.2 MB) Copy SHA256 hash SHA256 Wheel cp27
dss_python-0.9.8-cp27-cp27m-manylinux1_x86_64.whl (3.6 MB) Copy SHA256 hash SHA256 Wheel cp27
dss_python-0.9.8-cp27-cp27mu-manylinux1_x86_64.whl (3.6 MB) Copy SHA256 hash SHA256 Wheel cp27
dss_python-0.9.8-cp27-cp27m-win32.whl (2.0 MB) Copy SHA256 hash SHA256 Wheel cp27
dss_python-0.9.8-cp27-cp27m-win_amd64.whl (2.2 MB) Copy SHA256 hash SHA256 Wheel cp27
dss_python-0.9.8-cp34-cp34m-manylinux1_x86_64.whl (3.6 MB) Copy SHA256 hash SHA256 Wheel cp34
dss_python-0.9.8-cp35-cp35m-macosx_10_6_x86_64.whl (3.2 MB) Copy SHA256 hash SHA256 Wheel cp35
dss_python-0.9.8-cp35-cp35m-manylinux1_x86_64.whl (3.6 MB) Copy SHA256 hash SHA256 Wheel cp35
dss_python-0.9.8-cp35-cp35m-win32.whl (2.0 MB) Copy SHA256 hash SHA256 Wheel cp35
dss_python-0.9.8-cp35-cp35m-win_amd64.whl (2.2 MB) Copy SHA256 hash SHA256 Wheel cp35
dss_python-0.9.8-cp36-cp36m-macosx_10_7_x86_64.whl (3.2 MB) Copy SHA256 hash SHA256 Wheel cp36
dss_python-0.9.8-cp36-cp36m-manylinux1_x86_64.whl (3.6 MB) Copy SHA256 hash SHA256 Wheel cp36
dss_python-0.9.8-cp36-cp36m-win32.whl (2.0 MB) Copy SHA256 hash SHA256 Wheel cp36
dss_python-0.9.8-cp36-cp36m-win_amd64.whl (2.2 MB) Copy SHA256 hash SHA256 Wheel cp36
dss_python-0.9.8-cp37-cp37m-macosx_10_7_x86_64.whl (3.2 MB) Copy SHA256 hash SHA256 Wheel cp37
dss_python-0.9.8-cp37-cp37m-manylinux1_x86_64.whl (3.6 MB) Copy SHA256 hash SHA256 Wheel cp37
dss_python-0.9.8-cp37-cp37m-win32.whl (2.0 MB) Copy SHA256 hash SHA256 Wheel cp37
dss_python-0.9.8-cp37-cp37m-win_amd64.whl (2.2 MB) Copy SHA256 hash SHA256 Wheel cp37

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page