A Python package for managing hydraulic calculation actions: EPANET/SWMM simulations, RPT file imports, and more
Project description
Hydraulic Engine
| Testing | |
| Package | |
| Meta |
A Python package for managing hydraulic calculation actions: EPANET/SWMM simulations, RPT file imports, and more.
Features
- Run SWMM simulations: Execute Storm Water Management Model simulations
- Run EPANET simulations: Execute water distribution network simulations
- Parse INP files: Read and modify SWMM/EPANET input files
- Parse RPT files: Read and analyze simulation results
- Multiple database support: PostgreSQL (psycopg3), SQLite, and GeoPackage
Installation
From PyPI
pip install hydraulic-engine
From source
git clone https://github.com/bgeo-gis/hydraulic-engine.git
cd hydraulic-engine
pip install -e .
Development installation
pip install -e ".[dev]"
Quick Start
Running a SWMM Simulation
from hydraulic_engine.swmm import SwmmRunner
runner = SwmmRunner(
inp_path="drainage_model.inp",
rpt_path="results.rpt",
out_path="results.out",
)
result = runner.run()
if result.status.value == "success":
print(f"Simulation completed in {result.duration_seconds:.2f}s")
print(f"RPT file: {result.rpt_path}")
else:
print(f"Errors: {result.errors}")
Running an EPANET Simulation
from hydraulic_engine.epanet import EpanetRunner
runner = EpanetRunner(
inp_path="water_network.inp",
rpt_path="results.rpt",
bin_path="results.bin",
)
result = runner.run()
if result.status.value == "success":
print(f"Simulation completed in {result.duration_seconds:.2f}s")
Reading SWMM INP Files
from hydraulic_engine.swmm import SwmmInpHandler
handler = SwmmInpHandler()
handler.load_file("model.inp")
summary = handler.get_summary()
print(f"Junctions: {summary['counts']['junctions']}")
print(f"Conduits: {summary['counts']['conduits']}")
junctions = handler.get_junctions()
conduits = handler.get_conduits()
handler.write("modified_model.inp")
Reading SWMM Results
from hydraulic_engine.swmm import SwmmRptHandler
handler = SwmmRptHandler()
handler.load_file("results.rpt")
node_depths = handler.get_node_depth_summary()
link_flows = handler.get_link_flow_summary()
Progress Tracking
from hydraulic_engine.swmm import SwmmRunner
def on_progress(progress: int, message: str):
print(f"[{progress}%] {message}")
runner = SwmmRunner(inp_path="model.inp", progress_callback=on_progress)
result = runner.run()
Database Connection
The package supports database connections for storing/retrieving model data.
PostgreSQL Connection
import hydraulic_engine as he
conn = he.create_pg_connection(
host="localhost",
port=5432,
dbname="hydraulic_db",
user="user",
password="pass",
schema="my_schema",
)
rows = conn.get_rows("SELECT * FROM nodes")
he.close_connection()
GeoPackage Connection
import hydraulic_engine as he
conn = he.create_gpkg_connection("project.gpkg")
rows = conn.get_rows("SELECT * FROM conduits")
he.close_connection()
Package Structure
hydraulic-engine/
├── src/
│ └── hydraulic_engine/
│ ├── __init__.py
│ ├── exceptions.py
│ ├── config/
│ │ └── config.py
│ ├── epanet/
│ │ ├── runner.py # Run EPANET simulations
│ │ ├── inp_handler.py # Parse/write EPANET INP files
│ │ ├── bin_handler.py # Parse EPANET binary result files
│ │ ├── file_handler.py
│ │ └── models.py
│ ├── swmm/
│ │ ├── runner.py # Run SWMM simulations
│ │ ├── inp_handler.py # Parse/write SWMM INP files
│ │ ├── rpt_handler.py # Parse SWMM RPT files
│ │ ├── out_handler.py # Parse SWMM OUT files
│ │ ├── file_handler.py
│ │ └── models.py
│ └── utils/
│ ├── tools_log.py
│ ├── tools_db.py
│ ├── tools_api.py
│ ├── tools_os.py
│ ├── tools_config.py
│ └── tools_sensorthings.py
├── tests/
├── pyproject.toml
└── README.md
API Reference
SWMM Classes
| Class | Description |
|---|---|
SwmmRunner |
Run SWMM simulations |
SwmmInpHandler |
Read/write SWMM INP files |
SwmmRptHandler |
Parse SWMM RPT result files |
SwmmOutHandler |
Parse SWMM OUT result files |
EPANET Classes
| Class | Description |
|---|---|
EpanetRunner |
Run EPANET simulations |
EpanetInpHandler |
Read/write EPANET INP files |
EpanetBinHandler |
Parse EPANET BIN result files |
Connection Functions
| Function | Description |
|---|---|
create_pg_connection(...) |
Create PostgreSQL connection |
create_gpkg_connection(gpkg_path) |
Create GeoPackage connection |
create_sqlite_connection(db_path) |
Create SQLite connection |
get_connection() |
Get current default connection |
close_connection() |
Close default connection |
Dependencies
- Python >= 3.9
- pyswmm >= 2.0.0 (SWMM simulation engine)
- swmm-api >= 0.4.31 (INP/RPT file parsing)
- wntr >= 1.2.0 (EPANET simulations)
- psycopg[binary] >= 3.1.0
- requests >= 2.28.0
- pyproj >= 3.6.0
Development
Running tests
pytest tests/
Code formatting
black src/
ruff check src/
License
GNU General Public License v3.0 or later - see LICENSE.
Authors
BGEO - info@bgeo.es
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hydraulic_engine-0.4.1.tar.gz.
File metadata
- Download URL: hydraulic_engine-0.4.1.tar.gz
- Upload date:
- Size: 73.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0081eb0c88ce1be3570dd3836b1855327600c249fb2fa8ab4d8fb8b96cb722b6
|
|
| MD5 |
bd3f633b72857b6d97c6eb89b8055346
|
|
| BLAKE2b-256 |
c340f450ff391b5970d9c0571ff068557f92ee50ef5ac576f5468955d360be23
|
Provenance
The following attestation bundles were made for hydraulic_engine-0.4.1.tar.gz:
Publisher:
publish-to-pypi.yml on bgeo-gis/hydraulic-engine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hydraulic_engine-0.4.1.tar.gz -
Subject digest:
0081eb0c88ce1be3570dd3836b1855327600c249fb2fa8ab4d8fb8b96cb722b6 - Sigstore transparency entry: 1922714785
- Sigstore integration time:
-
Permalink:
bgeo-gis/hydraulic-engine@5b2619fd2e766f4efb6adc36583438c796e85c49 -
Branch / Tag:
refs/tags/v0.4.1 - Owner: https://github.com/bgeo-gis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@5b2619fd2e766f4efb6adc36583438c796e85c49 -
Trigger Event:
push
-
Statement type:
File details
Details for the file hydraulic_engine-0.4.1-py3-none-any.whl.
File metadata
- Download URL: hydraulic_engine-0.4.1-py3-none-any.whl
- Upload date:
- Size: 82.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce8c3a7b1f48f7299bd184d520a17b9704d6580c43f89dbc5919b19aa4e42f64
|
|
| MD5 |
4187dd92eb62ff26cf299fe86c27c9ac
|
|
| BLAKE2b-256 |
1861fcffd55a3da234c894ce9d4c06d28c927e3212a9c0c99f63027f4014181e
|
Provenance
The following attestation bundles were made for hydraulic_engine-0.4.1-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on bgeo-gis/hydraulic-engine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hydraulic_engine-0.4.1-py3-none-any.whl -
Subject digest:
ce8c3a7b1f48f7299bd184d520a17b9704d6580c43f89dbc5919b19aa4e42f64 - Sigstore transparency entry: 1922714902
- Sigstore integration time:
-
Permalink:
bgeo-gis/hydraulic-engine@5b2619fd2e766f4efb6adc36583438c796e85c49 -
Branch / Tag:
refs/tags/v0.4.1 - Owner: https://github.com/bgeo-gis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@5b2619fd2e766f4efb6adc36583438c796e85c49 -
Trigger Event:
push
-
Statement type: