Warning
S7CommPlus support is experimental. The API may change in future releases. If you encounter problems, please open an issue.
The s7 package provides a unified client for Siemens S7-1200 and S7-1500
PLCs. It automatically tries the S7CommPlus protocol first and falls back to
the legacy S7 protocol when needed.
from s7 import Client
client = Client()
client.connect("192.168.1.10", 0, 1)
data = client.db_read(1, 0, 4)
print(client.protocol) # Protocol.S7COMMPLUS or Protocol.LEGACY
client.disconnect()import asyncio
from s7 import AsyncClient
async def main():
client = AsyncClient()
await client.connect("192.168.1.10", 0, 1)
data = await client.db_read(1, 0, 4)
await client.disconnect()
asyncio.run(main())S7-1500 PLCs with firmware 2.x use S7CommPlus V2, which requires TLS. Pass
use_tls=True to the connect() method:
from s7 import Client
client = Client()
client.connect("192.168.1.10", 0, 1, use_tls=True)
data = client.db_read(1, 0, 4)
client.disconnect()For PLCs with custom certificates, provide the certificate paths:
client.connect(
"192.168.1.10", 0, 1,
use_tls=True,
tls_cert="/path/to/client.pem",
tls_key="/path/to/client.key",
tls_ca="/path/to/ca.pem",
)Password-protected PLCs require the password keyword argument:
from s7 import Client
client = Client()
client.connect("192.168.1.10", 0, 1, use_tls=True, password="my_plc_password")
data = client.db_read(1, 0, 4)
client.disconnect()By default the client uses Protocol.AUTO which tries S7CommPlus first.
You can force a specific protocol:
from s7 import Client, Protocol
# Force legacy S7 only
client = Client()
client.connect("192.168.1.10", 0, 1, protocol=Protocol.LEGACY)
# Force S7CommPlus (raises on failure)
client.connect("192.168.1.10", 0, 1, protocol=Protocol.S7COMMPLUS).. automodule:: s7.client :members:
.. automodule:: s7.async_client :members: