SMOLPy

Python rewrite of SMOL — a Network Description Language and Discrete-Event Simulator for industrial Measurement-Diagnostics-Control (MDC) networks.
SMOLPy lets you describe a network topology in pure Python, define traffic flows, and run a discrete-event simulation that produces real metric time-series. A built-in Dear PyGui desktop dashboard shows the topology and live metric charts as the simulation runs.
Three simulation engines, one model. A scenario, written in Python or in a .smol file, becomes one execution-independent model, and it runs on any of three engines:
- SimPy (Python): the reference implementation. It is always installed, runs the whole model and drives the dashboards.
- Rust (
smol-engine): a native engine that gives SimPy's results bit for bit and runs about 40× faster. B1 at 10 M frames takes 4.9 s, against 200.8 s on SimPy.
- ns-3: the same scenario on ns-3, the established network simulator, with its real IPv4, UDP and TCP stack. Modbus TCP and MQTT run over ns-3's TCP, with its handshake, acknowledgements, and flow and congestion control. Ethernet and PROFINET RT give SimPy's results bit for bit.
result = net.simulate(duration=60_000, backend="rust") # or "ns3"
Every engine runs the whole model: Ethernet, Modbus TCP, MQTT and PROFINET RT. Only the live and text dashboards need SimPy. See Simulation engine, Running on ns-3 and Execution backends.
📖 Full documentation: jwszolek.github.io/SMOLPy
Supported protocols
| Protocol |
Runs over |
Communication pattern |
Nodes / API |
.smol statements |
Key metrics |
| Ethernet (generic traffic) |
Layer 2 frames |
One-way flows: constant, Poisson, bursty, batch |
Adapter.sends() |
flow |
throughput, latency, bytes_sent, bytes_received |
| MQTT |
TCP/IP |
Publish / subscribe through a broker, QoS 0 and 1 |
MQTTBroker, Adapter.publishes(), MQTTBroker.routes() |
mqtt_broker, publish, route |
broker_queue, latency |
| Modbus TCP |
TCP/IP |
Request / response polling (Read Holding Registers, FC 03) |
ModbusSlave, Adapter.polls() |
modbus_slave, poll |
modbus_latency, modbus_unanswered, modbus_timeouts, modbus_skipped |
| PROFINET RT |
Layer 2 (EtherType 0x8892), 802.1Q priority 6 |
Cyclic producer / consumer exchange with watchdog |
ProfinetDevice, Adapter.controls() |
profinet_device, control |
pn_latency, pn_jitter, pn_watchdog_expiries |
Infrastructure: MAC-learning switches with 802.1Q strict-priority egress queues (qos="strict", or qos="fifo" to disable prioritisation), unbounded or bounded with tail drop (buffer= in bytes). One Adapter can act in several roles at once — e.g. a PLC that is a Modbus master, an MQTT publisher and a PROFINET controller.
Not supported (yet): PROFINET IRT, PROFIBUS, EtherNet/IP, EtherCAT, OPC UA, Modbus RTU (serial), and Modbus write function codes. See the Architecture Decision Records for what is planned.
Install
pip install smolpy # SimPy engine, dashboards, CLI
pip install "smolpy[rust]" # plus the native Rust engine, about 40x faster
pip install --pre "smolpy[rust]" # the latest development build of main
Release channels. The versions below are read live from PyPI and GitHub, so this table is always current:
| Channel |
smolpy |
smolpy-engine-rs |
Install |
| Stable, released by hand |
 |
 |
pip install "smolpy[rust]" |
Development, every merge to main |
 |
