Python in Industrial Automation: 4 Essential Real Uses

Share:
DCS & Automation
Python in Industrial Automation

Python does not replace a PLC on a factory floor. It sits one layer above it, reading data, generating reports, and building dashboards a PLC was never designed to produce.

That layered relationship is the entire story: a PLC handles fast, deterministic control, while Python handles everything that benefits from a general purpose programming language instead.

Libraries like pymodbus and asyncua turn a few lines of Python into a working connection to real plant floor devices, no custom driver required.

This guide covers where Python genuinely earns its place in an automation stack, a real OEE calculation worked through by hand, and a calculator to run the same math instantly.

OEE Report Calculator pymodbus Code Pattern Where Python Fits, and Where It Doesn't

Python in industrial automation covers everything above the real time control layer, using libraries like pymodbus and asyncua to pull data off PLCs and OPC UA servers, then processing that data with pandas, visualizing it with plotly, and generating automated reports, dashboards, and predictive maintenance alerts that a PLC's own programming language was never built to produce.

A PLC is excellent at exactly one thing, running deterministic logic fast enough to control a machine safely, and that narrow focus is precisely why it is not the right tool for reporting, analytics, or dashboards.

Python fills that gap instead, sitting above the control layer and pulling data out of it rather than replacing it.

Python in Industrial Automation

This article covers where that split actually falls, a working code pattern for reading PLC data, and a real OEE calculation worked through both by hand and with a live calculator.

The Libraries That Do the Heavy Lifting

pymodbus handles Modbus communication, letting a script read and write registers on any Modbus TCP or RTU device with just a handful of lines of code.

asyncua provides OPC UA client and server support, the modern standard many DCS and SCADA platforms expose for structured, secure data access.

The snap7 Python library talks directly to Siemens S7 PLCs, and pandas turns thousands of rows of logged process data into a workable table in seconds rather than hours in a spreadsheet.

Advertisement
Advertisement

Where Python Sits in the Automation Stack

Python Layer Reports, dashboards, analytics, ML ↑↓ pymodbus / asyncua PLC / DCS Layer Deterministic real time control ↑↓ Field Devices: Sensors, Actuators
Python sits above the PLC layer, pulling data through Modbus or OPC UA rather than replacing the deterministic control loop underneath it.

Data flows up through this stack for reporting and analysis, while control commands stay firmly inside the PLC layer where timing guarantees actually matter.

Reading PLC Data With pymodbus

Connecting to a PLC over Modbus TCP takes only a few lines, creating a client pointed at the device's IP address and the standard Modbus port.

from pymodbus.client import ModbusTcpClient
client = ModbusTcpClient("192.168.1.10", port=502)
client.connect()

result = client.read_holding_registers(address=0, count=10, slave=1)
if not result.isError():
    for i, val in enumerate(result.registers):
        print(f"Register {i}: {val}")

Checking the result for an error before using it matters, since real networks drop packets and a script that assumes every read succeeds will eventually crash on a live line.

A continuous polling loop wraps this same read in a loop with a short pause between iterations, commonly once per second for supervisory data, far slower than the millisecond timing a PLC's own control loop runs on.

Advertisement
Advertisement

OEE Report Calculator

A very common Python automation task is pulling shift data and turning it into an Overall Equipment Effectiveness report. Enter shift data below to see the same calculation a script would run.

📊
OEE Report Calculator
Availability x Performance x Quality, the calculation behind most Python shift reports
-
-

Two OEE Calculations Worked Through

A shift with 480 minutes planned, 60 minutes of downtime, a 30 second ideal cycle time, 700 units produced and 665 good units lands at just under 70% OEE, a fairly typical result for a line with room to improve.

Planned = 480 min, Downtime = 60 min
Ideal Cycle = 30s, Total = 700, Good = 665

OEE = 69.27%

A tighter shift with only 30 minutes of downtime, a faster 45 second cycle time expectation actually being met, and a higher good count relative to total reaches 81.25% OEE, closer to what most plants consider world class performance.

Planned = 480 min, Downtime = 30 min
Ideal Cycle = 45s, Total = 550, Good = 520

OEE = 81.25%
Advertisement
Advertisement

Four Real Python Automation Use Cases

Production Data Analysis

pandas processes thousands of logged sensor rows in seconds, spotting anomalies and drift a spreadsheet would struggle with.

Automated Shift Reports

A script pulls production counts and generates an OEE or downtime report automatically at the end of every shift.

Browser Based Dashboards

A lightweight web dashboard built in Python can display live plant data without the licensing cost of a full SCADA package.

Predictive Maintenance Alerts

Machine learning libraries flag early signs of drift, warning a technician before a fault actually takes a machine down.

Where Python Fits, and Where It Doesn't

✓ Suitable For

  • Supervisory polling and data logging, comfortably down to about 10 millisecond intervals
  • Processing millions of rows of historical process data for reporting or analysis
  • Building reports, dashboards, and predictive maintenance models above the control layer
  • Talking to multiple PLC vendors and protocols from one script

✗ Not Suitable For

  • Real time motion control, Python does not offer the timing guarantees that requires
  • Safety critical logic, which belongs in a certified safety PLC, not a general purpose script
  • Sub millisecond control loops, that timing budget belongs to the PLC, not a supervisory script
  • Replacing the PLC entirely, Python complements the control layer rather than substituting for it

Resources on Python in Industrial Automation

DOC
Python for Industrial Automation: Real Uses
controlbyte.tech
DOC
Python Modbus PLC: Read and Write Data With pymodbus
controlbyte.tech
Advertisement
Advertisement

Python in Industrial Automation Questions Engineers Ask

Can Python replace a PLC entirely?
No. Python lacks the deterministic timing guarantees a PLC provides, and it is not built for safety critical logic. Python works best as a supervisory layer reading data from a PLC, not as a replacement for the PLC's control function.
What is the difference between pymodbus and asyncua?
pymodbus handles the Modbus protocol, both TCP and RTU. asyncua handles OPC UA, a more modern, structured protocol many DCS and SCADA platforms expose. The right choice depends entirely on which protocol the target device or system actually speaks.
How fast can a Python script poll a PLC?
Comfortably down to about 10 millisecond intervals for supervisory data, though real world polling rates are usually set slower, often once per second, since reporting and dashboard use cases rarely need faster updates.
Why use Python instead of a SCADA package for a dashboard?
A lightweight Python web dashboard can display live plant data without the licensing cost of a full SCADA platform, which makes it attractive for smaller monitoring projects that do not need SCADA's full feature set.
What is Overall Equipment Effectiveness and why does Python calculate it?
OEE combines availability, performance and quality into a single percentage describing how effectively a machine is running. Python is a natural fit for calculating it automatically since the underlying production counts and downtime logs already live in a database or PLC that Python can read directly.
Is Python suitable for safety instrumented systems?
No, safety instrumented functions require certified hardware and software with formal safety integrity level ratings. Python has no certification path for that role and should never be used for safety critical logic.

External References

What We Learn Today

  • Python sits above the PLC's deterministic control layer, pulling data through protocols like Modbus and OPC UA rather than replacing control logic.
  • Libraries like pymodbus, asyncua, the snap7 wrapper, and pandas cover communication and data processing without custom drivers.
  • Common real uses include shift reporting, browser dashboards, and predictive maintenance, all sitting above the millisecond timing PLCs handle.
  • Python is not suitable for real time control or safety instrumented functions, both of which stay firmly on certified PLC hardware.
"Python never drives the machine. It just makes sure someone understands what the machine already did."

Leave a Reply

Your email address will not be published. Required fields are marked *