Package: dss-python
DSS-Python: Extended bindings for an alternative implementation of EPRI's OpenDSSPython bindings and misc tools for using our alternative OpenDSS (EPRI Distribution System Simulator) engine, materialized in 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 (including Raspberry Pi devices) and macOS (including Apple M1 and later).Please seeFAQfor a couple of notes. Check also the other projects fromDSS-Extensions.org:DSS C-API library: the base library that exposes a modified version (alternative implementation) 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 useopendssdirect.utilsto generate some DataFrames.OpenDSSDirect.jlis 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 Sharpis available for .NET/C#,packaged on NuGet, also mimics the COM classes (drop-in replacement forOpenDSSengine.DLL). The current version is now multi-platform too! Soon it will be possible to use it via COM.DSS MATLABpresents multi-platform integration (Windows, Linux, MacOS) with DSS C-API and is also very compatible with the API of the official OpenDSS COM classes.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 interactive features and diakoptics (planned for a future version).This module mimics the COM structure (as exposed viawin32comorcomtypes) — seeThe DSS instancefor 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. See alsoDSS-Extensions — OpenDSS: Overview of Python APIs.
Most of the COM documentation can be used as-is, but instead of returning tuples or lists, this module returns/accepts NumPy arrays for numeric data exchange, which is usually preferred by the users. By toggleDSS.AdvancedTypes, complex numbers and matrices (shaped arrays) are also used to provide a more modern experience.The module depends mostly on CFFI, NumPy, typing_extensions and, optionally, SciPy.Sparse for reading the sparse system admittance matrix. Pandas and matplotlib are optional dependenciesto enable plottingand other features.Release historyCheckthe Releases pageandthe changelog.Missing features and limitationsMost limitations are inherited fromdss_capi, i.e., these are not implemented:DSSProgressfromDLL/ImplDSSProgress.pas: would need a reimplementation depending on the target UI (GUI, text, headless, etc.). Part of it can already be handled through the callback mechanisms.OpenDSS-GIS features are not implemented since they're not open-source.In general, the DLL fromdss_capiprovides more features than both the official Direct DLL and the COM object.Extra featuresBesides most of the COM methods, some of the unique DDLL methods are also exposed in adapted forms, namely the methods fromDYMatrix.pas, especiallyGetCompressedYMatrix(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_check_for_error()from the main class or manually checking theDSS.Errorinterface.InstallingOn all major platforms, you can install directly from pip:pip install dss-pythonFor a full experience, install the optional dependencies with:pip install dss-python[all]Binary wheels are provided for all major platforms (Windows, Linux and MacOS) and many combinations of Python versions (3.7 to 3.12). If you have issues with a specific version, please open an issue about it.After a successful installation, you can then import thedssmodule from your Python interpreter.BuildingSince v0.14.0, dss_python itself is a pure-Python package, i.e., the usual install methods should work fine for itself. However, you may still need to build the backend yourself in some situations.The backend is now indss_python_backend. TheGet the repositoriesgit clone https://github.com/dss-extensions/dss_python.git
    git clone https://github.com/dss-extensions/dss_python_backend.gitAssuming you successfully built or downloaded the DSS C-API DLLs (checkits repositoryfor instructions), keep the folder organization as follows:dss_capi/
dss_python/
dss_python_backend/Open a command prompt in thedss_python_backendsubfolder and run the build process:python -m pip install .
cd ../dss_python
python -m pip install .DocumentationThe compiled documentation is hosted athttps://dss-extensions.org/dss_pythonExample usageCheck the documentation for more details.If you were usingwin32comin code like:importwin32com.clientdss_engine=win32com.client.gencache.EnsureDispatch("OpenDSSEngine.DSS")orcomtypes(incidentally,comtypesis usually faster thanwin32com, so we recommend it if you need the official OpenDSS COM module):importcomtypes.clientdss_engine=comtypes.client.CreateObject("OpenDSSEngine.DSS")you can replace that fragment with:fromdssimportDSSasdss_engineIf you need support for arbitrary capitalization (that is, you were not using early bindings with win32com), add a call todss.set_case_insensitive_attributes().Assuming you have a DSS script namedmaster.dss, you should be able to run it as shown below:fromdssimportDSSasdss_enginedss_engine.Text.Command="compile 'c:/dss_files/master.dss'"dss_engine.ActiveCircuit.Solution.Solve()voltages=dss_engine.ActiveCircuit.AllBusVoltsforiinrange(len(voltages)//2):print('node%d:%f+ j%f'%(i,voltages[2*i],voltages[2*i+1]))TestingSince 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 istests/validation.pyand requires the same folder structure as the building process. You needwin32comto 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 interactive featuresBesides bug fixes, the main functionality of this library is mostly done. Notable desirable features that may be implemented are:More examples, especially for the extra features. There is a growing documentation hosted athttps://dss-extensions.org/dss_python/; watch alsohttps://github.com/dss-extensions/dss-extensionsfor more.Reports integrated in Python and interactive features on plots. Since most of the plot types from the official OpenDSS are optionally available since DSS-Python 0.14.2, advanced integration and interactive features are planned for a future feature.Expect news about these items by version 1.0.While the base library (AltDSS/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 athttps://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 / AcknowledgmentsDSS-Python is based on EPRI's OpenDSS via thedss_capiproject, so check its licensing information too.This project is licensed under the (new) BSD, available in theLICENSEfile. 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.