- Table of Contents
- Quick links for documentation
- "The" library
libIEC61850 - How to use the Python binding
pyIEC61850 - Compiling the Python binding by yourself
- Compiling for Windows
- Compiling for amd64(x86-64) Linux (e.g. WSL2, QNAP NAS)
- Compiling for arm64(aarch64) Linux (e.g. Raspberry Pi 4/5)
- Compiling for arm32 Linux (e.g. Raspberry Pi 3)
- Compiling and testing using Docker
- Special case for libIEC61850 1.4.1
- Special case for libIEC61850 1.6 (only when GOOSE functions not needed)
- Other Information
- License
This project contains basic information regarding the compiled Python binding of the open-source IEC 61850
software stack libIEC61850 developed by MZ Automation GmbH
Some important documentations can be found in the doc folder, including:
- Compiling for Windows applications
- Compiling for Linux (AMD x86-64) (WSL2, QNAP) using Docker
- Compiling for Linux (ARM64) (raspberry pi 4/5) using Docker
- Compiling the Python binding in Linux environment
- Compiling and testing the Python binding using Docker (accommodating latest Python versions)
Taken from the libIEC61850 homepage:
This library provides an implementation of IEC61850 on top of the MMS (Manufacturing Message Specification) protocol in standard C. It also provides support for intra-substation communication via GOOSE. The goal of this project is to provide an implementation that is very portable and can run on embedded systems and micro-controllers. Also provided is a set of simple examples that can be used as a starting point for own applications. The library also contains a . NET wrapper to allow the library to be used easily in high-level languages like C#. This implementation runs on embedded systems, embedded Linux systems as well as on desktop computers running Linux, Windows or MacOS.
In our own words:
The libIEC61850 library is a magic tool for the realisation of smart grid applications,
especially with its full protocol stack for MMS and the API for dynamic data model generation.
This repository contains already complied python bindings for different platforms, python versions and software versions.
The ready-for-use files are placed in the sub-folder named pyiec61850_compiled. The files are organised by
pyiec61850_compiled
├── <linux platform indicator>
│ ├── <libIEC61850 version>
│ │ ├── <Python version 1>
│ │ │ ├── _iec61850.so # Note: for libIEC61850 >= 1.6, the name is changed to _pyiec61850.so
│ │ │ ├── iec61850.py # Note: for libIEC61850 >= 1.6, the name is changed to pyiec61850.py
│ │ ├── <Python version 2>
│ │ ...
│ │ └── libiec61850-<version> # a subfolder containing a necessary dependency
│ │ └── build
│ │ └── src
│ │ └── libiec61850.so.<version> # required by the _iec61850.so
├── Windows
│ ├── <libIEC61850 version> # currently only 1.4.1 is working
│ │ └── <Python version>
│ │ ├── _iec61850.pyd
│ │ └── iec61850.py
Note: the GOOSE functionalities are not in focus regarding our research, consequently, the
compiled bindings (in particular for Linux) do not include the two associated third-party modules winpcap and
mbedtls. To bypass the GOOSE errors during the compiling, we turned off / ignored certain GOOSE functions. To deploy the linux bindings for
GOOSE-related applications, you may have to recompile the lib by yourself. Refer to this documentation Compiling
for Windows applications for more details regarding the handling of GOOSE functions during compiling.
Note: for SGFG members, one 7z file containing all src files of libIEC61850 after compilation is placed here on our sharepoint If you would like to perform a quick test for a specific combination, just go ahead and refer to the documentation Compiling and testing using Docker (accommodating changes in latest Python versions). Well, for flexible deployment, we recommend you to use 3 compiled files and start a new (docker) application.
For the Windows Python binding, it suffices to add the pyd and py file of the correct Python version to the
syspath of your IEC 61850 application. Then import the lib in Python should work:
If Python throws an importlib error, double-check the python version and file path.
As of the Linux Python binding, only including the shared object (.so file) and py file is not enough, as the shared
object also depends on the file ./libiec61850-<version>/build/src/libiec61850.so.<version>.
During the compilation in Docker, we have a workflow that first creates a subfolder named work and then perform
make in the subfolder ./work/libiec61850-<version>/build, which leads to the inheritance of this directory structure in
the dependency file. Although this process produces a bunch of files in the build folder after the compiling, only
this single file is necessary to make the import of pyiec61850 function properly (aside
from the shared object and py file), as shown in the screenshot below.
In other words, when deploying pyiec61850 in Docker, one should first make a directory named work and then copy the
folder ./libiec61850-<version>/build/src/ (containing that single dependency file) into it. Make sure you are
selecting the right version.
To check whether the essential dependencies are all right, just do this:
ldd _iec61850.so
if everything is fine, you should also see similar returns as in the screenshot above. In particular, there should
not be any No such file or directory error related to files located in work.
P.S. libIEC61850-1.6 may come with some Symbol not found errors as shown below, you may ignore them as long as they
are not fatal for your application.
A list of the runpath of the dependency file (libiec61850.so.<version>) in all available pyiec61850 bindings
is summarised in the file runpath_check.txt.
- For deployment in Linux systems, it is NOT necessary to include the entire
compiled
libIEC61850project into your own program. Just adding the .so and .py files plus one dependency file suffices. - The compiled files for amd64 (WSL2, QNAP NAS, ...) and arm64 (Raspberry Pi) applications are NOT compatible / interchangeable.
- The dependency file in
buildis universally applicable for all Python versions, so we have the folder. /libiec61850-<version>/build/src/only once for each combination of libIEC61850 version and OS platform. The folder contains literally only one single file without file extension. - The compiled files in linux_amd64_x86-64_docker do not really
differ much from the amd64_x86-64 compilations. This is because docker
inherits the architecture of the base OS that it runs on. The docker compilation has been performed via amd64 WSL2
terminals using the docker desktop App. Fix the lib and Python version,
pyiec61850files in the two folders are
generally interchangeable, but pay attention to the runpath of the required dependency file, more info in the
debug section. - If packing everything under the
workdirectory (in Docker) would cause inconsistency in your application, consider change the file path in the dependency file usingpatchelf, see the debug section. - If the prescribed repository topology leads to inconsistency in your own project, consider locate the required files aligned to your project structure, and create soft links to access them.
- For
libIEC61850>= 1.6, the filenames of the two essentials are changed fromiec61850.pyand_iec61850.so (_iec61850.pydfor Windows) topyiec61850.pyand_pyiec61850.soaccordingly. Make sure you have built a version checker to avoid importlib error.
A demo docker program for libIEC61850-1.5.1, Linux amd64 platform, is available in the folder tester. Additionally, we have prepared two Python scripts as server (using a static data model) and client tester.
A test report can be found here. The report includes all the combinations we have considered and some specific test results for some of them.
If you are convinced that the Python binding you chose is absolutely correct, but in Python import iec61850 or
import pyiec61850 still throws error, it may be caused by inconsistency of the filepath in the required shared
object. For example, as shown in the screenshot below, sometimes we do encounter the No such file error.
In that case ldd only tells you No such file or directory but not where exactly the file is supposed to be.
To verify this, do the following (use the terminal in a docker desktop container as example):
apk add binutils # in other linux env, it could be apt-get, apt install or something else
readelf -d _iec61850.so # read details of the dependencies
Indeed, the runpath is identified as some other path rather than our default path . /work/libiec61850-<version>/build/src/, it might be a path mismatch when performing the compiling. But here the
true reason is that we are using a .so generated in a local Ubuntu server, so it does not have the default
runpath as being compiled in a docker container.
Anyway, to make it usable for docker, we have two options:
- do mkdir and move some files to make the runpath match, or
- use
patchelfto correct the path
Now we try the second approach:
apk add patchelf
patchelf --set-rpath '$ORIGIN/libiec61850-1.5.0/build/src' _iec61850.so
Note that we are already in the work directory, which will be assigned to $ORIGIN, so no need to repeat it in
the path; an alternate would be to replace $ORIGIN by /usr/local/lib:/work so that it is consistent with the
default runpath. After that, we can see that the path has been corrected and the required
shared object is successfully identified. Now we are all set, the pyiec61850 application is ready to go in Docker.
Occasionally, one would like to start with the libIEC61850 Python binding from the scratch. In this case
we provide you with some useful step-by-step instructions anyhow.
For windows applications, you may refer to this instruction: Cmpiling the Python binding for Windows environment.
For this we have two instructions with some overlapping and probably inconsistency, you may choose either of them.
- One approach using Docker desktop
- Generic workflow (accommodating changes in latest Python versions)
Note that although we use cmake for the Windows compiling and use the CMakeLists.txt file to pass
configurations, cmake only generates MakeFile in Linux. To perform a compiling one should use make rather than
cmake.
The compiling process for arm64 is almost identical to the generic workflow. The following instruction contains some basic information about setting up a compiler docker on Pi and transferring files.
Of course, one could choose to perform the cmake directly on Pi; the file transfer might also be easier when using winSCP, VS code or other tools with GUI.
The process for compiling for legacy raspberry pis or other 32-bit-based systems is almost identical.
Docker applications make your life easier, when properly used.
Here we offer some useful information regarding compiler as a Docker container:
- One approach using Docker desktop (the same file as above for amd64)
- Compiling and testing using Docker (accommodating changes in latest Python versions)
- Compiling for Raspberry Pi using Docker (the same file as above for arm64)
Docker might not be a reasonable choice for performing the compilation, since the compiling is mostly a one-time thing.
Well compiling via Docker allows one to immediately test the compiled pyiec61850 lib as a docker container or
application, as it will be later in the deployment environment.
Edit hal/serial/linux/serial_port_linux.c (in your source tree, not the build directory) and add these two lines immediately after the existing includes (e.g. after #include <errno.h>):
diff
CopyEdit
--- a/hal/serial/linux/serial_port_linux.c
+++ b/hal/serial/linux/serial_port_linux.c
@@
#include <termios.h>
#include <errno.h>
+ #include <sys/types.h>
+ #include <sys/time.h>
+ #include <sys/select.h>
#include "serial_port_linux.h"
…
or directly replace this as a new serial_port_linux.c
To compile the libIEC61850 for 1.6, one would need to add several third-party moduls, but if GOOSE is not required, then a small change has to be made in the source file before the whole compilation process to by pass the GOOSE modules.
Redirect to source code libiec61850-1.6\pyiec61850 and open the iec61850.i file and add these lines in the starting to ignore the Goose Publisher
/* File : iec61850.i */
%module(directors="1") pyiec61850 /*NOTE: new changed in version 1.6.0*/
%ignore GoosePublisher_createRemote; /*NOTE: new added*/
%ignore GooseReceiver_createRemote; /*NOTE: new added*/
%ignore ControlObjectClient_setTestMode(ControlObjectClient self);or just replace the existing file iec61850.i with this:
Then carry on the workflow like usual.
For compiling on windows, one needs more some more lines
%module(directors="1") pyiec61850 /*NOTE: new changed in version 1.6.0*/
%ignore GoosePublisher_createRemote; /*NOTE: new added*/
%ignore GooseReceiver_createRemote; /*NOTE: new added*/
%ignore GoosePublisher_create; /*NOTE: new added*/
%ignore GoosePublisher_createEx; /*NOTE: new added*/
Note that this trick is just a workaround for non-GOOSE applications, the right way to deal with GOOSE errors during compiling is to add the third-party modules properly. More details here: Compiling for Windows applications
- Falko Ebe: Initiative for the deployment of
libIEC61850in SGFG - Heiko Lorenz: first SGFG developer using
libIEC61850and Qt - Jeromie Morris: initial compilation of the Python binding
pyIEC61850and testing of thelibIEC61850server/client API use in Windows environment. - Shuo Chen: adaption of the Python binding
pyIEC61850to 64-bit linux environment (amd64, arm64) and docker application, developer of the testing scripts using thelibIEC61850server/client API. Main contributor of this git repo and the documentations. - Zhiyu Lu: compiling hints for the version libIEC61850-1.6 to get around GOOSE and SV related compiling errors. , support in establishing the docker workflow
- Zhongran Zhang: compiling of the Python binding on 32-bit linux platform, testing of the compiled libs for several OS and applications.
- Moritz Schwarz: testing of the compiled libs for several OS and applications.
- Ashish Pandey: systematic compiling and testing of the Python binding for almost common combinations of OS,
python version and
libIEC61850version except for 32-bit linux; reduction of docker image size; refinement of the workflow documentation.
The conception and implementation of pyiec61850DER was co-funded by the following research project:
-
"MeGA", grant number 03EI6108E (BMWK)
- Compiling for diverse combinations
- Implementation of the server and client tester
- Detailed documentation
-
“SERENDI-PV”, grant number 953016 (EU H2020)
- Compiling for
libIEC61850-1.4.1and Python 3.7 / 3.9 - Prototyping of the tester docker application
- Initial documentation
- Compiling for
These parts come with their own copyright and licence:
libIEC61850(incl.pyIEC61850) has Copyright (c) Michael Zillgith, MZ Automation GmbH- test tool
IEDExplorerhas Copyright (C) 2013 Pavel Charvat Docker Desktopis licensed as part of a free (Personal) or paid Docker subscription (Pro, Team or Business).
- Copyright (c) 2019-2026 J. Morris, S. Chen, Ulm University of Applied Sciences THU; Smart Grids Research Group SGFG
The compiled python libs and associated test scripts are provided under the license of GNU GPL v3. We hope they could be useful, but WITHOUT ANY WARRANTY. See the GNU General Public License for more details.
The Smart Grids Research Group keeps seeking solutions for the current and future smart grids, we are open to further discussion.
- Homepage: https://libiec61850.com/
- Github: https://github.com/mz-automation/libiec61850
- API reference model: https://support.mz-automation.de/doc/libiec61850/c/latest/index.html




