Skip to main content

Python bindings for libiec61850 - IEC 61850 protocol implementation

Project description

pyiec61850-ng

This library is experimental. Use at your own risk. No warranty of any kind is provided.

Next Generation Python bindings for libiec61850, packaged as a Python wheel.

Build and Test PyPI version Python Versions

This repository provides Python bindings for the libiec61850 library, which is an open-source implementation of the IEC 61850 standard for communication networks and systems in substations.

Installation

Install from PyPI (Recommended)

pip install pyiec61850-ng

Install from GitHub Release

pip install pyiec61850-ng --find-links https://github.com/f0rw4rd/pyiec61850-ng/releases/latest/download/

Install directly from GitHub

pip install git+https://github.com/f0rw4rd/pyiec61850-ng.git

Install from local wheel

pip install pyiec61850-ng-*.whl

Usage

Quick Start (Recommended - Safe API)

from pyiec61850.mms import MMSClient

# Use context manager for automatic cleanup
with MMSClient() as client:
    client.connect("192.168.1.100", 102)
    print("Connected successfully!")

    # Get server identity
    identity = client.get_server_identity()
    print(f"Server: {identity.vendor} {identity.model}")

    # Discover logical devices
    devices = client.get_logical_devices()
    for device in devices:
        print(f"Device: {device}")

        # Get logical nodes
        nodes = client.get_logical_nodes(device)
        for node in nodes:
            print(f"  Node: {node}")

# Connection automatically closed

Low-Level API

For advanced use cases, you can use the raw bindings directly:

import pyiec61850.pyiec61850 as pyiec61850

# Create and connect to an IEC 61850 server
connection = pyiec61850.IedConnection_create()
error = pyiec61850.IedConnection_connect(connection, "192.168.1.100", 102)

if error == pyiec61850.IED_ERROR_OK:
    print("Connected successfully!")
    # Perform operations...
    pyiec61850.IedConnection_close(connection)

pyiec61850.IedConnection_destroy(connection)

Examples

For comprehensive examples, see the examples directory:

Run examples:

python examples/01_basic_connection.py 192.168.1.100
python examples/02_device_discovery.py 192.168.1.100

Building from Source

The wheel package is built using Docker:

docker build -t pyiec61850-builder --build-arg LIBIEC61850_VERSION=v1.6 .

To extract the wheel file:

mkdir -p ./dist
docker create --name wheel-container pyiec61850-builder
docker cp wheel-container:/wheels/. ./dist/
docker rm wheel-container

Versioning

This package uses the format: LIBIEC61850_VERSION.REVISION

  • Example: 1.6.0.1 = libiec61850 v1.6.0, first package revision
  • 1.6.0: The exact libiec61850 version included (static)
  • .1: Package revision for bug fixes, rebuilds, binding improvements

This clearly shows which libiec61850 version you're getting and our package iteration.

Check current version:

python version.py        # Package version: 1.6.0.1
python version.py --libiec61850  # libiec61850 version: v1.6.0

TASE.2/ICCP Support (Highly Experimental)

Warning: TASE.2 support is highly experimental and may change significantly.

pyiec61850-ng includes support for TASE.2 (IEC 60870-6), also known as ICCP (Inter-Control Center Communications Protocol), used for real-time data exchange between control centers in the electric utility industry.

TASE.2 Quick Start

from pyiec61850.tase2 import TASE2Client

client = TASE2Client(
    local_ap_title="1.1.1.999",
    remote_ap_title="1.1.1.998"
)
client.connect("192.168.1.100", port=102)

# Discover domains (VCC/ICC)
domains = client.get_domains()
for domain in domains:
    print(f"Domain: {domain.name} ({domain.domain_type})")

# Read a data point
value = client.read_point("ICC1", "Voltage")
print(f"Value: {value.value}, Quality: {value.quality}")

# Security analysis
security = client.analyze_security()
print(f"Readable points: {security['readable_points']}")
print(f"Concerns: {security['concerns']}")

client.disconnect()

TASE.2 Features

  • Domain Discovery: VCC (Virtual Control Center) and ICC (Indication Control Center)
  • Variable Enumeration: List and read data points with quality information
  • Data Point Access: Read/write individual points or bulk enumeration
  • Transfer Sets (Block 2): RBE (Report-by-Exception) management
  • Device Control (Block 5): Select-Before-Operate, commands, setpoints
  • Bilateral Tables: Access control configuration queries
  • Security Analysis: Automated security assessment and recommendations

TASE.2 Data Types

from pyiec61850.tase2 import (
    Domain,          # VCC/ICC domain
    PointValue,      # Data point with value and quality
    TransferSet,     # Block 2 transfer set
    BilateralTable,  # Access control table
    ServerInfo,      # Server information
)

MMS Module (Safe Wrappers)

The pyiec61850.mms module provides safe Python wrappers around the raw SWIG bindings, preventing common crashes from NULL pointer dereferences and memory leaks.

Why Use the Safe Wrappers?

The raw pyiec61850 bindings require careful memory management:

  • LinkedList_destroy() must be called after iteration
  • MmsValue_delete() must be called after reading values
  • toCharP() crashes on NULL pointers

The MMS module handles all of this automatically.

MMS Client Example

