Skip to main content

Builds PyPI Install with conda conda package version Supports Linux Supports macOS Supports Microsoft Windows

DSS Python: Extended bindings for an implementation of EPRI's OpenDSS

Python bindings and misc tools for using the OpenDSS (EPRI Distribution System Simulator) engine through the alternative/unofficial implementation from the DSS C-API library. Based on DSS C-API, CFFI and NumPy, aiming for enhanced performance and full compatibility with the official COM object API on Windows, Linux and macOS. Support includes Intel-based (x86 and x64) processors, as well as ARM processors for Linux and macOS (including Apple M1 and later).

Please see FAQ for a couple of notes. Check also the other projects from DSS-Extensions.org:

  • DSS C-API library: the base library that exposes a modified version of EPRI's OpenDSS through a more traditional C interface, built with the open-source Free Pascal compiler instead of Delphi. As of 2022, this base library includes several extensive changes, while retaining very good compatibility.
  • dss.hpp: header-only library for C++, hosted within DSS C-API (include/ directory). Allows using DSS C-API more comfortably from C++, abstract memory management and low-level details such as API conventions of the DSS C-API library.
  • OpenDSSDirect.py: if you don't need COM compatibility, or just would like to check its extra functionalities. You can mix DSS Python and OpenDSSDirect.py -- for example, if you have old code using the official COM objects, you could quickly switch to DSS Python with very few code changes, and then use opendssdirect.utils to generate some DataFrames.
  • OpenDSSDirect.jl is a Julia module, created by Tom Short (@tshort), migrated with the help of Dheepak Krishnamurthy (@kdheepak) to DSS C-API instead of the DDLL in Feb 2019.
  • DSS Sharp is available for .NET/C#, packaged on NuGet, also mimics the COM classes (drop-in replacement for OpenDSSengine.DLL). The current version is now multi-platform too! Soon it will be possible to use it via COM.
  • DSS MATLAB presents multi-platform integration (Windows, Linux, MacOS) with DSS C-API and is also very compatible with the API of the official OpenDSS COM classes.

Version 0.13.x is based on OpenDSS revision 3595 (few commits after OpenDSS v9.6.1.1, but we pick and choose when to port certain features). While we plan to add a lot more functionality into DSS Python, the main goal of creating a COM-compatible API has been reached in 2018. If you find an unexpected missing feature, please report it! Currently missing features that will be implemented eventually are plotting (partial implementation available) and diakoptics (planned for future version).

This module mimics the COM structure (as exposed via win32com or comtypes) -- see The DSS instance for some docs -- effectively enabling multi-platform compatibility at Python level. Compared to other options, it provides easier migration from code that uses the official OpenDSS through COM. 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, which is usually preferred by the users.

The module depends on CFFI, NumPy and, optionally, SciPy.Sparse for reading the sparse system admittance matrix. Pandas and matplotlib are optional dependencies to enable plotting and other features.

Brief release history

  • 2023-04-01 / version 0.13.1: Microupdate to the OpenDSS engine; very minor Python changes.
  • 2023-03-29 / version 0.13.0: Updates to the OpenDSS engine, move plotting and initial notebook integration, matrix shapes and complex numbers, bug fixes, etc.
  • 2022-07-16 / version 0.12.1: Very minor release to address a bug found in v0.12.0, to add the Storages API, and include the property descriptions/help.
  • 2022-07-14 / version 0.12.0: Major release merging parallel features, multiple DSS engine instances, ZIP file support, incremental Y matrix updates, new API functions, partial plotting support, better performance, and so on. General usage examples for the new features will be incrementally added to https://github.com/dss-extensions/dss-extensions
  • 2021-03-09 / version 0.10.7-1: Very minor release to fix issues with some of the energy meter reports.
  • 2020-12-28 / version 0.10.7: Maintenance release to match DSS C-API 0.10.7, based on on OpenDSS revision 2963. Includes fixes and new features from the official OpenDSS.
  • 2020-07-31 / version 0.10.6: Maintenance release to match DSS C-API 0.10.6, based on on OpenDSS revision 2909. New important settings: DSS.LegacyModels and DSS.Error.ExtendedErrors.
  • 2020-03-03 / version 0.10.5: Maintenance release to match DSS C-API 0.10.5, based on on OpenDSS revision 2837. Temporarily drops the v8 parallel-machine functions, as well as conda packages on Windows.
  • 2019-11-16 / version 0.10.4: Maintenance release to match DSS C-API 0.10.4.
  • 2019-05-22 / version 0.10.3: Some important fixes, better general performance, new API extensions, new features ported from COM and the OpenDSS version 8 codebase.
  • 2019-02-28 / version 0.10.2: Some small fixes, adds the missing CtrlQueue.Push, faster LoadShapes and new property DSS.AllowEditor to toggle editor calls.
  • 2019-02-17 / version 0.10.1: Integrate DSS C-API changes/fix, some small fixes, and more error-checking.
  • 2018-11-17 / version 0.10.0: Lots of changes, fixes and new features. Check the new changelog document for a list.
  • 2018-08-12 / version 0.9.8: Reorganize modules (v7 and v8), adds 8 missing methods and new backend methods for OpenDSSDirect.py 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., these are 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.).
  • OpenDSS-GIS features are not implemented since they're not open-source.

In general, the DLL from dss_capi provides more features than both the official Direct DLL and the COM object.

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 map nearly all OpenDSS errors to Python exceptions, which seems a more natural way of working in Python. You can still manually trigger an error check by calling the function CheckForError() from the main module or manually checking the DSS.Error interface.

Installing

On all major platforms, you can install directly from pip:

    pip install dss_python

Or, if you're using the Anaconda distribution, you can try:

    conda install -c dss-extensions dss_python

Binary wheels are provided for all major platforms (Windows, Linux and MacOS) and many combinations of Python versions (3.5 to 3.10). If you have issues with a specific version, please open an issue about it. Conda packages support at least Python 3.7 to 3.10 (varying according to the release).

After a successful installation, you can then import the dss module from your Python interpreter.

Building

Get the repository:

    git clone https://github.com/dss-extensions/dss_python.git

Assuming you successfully built or downloaded the DSS C-API DLLs (check its repository for instructions), keep the folder organization as follows:

dss_capi/
dss_python/

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

python setup.py build
python setup.py install

If you are familiar with conda-build, there is a complete recipe to build DSS C-API, KLUSolve(X) and DSS Python in the conda subfolder.

Example usage

If you were using win32com in code like:

import win32com.client 
dss_engine = win32com.client.gencache.EnsureDispatch("OpenDSSEngine.DSS")

or comtypes (incidentally, comtypes is usually faster than win32com, so we recommend it if you need the official OpenDSS COM module):

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

you can replace that fragment with:

from dss import DSS as dss_engine

If you need the mixed-cased handling (that is, you were not using early bindings with win32com), add a call to dss.use_com_compat().

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

from dss import DSS as dss_engine

dss_engine.Text.Command = "compile 'c:/dss_files/master.dss'"
dss_engine.ActiveCircuit.Solution.Solve()
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]))

Testing

Since the DLL is built using the Free Pascal compiler, 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 other minor issues. Most of the sample files from the official OpenDSS repository are used for validation.

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

As of version 0.11, the full validation suite can be run on the three supported platforms. This is possible by saving the official COM DLL output and loading it on macOS and Linux. We hope to fully automate this validation in the future.

Roadmap: docs and plotting

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

Expect news about these items by version 0.13.

While the base library (DSS C-API) will go through some API changes before v1.0, those do not affect usage from the Python side.

Questions?

