Python will not replace ladder logic or structured text on the PLC, but it is the most practical tool for what happens around the PLC: reading data from controllers, analysing logs, automating reports and prototyping condition monitoring. In the 2025 Stack Overflow Developer Survey, Python was used by 57.9% of all respondents, so help and libraries are plentiful. Use it beside the PLC, not inside the control loop.
Why would a PLC engineer learn Python?
Because the data that explains a problem usually sits outside the PLC. Production logs, alarm exports, historian files and CSV downloads need cleaning, joining and plotting, and Python does that in a few lines. It is also the language used by most data-science and machine-learning libraries, so it is the common ground when an automation team works with data engineers.
Good first uses:
- Production and alarm analysis. Load an alarm export, count alarms per hour, find the top ten nuisance alarms.
- Automated reports. Turn a daily log into an Excel or PDF summary.
- Signal analysis. Filter noisy sensor data and look at vibration in the frequency domain with SciPy.
- Test benches and data collection. Poll a PLC or sensor at a fixed rate and write to a file or database.
- Prototyping. Test an idea on logged data before building it in the PLC or SCADA.
Which Python libraries talk to industrial devices?
Four libraries cover most cases. Library status changes, so check each project page before relying on it.
| Task | Library | What to know (checked October 2026) |
|---|---|---|
| Siemens S7 PLC access | python-snap7 (import name s7 or snap7) | Version 3.3.0. Pure Python, supports S7-300/400 and S7-1200/1500 with PUT/GET enabled |
| Modbus TCP and RTU | pymodbus | Version 3.16.1. Client, server and simulator; sync and async |
| OPC UA client and server | asyncua | Version 2.1.0. Project name opcua-asyncio on GitHub; install as asyncua |
| Allen-Bradley EtherNet/IP | pycomm3 | Version 1.2.16, but the README says it is no longer actively developed |
| Data analysis | pandas, NumPy, SciPy | Tables, arrays and signal processing |
| Charts | Matplotlib, Plotly | Static and interactive plots |
Note two corrections to common advice. The OPC UA library is installed as asyncua, not "opcua-asyncio" (that is the repository name). And pycomm3 is no longer actively developed, so evaluate alternatives before using it in new work.
How do you read a Siemens PLC from Python?
Use python-snap7 on a test or non-critical controller, and understand the security trade-off first. The project README gives this minimal pattern, shown here as plain lines:
- from s7 import Client
- client = Client()
- client.connect("192.168.1.10", 0, 1)
- data = client.db_read(1, 0, 4)
- client.disconnect()
The arguments are the IP address, rack and slot, then data block number, start byte and length. The call returns raw bytes that you decode yourself, for example with Python's standard struct module for a REAL or DINT.
Three cautions from the project documentation:
- On S7-1200 and S7-1500 it only works when PUT/GET access is enabled in TIA Portal, and it cannot read optimised data blocks. You must switch off optimised block access for the data block you want.
- The README states that PUT/GET is unauthenticated and disabled by default, so leaving it disabled is the more secure configuration.
- If PUT/GET is off, or you need symbolic access, the project points to a separate library, s7commplus, which is younger and has firmware limits. For anything beyond a lab, OPC UA (below) is usually the better route.
Do not enable PUT/GET on production safety-related or critical controllers just to run a script. Agree it with whoever owns the plant's cybersecurity and change control.
How do you use Modbus and OPC UA from Python?
Both are straightforward and both are better choices than raw S7 access for production data collection. The pymodbus README shows a Modbus TCP client in four lines:
- from pymodbus.client import ModbusTcpClient
- client = ModbusTcpClient('MyDevice.lan')
- client.connect()
- result = client.read_coils(1,1)
- client.close()
Method signatures changed between pymodbus major versions, so match the examples to the installed version.
For OPC UA, the asyncua README shows the client as an asynchronous context manager: import Client from asyncua, open "async with Client(url='opc.tcp://localhost:4840/freeopcua/server/') as client", then get a node with client.get_node and read it with await node.read_value(). Use certificates and signed, encrypted endpoints when connecting to a real server. Our OPC UA guide explains the security settings.
What does a Python data workflow look like?
A reliable pattern separates collection, storage and analysis, so that each can fail independently.
- Collect. A small service polls the PLC (via OPC UA or Modbus) or subscribes to changes, and writes timestamped rows to a file or database.
- Clean. In pandas, set a datetime index, remove duplicates, handle gaps and convert units.
- Analyse. Resample to a useful interval, compute rolling statistics, flag outliers or find cycle times.
- Report. Produce a chart, a spreadsheet or a short email summary on a schedule.
- Decide. Humans or the PLC logic act on the result. Keep the control decision in the controller.
What are the limits of Python in industry?
Python is a general-purpose, interpreted language, so keep it away from jobs that need deterministic timing or certified safety.
- Not real-time. Operating-system scheduling, garbage collection and network latency make Python unsuitable for control loops measured in milliseconds.
- Not a safety function. Safety logic belongs in certified safety controllers, not scripts.
- Maintenance risk. A forgotten script on a laptop becomes an unsupported production dependency. Put code in version control, document the connection details and have an owner.
- Cybersecurity. Scripts that write to PLCs are a change-control and security matter. Prefer read-only access and least-privilege accounts.
IEC 61131-3 languages and Python are complementary: the PLC runs the machine, and Python helps you understand it.
How do I start learning?
Start with data analysis, not PLC writes. Install Python, learn pandas and Matplotlib on a downloaded CSV of alarm or sensor data, then add pymodbus against a simulator before touching any live controller. Practise the PLC side in free simulators first: the PLC simulator and ladder logic simulator run in the browser with no install.
What does a worked example look like?
Suppose a line generates an alarm export every shift and operators complain about nuisance alarms. A short script can load the CSV with pandas, convert the timestamp column to datetimes, group by alarm tag and count occurrences, then sort the result so the ten noisiest alarms appear first. Plot the counts per hour with Matplotlib and you can see whether alarms cluster around shift changes or a particular product changeover. The result is evidence to take to the engineering team, and no PLC was touched. This read-only pattern is the safest and most valuable place to begin.
How do you keep Python projects maintainable?
Treat scripts as small software products. Keep them in version control, pin library versions in a requirements file because APIs change between major releases, store connection settings in a configuration file rather than in the code, and write down which PLC addresses or OPC UA nodes each script reads. Log errors, add timeouts so a dead network does not hang the program, and name an owner who will keep it running. These habits matter more than clever code when a script becomes part of how a plant is monitored.
How EDWartens can help
EDWartens UK does not currently teach Python for industrial use in the Professional Module, and we do not claim otherwise. The Professional Module is a five-day live online class in Siemens TIA Portal (PLC, HMI, WinCC SCADA) with self-paced Basic Engineering, and the Python skills in this article build on that PLC foundation. The course is online and simulation-based, and its CPD certificate is not a regulated qualification. See the training overview or create a free account. Related: AI in manufacturing and predictive maintenance.





