Skip to main content

A Python package for managing hydraulic calculation actions: EPANET/SWMM simulations, RPT file imports, and more

Project description

Hydraulic Engine

Testing CI - Test
Package PyPI Latest Release PyPI Downloads
Meta License - GNU GPL3

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

import hydraulic_engine as he

# Create runner
runner = he.SwmmRunner(inp_path="drainage_model.inp")

# Run simulation
result = runner.run()

# Check results
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

import hydraulic_engine as he

# Create runner
runner = he.EpanetRunner(inp_path="water_network.inp")

# Run simulation
result = runner.run()

# Check results
if result.status.value == "success":
    print(f"Simulation completed in {result.duration_seconds:.2f}s")

Reading SWMM INP Files

import hydraulic_engine as he

# Create handler
handler = he.SwmmInpHandler()

# Read INP file
if handler.read("model.inp"):
    # Get model summary
    summary = handler.get_summary()
    print(f"Junctions: {summary['counts']['junctions']}")
    print(f"Conduits: {summary['counts']['conduits']}")

    # Get specific sections
    junctions = handler.get_junctions()
    conduits = handler.get_conduits()

    # Modify and save
    handler.write("modified_model.inp")

Reading SWMM Results

import hydraulic_engine as he

# Create handler
handler = he.SwmmRptHandler()

# Read RPT file
if handler.load_result("results.rpt"):
    # Get results
    node_depths = handler.get_node_depth_summary()
    link_flows = handler.get_link_flow_summary()

Validating INP Files

import hydraulic_engine as he

# Validate without running
runner = he.SwmmRunner()
validation = runner.validate_inp("model.inp")

if validation["valid"]:
    print(f"Model info: {validation['info']}")
else:
    print(f"Validation errors: {validation['errors']}")

Progress Tracking

import hydraulic_engine as he

def on_progress(progress: int, message: str):
    print(f"[{progress}%] {message}")

runner = he.SwmmRunner(progress_callback=on_progress)
result = runner.run("model.inp")

Database Connection

The package supports database connections for storing/retrieving model data.

PostgreSQL Connection

import hydraulic_engine as he

# Create connection (becomes the default)
conn = he.create_pg_connection(
    host="localhost",
    port=5432,
    dbname="hydraulic_db",
    user="user",
    password="pass",
    schema="my_schema"
)

# Use connection
rows = conn.get_rows("SELECT * FROM nodes")

# Close when done
he.close_connection()

GeoPackage Connection

import hydraulic_engine as he

# Create connection
conn = he.create_gpkg_connection("project.gpkg")

# Query data
rows = conn.get_rows("SELECT * FROM conduits")

# Close when done
he.close_connection()

Package Structure

hydraulic-engine/
├── src/
│   └── hydraulic_engine/
│       ├── __init__.py│
│       ├── config/
│       │   ├── config.py
│       ├── core/
│       │   ├── swmm/                    # SWMM-specific functionality
│       │   │   ├── 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
│       │   ├── epanet/                  # EPANET-specific functionality
│       │   │   ├── runner.py            # Run EPANET simulations
│       │   │   ├── inp_handler.py       # Parse/write EPANET INP files
│       │   │   └── bin_handler.py       # Parse EPANET BINARY files
│       │   └── utils/                   # Shared utilities
│       │       ├── tools_log.py
│       │       ├── tools_db.py
│       │       └── tools_api.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.60 (INP/RPT file parsing)
  • wntr >= 1.0.0 (EPANET simulations)
  • psycopg[binary] >= 3.1.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

hydraulic_engine-0.3.2.tar.gz (73.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hydraulic_engine-0.3.2-py3-none-any.whl (80.5 kB view details)

Uploaded Python 3

File details

Details for the file hydraulic_engine-0.3.2.tar.gz.

File metadata

  • Download URL: hydraulic_engine-0.3.2.tar.gz
  • Upload date:
  • Size: 73.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hydraulic_engine-0.3.2.tar.gz
Algorithm Hash digest
SHA256 06c844d028900e7e4623b879d85ed38b8673d6335a97febf4197dc880d2dd0ad
MD5 bb916321d7dc847b7834a65cc023cd8f
BLAKE2b-256 d350d55d77aea24737a25cf34a9a6f588755858927a1c1e579e2adf7e7278009

See more details on using hashes here.

Provenance

The following attestation bundles were made for hydraulic_engine-0.3.2.tar.gz:

Publisher: publish-to-pypi.yml on Giswater/hydraulic_engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hydraulic_engine-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for hydraulic_engine-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 713d94465e5f83a135aa200e8be1d8eea00f8d3ac285e9161532ac5180f5e0e7
MD5 c8314d42cc2d9108e36abc67b5b6e9b3
BLAKE2b-256 6f5840b16cd1e384ad269bb18535c4be73622631cd60e35375a2b6d436e65676

See more details on using hashes here.

Provenance

The following attestation bundles were made for hydraulic_engine-0.3.2-py3-none-any.whl:

Publisher: publish-to-pypi.yml on Giswater/hydraulic_engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page