If you have any question, feel free to open a ticket on GitHub (here or at https://github.com/dss-extensions/dss-extensions), or contact directly me through email (pmeira at ieee.org). Please allow me a few days to respond.

Credits / Acknowledgment

DSS-Python is based on EPRI's OpenDSS via the dss_capi project, so check its licensing information too.

This project is licensed under the (new) BSD, available in the LICENSE file. It's the same license OpenDSS uses (OPENDSS_LICENSE). OpenDSS itself uses KLUSolve and SuiteSparse, licensed under the GNU LGPL 2.1.

I thank my colleagues at the University of Campinas, Brazil, for providing feedback and helping me test this package during its inception in 2016-2017, as well as the many users and collaborators that have been using this or other DSS Extensions since the public releases in 2018.

Release files for dss-python 0.13.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for dss-python 0.13.1
File
dss_python-0.13.1-cp37-abi3-win_amd64.whl CPython 3.7 abi3 Windows x86-64 Details
dss_python-0.13.1-cp37-abi3-win32.whl CPython 3.7 abi3 Windows x86-32 Details
dss_python-0.13.1-cp37-abi3-manylinux_2_28_x86_64.whl CPython 3.7 abi3 Linux glibc 2.28+ x86-64 Details
dss_python-0.13.1-cp37-abi3-manylinux_2_28_aarch64.whl CPython 3.7 abi3 Linux glibc 2.28+ ARM64 Details
dss_python-0.13.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.7 abi3 Linux glibc 2.17+ x86-64 Details
dss_python-0.13.1-cp37-abi3-manylinux_2_17_i686.manylinux2014_i686.whl CPython 3.7 abi3 Linux glibc 2.17+ x86-32 Details
dss_python-0.13.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.7 abi3 Linux glibc 2.17+ ARM64 Details
dss_python-0.13.1-cp37-abi3-macosx_12_0_arm64.whl CPython 3.7 abi3 macOS 12.0+ ARM64 Details
dss_python-0.13.1-cp37-abi3-macosx_10_15_x86_64.whl CPython 3.7 abi3 macOS 10.15+ x86-64 Details

Total release size: 135.9 MB

Release files / dss_python-0.13.1-cp37-abi3-win_amd64.whl

Download URL dss_python-0.13.1-cp37-abi3-win_amd64.whl
Size 17.2 MB
Tags CPython 3.7 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
4ce0942bc03b7e65ed1b73ec9e60eadd0ce693f5e055d6518f7ad996ee2a97d2
BLAKE2b-256 checksum
How to use checksums
158af959c9945f62c24ff72bedfe9dc9ba31f5e11c1f9ce2a25c3cfe066a42eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.12

Release files / dss_python-0.13.1-cp37-abi3-win32.whl

Download URL dss_python-0.13.1-cp37-abi3-win32.whl
Size 15.9 MB
Tags CPython 3.7 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
dd9d48a2a73a30e00a6790f2ea5622171299f0c4c358ba15c0f351485dd62a85
BLAKE2b-256 checksum
How to use checksums
927f3999cde78234b0f0bcd7d836ed3c160715b1f76a43f12335a58e3737af6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.12

Release files / dss_python-0.13.1-cp37-abi3-manylinux_2_28_x86_64.whl

Download URL dss_python-0.13.1-cp37-abi3-manylinux_2_28_x86_64.whl
Size 20.3 MB
Tags CPython 3.7 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
7417c2241576fabf808af45ca0b27dd884324c419a407a0bb64852ba4acf4456
BLAKE2b-256 checksum
How to use checksums
8b010bddd58c770f824e528d9be21d616521bbc9dcd35f87d6317b0e0432ebe8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.12

Release files / dss_python-0.13.1-cp37-abi3-manylinux_2_28_aarch64.whl

Download URL dss_python-0.13.1-cp37-abi3-manylinux_2_28_aarch64.whl
Size 15.3 MB
Tags CPython 3.7 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
796176bb10e1d279bc8982805fea21edcfe9851a5ac002bb2e8da6ee53d46635
BLAKE2b-256 checksum
How to use checksums
1c837312474f565da8c73402d98056c29351ad5fc013bc8cd838367d7ef09a80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.12

Release files / dss_python-0.13.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL dss_python-0.13.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 20.3 MB
Tags CPython 3.7 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
f57809f61f2c5e8a531ab428a32603309f434ac116727746e01c9d85926378fd
BLAKE2b-256 checksum
How to use checksums
095b14714f50cd34093005908f0660b522307b8a70e7d4cebefca45d5403717a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.12

Release files / dss_python-0.13.1-cp37-abi3-manylinux_2_17_i686.manylinux2014_i686.whl

Download URL dss_python-0.13.1-cp37-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Size 19.0 MB
Tags CPython 3.7 Linux glibc 2.17+ x86-32 abi3
SHA-256 checksum
How to use checksums
dbb308d29e06a58285b7cacd6d69100be3aeed2e6d18c866bbe03e4434d95fd2
BLAKE2b-256 checksum
How to use checksums
8c1f82f3deb095b866716ea8cf34434bf3cc7b846e8e8d8209de71e979b3bd26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.12

Release files / dss_python-0.13.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL dss_python-0.13.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 15.3 MB
Tags CPython 3.7 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
51e2f9bbe61ccd989e951cefde00b749916350dfe02bcec6a34e99efb3cb94db
BLAKE2b-256 checksum
How to use checksums
4c6a2a636ba1dda8e84dd31fc468f43742f662b2d7635c784b9e3d7f7621b979
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.12

Release files / dss_python-0.13.1-cp37-abi3-macosx_12_0_arm64.whl

Download URL dss_python-0.13.1-cp37-abi3-macosx_12_0_arm64.whl
Size 6.1 MB
Tags CPython 3.7 abi3 macOS 12.0+ ARM64
SHA-256 checksum
How to use checksums
0b9f7b04b0bdd4dd5b4c455f3fa349dfb2b258bd3d7a8ca72c52ceb4f29b4d93
BLAKE2b-256 checksum
How to use checksums
3a32e13bd9a57527bbb86b9edbb12cc1537a3cd309b4109de423171fa1c31fd6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.12

Release files / dss_python-0.13.1-cp37-abi3-macosx_10_15_x86_64.whl

Download URL dss_python-0.13.1-cp37-abi3-macosx_10_15_x86_64.whl
Size 6.4 MB
Tags CPython 3.7 abi3 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
1c18a335da4185f3f4cfa8850135fc54b5fc0594148ba922b434cf534a3ff5aa
BLAKE2b-256 checksum
How to use checksums
a7bf35069ca37fb70f357b24f53ea6a39c1378852aa55f8dba49b81cf7b0443d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.12

Release history Release notifications | RSS feed

0.15.7

2 release files

0.15.6

2 release files

0.15.5

2 release files

0.15.4

2 release files

0.15.3

2 release files

0.15.2

2 release files

0.15.1

2 release files

0.15.0

2 release files

0.14.4

1 release file

0.14.3

1 release file

0.14.2

1 release file

0.14.1

1 release file

0.14.0

1 release file

This release

0.13.1 This release

9 release files

0.13.0

7 release files

0.12.1

8 release files

0.12.0

8 release files

0.9.8

18 release files

0.9.7

2 release files

0.9.6

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page