python-snap7 is a pure Python S7 communication library for Siemens PLCs, implementing the full protocol stack (TPKT, COTP, S7) in Python. As of version 3.0.0, it no longer requires the underlying Snap7 C library. It provides an interface for connecting to and interacting with Siemens S7-300, S7-400, S7-1200, and S7-1500 PLCs. The library is actively maintained with a moderate release cadence, with major versions introducing significant architectural changes.
pip install python-snap7Verified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to connect to a Siemens PLC using `snap7.client.Client`, read 10 bytes from Data Block (DB) 10, and then disconnect. Ensure the PLC's IP address, rack, and slot are correctly configured. Remember to enable PUT/GET communication on your PLC for the library to function correctly.
Update your code to use `from snap7.client import Client` instead of `import snap7.snap7` or `from snap7 import snap7`. Remove any manual C library installations (`libsnap7.so`, `snap7.dll`). Consult the v3.0.0 documentation for updated API specifics.
Review the official documentation and changelog for `python-snap7` v2.x to v3.x migration. Pay close attention to method signatures and data type handling, especially if upgrading from pre-2.0 versions.
For versions prior to 3.0.0, ensure the Snap7 C library is correctly installed for your operating system and its location is known to your environment. For v3.0.0+, this is no longer necessary.
Check your PLC's TIA Portal project settings for the CPU and ensure PUT/GET communication is enabled. Also verify firewall rules on both the PLC network and the client machine.
Update your import statements to use the new pure Python client: `from snap7.client import Client`.
1. Verify `plc_ip`, `plc_rack`, `plc_slot` are correct. 2. Ping the PLC's IP address. 3. Ensure PUT/GET communication is enabled in the PLC's TIA Portal project. 4. Check network firewalls on both the client and PLC side.
Convert your string data to a `bytearray` or `bytes` object before passing it to the write functions. Example: `data_to_write = bytearray(b'Hello')` or `data_to_write = 'Hello'.encode('ascii')`.No dependency data recorded yet.