from pyiec61850.mms import MMSClient, ConnectionFailedError

with MMSClient() as client:
    try:
        client.connect("192.168.1.100", 102)

        # All memory management is automatic
        for device in client.get_logical_devices():
            for node in client.get_logical_nodes(device):
                print(f"{device}/{node}")

    except ConnectionFailedError as e:
        print(f"Connection failed: {e}")

Safe Utilities for Raw Bindings

If you need to use raw bindings, use the safe utilities:

from pyiec61850.mms.utils import (
    safe_to_char_p,        # NULL-safe string conversion
    LinkedListGuard,       # Auto-cleanup context manager
    MmsValueGuard,         # Auto-cleanup for MmsValue
)
import pyiec61850.pyiec61850 as iec61850

# Safe iteration with automatic cleanup
result = iec61850.IedConnection_getLogicalDeviceList(connection)
device_list, error = result

with LinkedListGuard(device_list) as guard:
    for device_name in guard:  # NULL pointers automatically skipped
        print(device_name)
# LinkedList automatically destroyed

License

This project is licensed under the GNU General Public License v3.0 (GPLv3) - see the LICENSE file for details.

Third-Party Components

  • libiec61850 by MZ Automation GmbH - GPLv3 (commercial license available)
  • Mbed TLS - Apache License 2.0

The compiled libiec61850.so and SWIG bindings included in wheel distributions are built from the libiec61850 source code. See the NOTICE file for full attribution details.

For commercial use cases where GPLv3 is not suitable, a commercial license for libiec61850 is available from MZ Automation GmbH.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyiec61850_ng-1.6.1.0-cp314-cp314-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.14Windows x86-64

pyiec61850_ng-1.6.1.0-cp313-cp313-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.13Windows x86-64

pyiec61850_ng-1.6.1.0-cp312-cp312-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.12Windows x86-64

pyiec61850_ng-1.6.1.0-cp311-cp311-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.11Windows x86-64

pyiec61850_ng-1.6.1.0-cp310-cp310-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.10Windows x86-64

pyiec61850_ng-1.6.1.0-cp39-cp39-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.9Windows x86-64

File details

Details for the file pyiec61850_ng-1.6.1.0-py3-none-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for pyiec61850_ng-1.6.1.0-py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 bb744d2d21afbcd056411860eb5ddd3e36422c5b40d5ad36169054a2652f436d
MD5 14d650b29a83598bc4f39168c7cbaeb8
BLAKE2b-256 75b1b0f0c625daddd6990bc95b6b589ebab28fe88d5f48a79b5c0cbd8ae1651e

See more details on using hashes here.

File details

Details for the file pyiec61850_ng-1.6.1.0-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for pyiec61850_ng-1.6.1.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 23ee49559207206ca2bd279ff2b50e1462bf2f37b81559e1fcec9f800303647d
MD5 0f6663ec94a53f0bb0be3e5f68da602b
BLAKE2b-256 df775dd37a51142778f059539b2422045ae817ba46438eaafc4959e27efe3b1d

See more details on using hashes here.

File details

Details for the file pyiec61850_ng-1.6.1.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for pyiec61850_ng-1.6.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ed4d9fbb93bcc356d2db451c9cb3457f8938d680872b48fddb9e612ebeb6499e
MD5 d8df98040f4626ef89b9d9e1edd9b7d5
BLAKE2b-256 17bd275eabc45f4bd824ade5bf88d09c8790e77885c93e1f69a5b9201d7cb22c

See more details on using hashes here.

File details

Details for the file pyiec61850_ng-1.6.1.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for pyiec61850_ng-1.6.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 11e87362aa06775ebd30f37b5806bc220ecdc9c98de9bccfdc1c7a012796924c
MD5 c7b0fdeb73e673833b5aa968bc7d3ff4
BLAKE2b-256 ea62e9b6949e35f7b775316860a447b44f2a9ac9f37f4ac3538e5f62c26f3cc9

See more details on using hashes here.

File details

Details for the file pyiec61850_ng-1.6.1.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pyiec61850_ng-1.6.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9fde9d718d70f6c2c9702587d70cb9a33f1d642db9dde67a27d0ee0b9ac830f7
MD5 b5d94db55d840e18ed9c68352065981e
BLAKE2b-256 c41cff85e7f854e777ce2e533e1142d6b7966fc35bfe7952549fd4182b28a26c

See more details on using hashes here.

File details

Details for the file pyiec61850_ng-1.6.1.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pyiec61850_ng-1.6.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 eb70192888bf2c21b2009903720d7dd230e5780000c24fc33c8de1d915f10263
MD5 be195dc8bc58e4c22ed8797edaed9597
BLAKE2b-256 6c41fa11cfe3d540002abe14669898e749341f583fb91c6f5ddf1a93b1c2db91

See more details on using hashes here.

File details

Details for the file pyiec61850_ng-1.6.1.0-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for pyiec61850_ng-1.6.1.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 8ed63f72fbe82660758984b1ff2f397f5b5e0c76c48e86681465a1fc6e8de759
MD5 ebe9259c2fc34896cff76aaa99be35a4
BLAKE2b-256 b1e10bd998156ae19409ff4d6fa424663b65a8b1dd57a2c51a07274408281a09

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page