same version |
pip install --pre "smolpy[rust]" |
- What a development build is. Every merge to
main that changes the package publishes one, as X.Y.(Z+1).devN, N commits after the latest release.
- How to get it. It is a pre-release on PyPI, so
pip installs it only with --pre.
- Where it is on GitHub. The Development build pre-release points to its commit.
- Releases proper are made by hand.
Without Python, from the Docker image of each release, which has SMOLPy and the Rust engine for linux/amd64 and linux/arm64:
docker run --rm -v "$PWD:/work" ghcr.io/jwszolek/smolpy run plant.smol --backend rust -o results.csv
- The image runs headless: the live dashboard needs a display, so a
.smol file needs mode=headless or mode=text.
- It runs as uid 1000. To own the files it writes as yourself, add
--user "$(id -u):$(id -g)".
- A version is pinned as
ghcr.io/jwszolek/smolpy:<version>; latest is the latest release.
With ns-3, from the image <version>-ns3 or latest-ns3, published from 1.10.0 on, for linux/amd64 and, from the release after 1.10.1, linux/arm64. It adds the pinned ns-3 build and the ns-3 backend, ready to run:
docker run --rm -v "$PWD:/work" ghcr.io/jwszolek/smolpy:latest-ns3 run plant.smol --backend ns3 -o results.csv
- It is about 1.3 GB (300 MB to download), because it holds ns-3's build and a C++ toolchain.
- It contains ns-3, so it is distributed under GPLv2's terms. SMOLPy itself stays MIT.
From a clone, for development:
uv sync # installs all runtime + dev dependencies
Quick start
from smolpy import Network
net = Network("office-net")
host_a = net.adapter("host-A", ip="10.0.0.1")
server = net.adapter("server", ip="10.0.0.10")
sw1 = net.switch("sw1", ports=8, mode="store-and-forward")
net.link(host_a, sw1, speed=1_000, length=5) # speed in Mb/s, length in metres
net.link(server, sw1, speed=10_000, length=2)
host_a.sends(to=server, rate=8_000, size=1_518, pattern="constant")
net.observe("throughput", on=server, every=100) # sample every 100 ms
net.observe("queue_depth", on=sw1, every=50)
result = net.simulate(duration=30_000, live=True) # 30 s simulation with live dashboard
result.report() # print summary table to terminal
Run it:
uv run smolpy run my_script.py
Dashboard
When live=True the simulation runs in a background thread while a full-screen Dear PyGui window opens immediately.
Topology panel (left)
Each node is drawn as a coloured circle:
| Colour |
Node type |
| Blue |
Adapter (host / server / NIC / PLC) |
| Green |
Switch |
| Purple |
MQTTBroker |
| Coral red |
ModbusSlave |
| Teal |
ProfinetDevice |
Node fill changes dynamically during the simulation:
| Appearance |
Meaning |
| Dim (faded) |
Node idle — no traffic yet |
| Pulsing bright fill |
Node actively transmitting (bytes_sent > 0) |
| Solid bright fill |
Node forwarding traffic (switch) |
| Pulsing amber outer ring |
Node actively receiving data (bytes_received > 0) |
Animated particles flow along every link to show live traffic direction.
Metrics panel (right)
One chart per observed metric. All series update in real time. Axes auto-scale to fit the data.
Simulation controls
Three controls appear in the title bar during a live simulation:
| Control |
Effect |
| ⏸ Pause |
Freezes simulation time; dashboard stays interactive. Click again to resume. |
| ▶ Resume |
Continues from the exact pause point. |
| ⏹ Stop |
Ends the simulation early; plots freeze at the last collected sample. |
Status indicator:
- ● Simulating… — running
- ● Paused — paused by user
- ● Done — completed normally
- ● Stopped — ended by user
DSL reference
Topology builders
adapter = net.adapter("name", ip="10.0.0.1") # NIC / host / server
switch = net.switch("name", ports=16, mode="store-and-forward") # qos="strict" (default) or "fifo"
broker = net.mqtt_broker("name", ip="10.0.2.1") # MQTT message broker
slave = net.modbus_slave("name", ip="10.0.0.10", unit_id=1) # Modbus TCP slave
device = net.profinet_device("name", ip="10.0.4.1") # PROFINET IO device
net.link(a, b, speed=1_000, length=10) # Mb/s and metres
Multiple switches can be chained to model hierarchical topologies:
core_sw = net.switch("core-sw", ports=16, mode="store-and-forward")
edge_sw = net.switch("edge-sw", ports=8, mode="store-and-forward")
net.link(edge_sw, core_sw, speed=1_000, length=5) # inter-switch uplink
Traffic
# Basic Ethernet send
src.sends(to=dst, rate=8_000, size=1_518, pattern="constant")
# Delayed start (useful for staggered scenarios)
src.sends(to=dst, rate=8_000, size=1_518, pattern="constant", delay_ms=5_000)
# MQTT publish (sensor-style, constant-rate)
sensor.publishes(to=broker, topic="plant/temp", rate=1.0, payload=20, qos=1)
sensor.publishes(to=broker, topic="plant/temp", rate=1.0, payload=20, qos=0, delay_ms=2_000)
# Broker topic routing — must be called before simulate()
broker.routes("plant/temp", to=[server])
# Modbus TCP poll (master → slave, Read Holding Registers)
plc.polls(slave, register=40001, count=10, rate=1.0)
plc.polls(slave, register=30001, count=5, rate=2.0, delay_ms=500)
# ...waiting for each response, with a timeout of 1 s
plc.polls(meter, register=0, count=10, rate=100, outstanding=1, timeout_ms=1_000)
# PROFINET RT cyclic I/O (controller ↔ device), 4 ms update time
plc.controls(device, cycle=4, inputs=32, outputs=16, hold=3)
| Parameter |
Type |
Description |
to |
Adapter |
Destination adapter |
rate |
float |
Frames per second |
size |
int | "imix" |
Ethernet frame size in bytes, FCS included, at least 64; or Internet Mix distribution |
pattern |
str |
"constant", "poisson", "bursty", or "batch" |
delay_ms |
float |
Simulation time before this flow starts (default 0) |
priority |
int |
802.1Q priority (PCP) 0–7 (default 0) |
publishes() parameters
| Parameter |
Type |
Description |
to |
MQTTBroker |
Target broker |
topic |
str |
MQTT topic string |
rate |
float |
Messages per second (default 1.0) |
payload |
int |
Payload bytes (default 20) |
qos |
int |
0 = fire-and-forget, 1 = PUBACK acknowledgement |
delay_ms |
float |
Simulation time before publishing starts (default 0) |
polls() parameters
| Parameter |
Type |
Description |
slave |
ModbusSlave |
Target slave to poll |
register |
int |
Starting holding-register address |
count |
int |
Number of registers to read |
rate |
float |
Polls per second (default 1.0) |
delay_ms |
float |
Simulation time before polling starts (default 0) |
outstanding |
int | None |
1: at most one request of the pair awaits a response; None: unlimited (default) |
timeout_ms |
float | None |
Response timeout, with outstanding=1 (default None: no timeout) |
controls() parameters