pyswmm?pyswmm is a Python wrapper library for the [EPA SWMM (Storm Water Management Model)] engine, enabling users to control and extend SWMM simulations directly within a Python environment.
"An interface to run, monitor, and control SWMM in real-time using Python."
| Feature | Description |
|---|---|
| ✅ Run SWMM simulations | Execute .inp files via Python |
| ✅ Real-time simulation tracking | Monitor the state of nodes, links, subcatchments, storage units, etc. |
| ✅ Controllable elements | Actively control some components (e.g., storage depth, pump ON/OFF) |
| ✅ Loop integration | Integrate with external algorithms (e.g., reinforcement learning, optimization) |
| ✅ Scenario automation | Run multiple experiments by varying input conditions (e.g., rainfall, infrastructure size) |
| Module | Description |
|---|---|
Simulation | Simulation controller (used with a with statement) |
Nodes | Access and control manholes, storage units, etc. |
Links | Monitor flow/velocity in conduits, pumps, valves |
Subcatchments | Track runoff and watershed data |
Pollutants, LIDControls | Analyze pollutants and low impact development (LID) features |
RainGages | Access rainfall data |
from pyswmm import Simulation, Nodes
with Simulation("model.inp") as sim:
node = Nodes(sim)["J1"]
for step in sim:
print(f"Time: {sim.current_time}, Depth: {node.depth:.2f} m")
| Item | Description |
|---|---|
| No GUI | Command-line based; requires external tools for visualization (e.g., matplotlib, GUI tools) |
| LID real-time control limited | LID parameters can’t be adjusted in real-time; need to edit INP |
| Not full control of all features | Some SWMM components (e.g., rule-based logic) are partially supported |
pip install pyswmm
※ Supports Windows, macOS, Linux.
Note: As it depends on C-based libraries, system-specific build issues may occur → virtual environments are recommended.