Table of Contents
TogglePython 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.
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.

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.
Where Python Sits in the Automation Stack
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.
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.
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.
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.
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.
Ideal Cycle = 45s, Total = 550, Good = 520
OEE = 81.25%
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
Python in Industrial Automation Questions Engineers Ask
Related Articles
External References
- ControlByte: Python for Industrial Automation, Real Uses
- ControlByte: Python Modbus PLC, Read and Write Data With pymodbus
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.
