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.3-cp314-cp314-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.14Windows x86-64

pyiec61850_ng-1.6.1.3-cp314-cp314-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.26+ x86-64manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.13Windows x86-64

pyiec61850_ng-1.6.1.3-cp313-cp313-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.26+ x86-64manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.12Windows x86-64

pyiec61850_ng-1.6.1.3-cp312-cp312-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.26+ x86-64manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.11Windows x86-64

pyiec61850_ng-1.6.1.3-cp311-cp311-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.26+ x86-64manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.10Windows x86-64

pyiec61850_ng-1.6.1.3-cp310-cp310-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.26+ x86-64manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.9Windows x86-64

pyiec61850_ng-1.6.1.3-cp39-cp39-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.26+ x86-64manylinux: glibc 2.28+ x86-64

File details

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

File metadata

File hashes

Hashes for pyiec61850_ng-1.6.1.3-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 a39ac906ec29929f420903797e4ec2324cac96fa3191dff6da52e8b376a75ef5
MD5 18b68c1c745ccb1ee458ea289d2ff4e6
BLAKE2b-256 72828eb21bb83d22b04cae4b3efb8ffd8710d9ce9ba59badbd206c8ec0010a4f

See more details on using hashes here.

File details

Details for the file pyiec61850_ng-1.6.1.3-cp314-cp314-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyiec61850_ng-1.6.1.3-cp314-cp314-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 440c69a978c7575956683f3df85b28fc7df8912a0a1cac7ec4371af76affaf0d
MD5 7e2cb5bf32d6fece64173e2a3eb57d2e
BLAKE2b-256 3e6e7a847070bb9155cb862e90c5543954dffed76fb0d877f43d0c6d12169b90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyiec61850_ng-1.6.1.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b2fc7ce033b8d1aad4ad449f0507fda5ec62dba09003028838e78bfc240a4e9e
MD5 b98d26cb3d7a05d78b98e1321aa024c8
BLAKE2b-256 b5590a6b8bb2928483f5527d169becc94f2b9f9bb54f48ac2cb2db1fa017c0d7

See more details on using hashes here.

File details

Details for the file pyiec61850_ng-1.6.1.3-cp313-cp313-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyiec61850_ng-1.6.1.3-cp313-cp313-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ca0867292bbecb5aba2897eae606684144bd813083e68c728796f5f2b0e5b1cd
MD5 bcecef4583d41a95c7f51b1f45bfd4c2
BLAKE2b-256 6865666218a657d9249ce48c97ce3f1349e4e0626e7824b93f6c2dca1cf44f40

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyiec61850_ng-1.6.1.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2cd8f04cdf62c1e02ef2ae5e256410161d9f2b8cf50a014c7d2be39da317af14
MD5 4afe52ed7d9ba55435d7e18fd2d96e76
BLAKE2b-256 2e6abcc6345e3c5651f286a79179b06c5cbd7686a9b35089d60748e9bdfa2ef8

See more details on using hashes here.

File details

Details for the file pyiec61850_ng-1.6.1.3-cp312-cp312-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyiec61850_ng-1.6.1.3-cp312-cp312-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6901d7f0e9a6054061d22634551ffd18933042ab5c68737fa67ca011beb0b2ab
MD5 a070f9afeedd869aeecfa13d684b9d16
BLAKE2b-256 1461f43db77683864981046559275dc6b2442dc3939ee0fc7547f4ece74e616c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyiec61850_ng-1.6.1.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 dd4ffbe67dde394648263c42df6c4252a147d82348cb5aedce2d8f486f22a9f4
MD5 5a9c836af6eded3d51f8d3d8f666ea2b
BLAKE2b-256 3f8cdd261a46a328f18c0fc91371c05dd549fba2d50f3661934c83a95cbcfa91

See more details on using hashes here.

File details

Details for the file pyiec61850_ng-1.6.1.3-cp311-cp311-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyiec61850_ng-1.6.1.3-cp311-cp311-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9d6f8d1f7702c99134d0f089344cbd40981684ab7877a69c4358e8b76c8b2850
MD5 970d07f3ea30aada722bd5969d6d8283
BLAKE2b-256 652cff96fc14a669b92e06b2dee2834ae5fa49bc84985600b6dec7a0be23da0b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyiec61850_ng-1.6.1.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8e5c6df64ee99e9b508ea151114ccf5182cb43e71588fe9c2e15c6799671a2b5
MD5 3045dae4aa5c2af5158f633e42a21d64
BLAKE2b-256 d11dd6550bbb6c55f17371a2e8e4505b4b0fd54ddb7653478014b4d466a0ed96

See more details on using hashes here.

File details

Details for the file pyiec61850_ng-1.6.1.3-cp310-cp310-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyiec61850_ng-1.6.1.3-cp310-cp310-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5563210f8c4287cedacb680240f9de680a1e43bb842002d8c926af941b0931f6
MD5 13b6b130ec816970b6bdebf15bbebba6
BLAKE2b-256 92e53ba16b6d248c71d1d9bd922cdeaa5c59208881a1715c773689476500fdcb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyiec61850_ng-1.6.1.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 c90a6c13edabb6f20b4e425891e6ed0f7d9ce1630a1d7e871ae66afab23b25dc
MD5 3cdcbe20ab7606f3235c51a38f1d7c37
BLAKE2b-256 efb15669128db766968afddc2def6817e7bf8b6cf5460995f6b52863d40327e5

See more details on using hashes here.

File details

Details for the file pyiec61850_ng-1.6.1.3-cp39-cp39-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyiec61850_ng-1.6.1.3-cp39-cp39-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 171154a8f3c464f837fd4d68bdf1880be72c0ff36cfecca780d7043d24f385ef
MD5 b4cffec1172ea6f38b5b45aa1431aba4
BLAKE2b-256 cc71472c6cc4903d6102fe4adb0bfb2c03631b113922fb9fbb70cbe83983e426

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