Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
d7556ff
chore(deps): bump the all-dependencies group with 4 updates (#609)
dependabot[bot] Mar 18, 2026
3ae975f
Update documentation for 3.0 release
gijzelaerr Mar 18, 2026
d779ba3
Add note explaining the historical python-snap7 name
gijzelaerr Mar 18, 2026
f880d8c
Add contributors to 3.0.0 release notes
gijzelaerr Mar 18, 2026
4c52bcb
Add coverage badge and coverage threshold (#637)
gijzelaerr Mar 20, 2026
67713e2
Add comprehensive tests for partner.py (57% -> 84% coverage) (#645)
gijzelaerr Mar 20, 2026
60047da
Accept memoryview in setter and getter type annotations (#647)
gijzelaerr Mar 20, 2026
6ccacf5
Add integration tests for server block operations and USERDATA handle…
gijzelaerr Mar 20, 2026
4bded55
Add tests for snap7/logo.py to improve coverage from 53% to 97% (#643)
gijzelaerr Mar 20, 2026
5443402
Add tests to improve coverage from 78% to 84% (#642)
gijzelaerr Mar 20, 2026
fe6df93
Add native AsyncClient with asyncio support (#593)
gijzelaerr Mar 20, 2026
d52b70b
Add S7CommPlus protocol scaffolding for S7-1200/1500 (#603)
gijzelaerr Mar 20, 2026
a2561a2
Enhanced CLI tools for PLC interaction (#631)
gijzelaerr Mar 20, 2026
ab09964
Add typed DB access methods for common S7 data types (#632)
gijzelaerr Mar 20, 2026
108a107
Add protocol conformance test suite (#633)
gijzelaerr Mar 20, 2026
f0634f8
Add examples cookbook and troubleshooting documentation (#610)
gijzelaerr Mar 20, 2026
b16c707
Cleanup: consolidate tests, docs, and README (#648)
gijzelaerr Mar 20, 2026
76acf91
Restructure docs into logical sections (#649)
gijzelaerr Mar 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ jobs:
uv pip install ".[test]"
- name: Run pytest
run: uv run pytest --cov=snap7 --cov-report=xml --cov-report=term
- name: Upload coverage report
- name: Upload coverage to Codecov
if: matrix.python-version == '3.13' && matrix.runs-on == 'ubuntu-24.04'
uses: actions/upload-artifact@v7
uses: codecov/codecov-action@v5
with:
name: coverage-report
path: coverage.xml
files: coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
26 changes: 24 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,43 @@ CHANGES
-----

Major release: python-snap7 is now a pure Python S7 communication library.
This version completely breaks with the previous approach of wrapping the C snap7
shared library. The entire S7 protocol stack is now implemented in pure Python,
greatly improving portability and making it easier to install and extend.

* **Breaking**: The C snap7 library is no longer required or used
* Complete rewrite of the S7 protocol stack in pure Python
* Native Python implementation of TPKT (RFC 1006) and COTP (ISO 8073) layers
* Native S7 protocol PDU encoding/decoding
* Pure Python server implementation for testing and simulation
* No platform-specific binary dependencies
* No platform-specific binary dependencies — works on any platform that runs Python
* Improved error handling and connection management
* Full type annotations with mypy strict mode
* CLI interface for running an S7 server emulator (`pip install "python-snap7[cli]"`)

If you experience issues with 3.0, pin to the last pre-3.0 release:
If you experience issues with 3.0, please report them on the
[issue tracker](https://github.com/gijzelaerr/python-snap7/issues) with a clear
description and the version you are using. As a workaround, pin to the last
pre-3.0 release:

$ pip install "python-snap7<3"

### Thanks

Special thanks to the following people for testing, reporting issues, and providing
feedback during the 3.0 development:

* [@lupaulus](https://github.com/lupaulus) — extensive testing and bug reports
* [@spreeker](https://github.com/spreeker) — testing and feedback
* [@nikteliy](https://github.com/nikteliy) — review and feedback on the rewrite
* [@amorelettronico](https://github.com/amorelettronico) — testing
* [@razour08](https://github.com/razour08) — testing
* [@core-engineering](https://github.com/core-engineering) — bug reports (#553)
* [@AndreasScharf](https://github.com/AndreasScharf) — bug reports (#572)
* [@Robatronic](https://github.com/Robatronic) — bug reports (#574)
* [@hirotasoshu](https://github.com/hirotasoshu) — feedback (#545)
* [@PoitrasJ](https://github.com/PoitrasJ) — bug reports (#479)

1.2
---

Expand Down
56 changes: 47 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,25 +1,63 @@
.. image:: https://img.shields.io/pypi/v/python-snap7.svg
:target: https://pypi.org/project/python-snap7/

.. image:: https://img.shields.io/pypi/pyversions/python-snap7.svg
:target: https://pypi.org/project/python-snap7/

.. image:: https://img.shields.io/github/license/gijzelaerr/python-snap7.svg
:target: https://github.com/gijzelaerr/python-snap7/blob/master/LICENSE

.. image:: https://github.com/gijzelaerr/python-snap7/actions/workflows/test.yml/badge.svg
:target: https://github.com/gijzelaerr/python-snap7/actions/workflows/test.yml

.. image:: https://readthedocs.org/projects/python-snap7/badge/
:target: https://python-snap7.readthedocs.io/en/latest/

.. image:: https://codecov.io/gh/gijzelaerr/python-snap7/branch/master/graph/badge.svg
:target: https://codecov.io/gh/gijzelaerr/python-snap7

About
=====

Python-snap7 is a pure Python S7 communication library for interfacing with Siemens S7 PLCs.

The name "python-snap7" is historical — the library originally started as a Python wrapper
around the `Snap7 <http://snap7.sourceforge.net/>`_ C library. As of version 3.0, the C
library is no longer used, but the name is kept for backwards compatibility.

Python-snap7 is tested with Python 3.10+, on Windows, Linux and OS X.

The full documentation is available on `Read The Docs <https://python-snap7.readthedocs.io/en/latest/>`_.


Version 3.0 - Breaking Changes
===============================
Version 3.0 - Pure Python Rewrite
==================================

Version 3.0 is a ground-up rewrite of python-snap7. The library no longer wraps the
C snap7 shared library — instead, the entire S7 protocol stack (TPKT, COTP, and S7)
is now implemented in pure Python. This is a **breaking change** from all previous
versions.

**Why this matters:**

* **Portability**: No more platform-specific shared libraries (`.dll`, `.so`, `.dylib`).
python-snap7 now works on any platform that runs Python — including ARM, Alpine Linux,
and other environments where the C library was difficult or impossible to install.
* **Easier installation**: Just ``pip install python-snap7``. No native dependencies,
no compiler toolchains, no manual library setup.
* **Easier to extend**: New features and protocol support can be added directly in Python.

Version 3.0 is a major release that rewrites python-snap7 as a pure Python
implementation. The C snap7 library is no longer required.
**If you experience issues with 3.0:**

This release may contain breaking changes. If you experience issues, you can
pin to the last pre-3.0 release::
1. Please report them on the `issue tracker <https://github.com/gijzelaerr/python-snap7/issues>`_
with a clear description of the problem and the version you are using
(``python -c "import snap7; print(snap7.__version__)"``).
2. As a workaround, you can pin to the last pre-3.0 release::

$ pip install "python-snap7<3"
$ pip install "python-snap7<3"

The latest stable pre-3.0 release is version 2.1.0.
The latest stable pre-3.0 release is version 2.1.0. Documentation for pre-3.0
versions is available at `Read The Docs <https://python-snap7.readthedocs.io/en/v2/>`_.


Installation
Expand All @@ -29,4 +67,4 @@ Install using pip::

$ pip install python-snap7

No native libraries or platform-specific dependencies are required - python-snap7 is a pure Python package that works on all platforms.
No native libraries or platform-specific dependencies are required python-snap7 is a pure Python package that works on all platforms.
5 changes: 5 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
coverage:
status:
project:
default:
target: 80%
49 changes: 49 additions & 0 deletions doc/API/async_client.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
AsyncClient
===========

.. warning::

The ``AsyncClient`` is **experimental**. The API may change in future
releases. If you encounter problems, please `open an issue
<https://github.com/gijzelaerr/python-snap7/issues>`_.

The :class:`~snap7.async_client.AsyncClient` provides a native ``asyncio``
interface for communicating with Siemens S7 PLCs. It has feature parity with
the synchronous :class:`~snap7.client.Client` and is safe for concurrent use
via ``asyncio.gather()``.

Quick start
-----------

.. code-block:: python

import asyncio
import snap7

async def main():
async with snap7.AsyncClient() as client:
await client.connect("192.168.1.10", 0, 1)
data = await client.db_read(1, 0, 4)
print(data)

asyncio.run(main())

Concurrent reads
----------------

An internal ``asyncio.Lock`` serialises each send/receive cycle so that
multiple coroutines can safely share a single connection:

.. code-block:: python

results = await asyncio.gather(
client.db_read(1, 0, 4),
client.db_read(1, 10, 4),
)

API reference
-------------

.. automodule:: snap7.async_client
:members:
:exclude-members: AsyncISOTCPConnection
70 changes: 70 additions & 0 deletions doc/API/s7commplus.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
S7CommPlus (S7-1200/1500)
=========================

.. warning::

S7CommPlus support is **experimental**. The API may change in future
releases. If you encounter problems, please `open an issue
<https://github.com/gijzelaerr/python-snap7/issues>`_.

The :mod:`snap7.s7commplus` package provides support for Siemens S7-1200 and
S7-1500 PLCs, which use the S7CommPlus protocol instead of the classic S7
protocol used by S7-300/400.

Both synchronous and asynchronous clients are available. When a PLC does not
support S7CommPlus data operations, the clients automatically fall back to the
legacy S7 protocol transparently.

Synchronous client
------------------

.. code-block:: python

from snap7.s7commplus.client import S7CommPlusClient

client = S7CommPlusClient()
client.connect("192.168.1.10")
data = client.db_read(1, 0, 4)
client.disconnect()

Asynchronous client
-------------------

.. code-block:: python

import asyncio
from snap7.s7commplus.async_client import S7CommPlusAsyncClient

async def main():
client = S7CommPlusAsyncClient()
await client.connect("192.168.1.10")
data = await client.db_read(1, 0, 4)
await client.disconnect()

asyncio.run(main())

Legacy fallback
---------------

If the PLC returns an error for S7CommPlus data operations (common with some
firmware versions), the client automatically falls back to the classic S7
protocol. You can check whether fallback is active:

.. code-block:: python

client.connect("192.168.1.10")
if client.using_legacy_fallback:
print("Using legacy S7 protocol")

API reference
-------------

.. automodule:: snap7.s7commplus.client
:members:

.. automodule:: snap7.s7commplus.async_client
:members:

.. automodule:: snap7.s7commplus.connection
:members:
:exclude-members: S7CommPlusConnection
100 changes: 100 additions & 0 deletions doc/connecting.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
Connecting to PLCs
==================

This page shows how to connect to different Siemens PLC models using
python-snap7.

.. contents:: On this page
:local:
:depth: 2


Rack/Slot Reference
-------------------

.. list-table::
:header-rows: 1
:widths: 20 10 10 60

* - PLC Model
- Rack
- Slot
- Notes
* - S7-300
- 0
- 2
-
* - S7-400
- 0
- 3
- May vary with multi-rack configurations
* - S7-1200
- 0
- 1
- PUT/GET access must be enabled in TIA Portal
* - S7-1500
- 0
- 1
- PUT/GET access must be enabled in TIA Portal
* - S7-200 / Logo
- --
- --
- Use ``set_connection_params`` with TSAP addressing

.. warning::

S7-1200 and S7-1500 PLCs ship with PUT/GET communication disabled by
default. Enable it in TIA Portal under the CPU properties before
connecting. See :doc:`tia-portal-config` for step-by-step instructions.


S7-300
------

.. code-block:: python

import snap7

client = snap7.Client()
client.connect("192.168.1.10", 0, 2)

S7-400
------

.. code-block:: python

import snap7

client = snap7.Client()
client.connect("192.168.1.10", 0, 3)

S7-1200 / S7-1500
------------------

.. code-block:: python

import snap7

client = snap7.Client()
client.connect("192.168.1.10", 0, 1)

S7-200 / Logo (TSAP Connection)
--------------------------------

.. code-block:: python

import snap7

client = snap7.Client()
client.set_connection_params("192.168.1.10", 0x1000, 0x2000)
client.connect("192.168.1.10", 0, 0)

Using a Non-Standard Port
--------------------------

.. code-block:: python

import snap7

client = snap7.Client()
client.connect("192.168.1.10", 0, 1, tcp_port=1102)
Loading