Metadata-Version: 2.5
Name: fieldsim
Version: 0.4.0
Summary: Virtual Modbus, OPC UA and S7 devices for testing industrial software without hardware.
Project-URL: Homepage, https://github.com/enesuslu15/fieldsim
Project-URL: Documentation, https://enesuslu15.github.io/fieldsim/
Project-URL: Changelog, https://github.com/enesuslu15/fieldsim/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/enesuslu15/fieldsim/issues
Author: enesuslu15
License: MIT License
        
        Copyright (c) 2026 enesuslu15
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: iiot,industrial,modbus,opc-ua,plc,pytest,s7,siemens,simulator,testing
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: AsyncIO
Classifier: Framework :: Pytest
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Manufacturing
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: System :: Networking
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: pydantic<3,>=2.6
Requires-Dist: pyyaml>=6.0
Requires-Dist: typer>=0.12
Provides-Extra: all
Requires-Dist: asyncua<3,>=2.1; extra == 'all'
Requires-Dist: python-snap7<4,>=3.4; extra == 'all'
Provides-Extra: dev
Requires-Dist: asyncua<3,>=2.1; extra == 'dev'
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: pre-commit>=3.5; extra == 'dev'
Requires-Dist: pymodbus<4,>=3.10; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: python-snap7<4,>=3.4; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Requires-Dist: types-pyyaml; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
Requires-Dist: mkdocstrings[python]>=0.26; extra == 'docs'
Provides-Extra: opcua
Requires-Dist: asyncua<3,>=2.1; extra == 'opcua'
Provides-Extra: s7
Requires-Dist: python-snap7<4,>=3.4; extra == 's7'
Description-Content-Type: text/markdown

# fieldsim

[![PyPI](https://img.shields.io/pypi/v/fieldsim)](https://pypi.org/project/fieldsim/)
[![Python](https://img.shields.io/pypi/pyversions/fieldsim)](https://pypi.org/project/fieldsim/)
[![CI](https://github.com/enesuslu15/fieldsim/actions/workflows/ci.yml/badge.svg)](https://github.com/enesuslu15/fieldsim/actions/workflows/ci.yml)
[![Docs](https://github.com/enesuslu15/fieldsim/actions/workflows/docs.yml/badge.svg)](https://enesuslu15.github.io/fieldsim/)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue)](LICENSE)

**Virtual industrial devices for testing software without hardware.**

fieldsim starts fake **Modbus**, **OPC UA** and **Siemens S7** devices from a YAML
file, drives their values with generators, breaks them on purpose with fault
injection and plays scripted scenarios — so you can test gateways, SCADA
connectors and edge apps in CI, no PLC on your desk required.

📖 **Documentation: <https://enesuslu15.github.io/fieldsim/>**

```python
import pytest


@pytest.mark.fieldsim("boiler.yaml")
def test_gateway_survives_a_slow_plc(modbus_device):
    modbus_device.set("temperature", 85.0)  # pauses the generator
    with modbus_device.fault("latency", delay="800ms"):
        assert Gateway(*modbus_device.address, timeout=1).temperature() == 85.0


@pytest.mark.fieldsim("boiler.yaml", clock="virtual")
def test_overheat_alarm(modbus_device):
    modbus_device.advance(600)  # ten minutes, instantly
    assert Gateway(*modbus_device.address).alarm_raised()
```

## Install

```bash
pip install fieldsim             # Modbus TCP / RTU over TCP
pip install "fieldsim[opcua]"    # + OPC UA
pip install "fieldsim[s7]"       # + Siemens S7 (experimental)
pip install "fieldsim[all]"      # everything
```

or run it as a container:

```bash
docker run --rm -p 5020:5020 -v "$PWD/boiler.yaml:/config/devices.yaml:ro" ghcr.io/enesuslu15/fieldsim
```

## Features

- **Three protocols** — Modbus TCP and RTU over TCP (own asyncio server), OPC UA
  (on asyncua) and S7comm (on python-snap7, experimental), mixed freely in one file.
- **Devices from YAML** — register maps, OPC UA node trees, S7 data blocks; typed
  points with byte/word order, validated with precise error locations and a JSON
  Schema for editor autocompletion.
- **Generators** — sine, ramp, random walk, sequence, so data looks like a
  running machine.
- **Fault injection** — latency, lost responses (optionally after executing the
  request), disconnects, Modbus exceptions, OPC UA status codes, six kinds of
  corrupted frames, outages; filtered by function code or service, by
  probability or count, reproducible with a seed.
- **Scenarios and virtual time** — "overheat at 30 s, outage at 60 s", played
  instantly and identically on every run.
- **pytest plugin** — `modbus_device`, `opcua_device`, `s7_device`, factories and
  a marker; free ports, background thread, works for sync, asyncio and xdist.
- **Write log** — `wait_for_write("setpoint")` to assert what your code sent.
- **CI ready** — CLI (`init`, `validate`, `run`, `check`, `schema`), a multi-arch
  Docker image with a health check, copy-paste GitHub Actions jobs.

## A device file

```yaml
version: 1
devices:
  - name: boiler-plc
    protocol: modbus_tcp
    port: 5020
    registers:
      holding_registers:
        - name: temperature
          address: 0
          type: float32
          generator: { type: sine, min: 60, max: 90, period: 30s }
        - { name: setpoint, address: 2, type: uint16, value: 75 }
    faults:
      - { type: latency, delay: 20ms, jitter: 10ms }
    scenario:
      - { at: 30s, set: { temperature: 120 } }
      - { at: 40s, fault: { type: exception, code: 6 }, duration: 5s }
      - { at: 60s, offline: 10s }

  - name: packaging-line
    protocol: opcua
    port: 4840
    nodes:
      - name: Line1
        nodes:
          - { name: Speed, type: Double, generator: { type: ramp, start: 0, end: 2, period: 1m } }
          - { name: Product, type: String, value: A-100, writable: true }

  - name: press-plc
    protocol: s7
    port: 1102
    data_blocks:
      - number: 10
        points:
          - { name: pressure, offset: 0, type: REAL, value: 200.0 }    # DB10.DBD0
          - { name: running, offset: 8, bit: 0, type: BOOL }           # DB10.DBX8.0
```

```bash
fieldsim validate plant.yaml
fieldsim run plant.yaml
```

More in the [examples](examples/) folder and the
[documentation](https://enesuslu15.github.io/fieldsim/).

## Contributing

Issues and pull requests are welcome — see [CONTRIBUTING.md](CONTRIBUTING.md).
fieldsim follows [Semantic Versioning](https://semver.org/); changes are listed in
the [changelog](CHANGELOG.md).

## License

MIT
