Skip to main content

watershed-retrieve

PyPI version License: MIT Python 3.13+

Instant access to ~60,000 pre-delineated watershed boundaries and river networks across 16 countries, served as GeoParquet. Supports multiple hydrofabrics (MERIT-Hydro and HydroSHEDS v1). No data download required — basins are fetched on demand from a public CDN and cached locally.

Background

This library is a community contribution to the RivRetrieve ecosystem. Where RivRetrieve provides observed streamflow time series for gauging stations worldwide, watershed-retrieve adds the corresponding watershed boundaries and river networks.

Delineation is available on two hydrofabrics:

The watershed delineation was performed using a Rust reimplementation of the algorithm described in mheberger/delineator. This is the same methodology used by CAMELS-DE (Loritz et al., 2024) to derive consistent catchment boundaries for 1582 gauging stations across Germany from MERIT Hydro.

See the original proposal: kratzert/RivRetrieve-Python#87.

Installation

pip install watershed-retrieve

Quick Start

import watershed_retrieve as wr

# Zero-config — data is fetched from R2 CDN and cached locally (MERIT-Hydro by default)
watershed = wr.get_watershed("portugal", "04K/04A")

# With river network
watershed, rivers = wr.get_watershed_with_rivers("portugal", "04K/04A")

# Bulk retrieval — all watersheds for a country
all_watersheds = wr.get_watersheds("portugal")

Selecting a hydrofabric

from watershed_retrieve import Fabric

# Use HydroSHEDS v1 instead of MERIT-Hydro
wr.configure(fabric=Fabric.HYDROSHEDS_V1)

# All subsequent calls use HydroSHEDS data
watershed = wr.get_watershed("portugal", "04K/04A")

# Switch back to MERIT-Hydro
wr.configure(fabric=Fabric.MERIT)

Local data directory

# Option 1: Environment variable
# export WATERSHED_RETRIEVE_DATA_DIR=/path/to/parquet/files

# Option 2: Programmatic
wr.configure("/path/to/parquet/files")

# Option 3: Explicit backend selection
from watershed_retrieve import Backend
wr.configure(backend=Backend.R2, cache_dir=Path("~/.my-cache"))

API Reference

Discovery

# List all supported countries
wr.available_countries()
# -> ['australia', 'brazil', 'canada', ..., 'usa']

# List gauge IDs for a country
wr.available_gauges("portugal")
# -> ['02G-02H', '02O-01H', ..., '16J-01H']  (~710 gauges)

Single Watershed

# Watershed boundary (GeoDataFrame, 1 row)
gdf = wr.get_watershed("portugal", "04K/04A")

# Watershed + river network (WatershedResult — unpackable NamedTuple)
result = wr.get_watershed_with_rivers("portugal", "04K/04A")
watershed, rivers = result

Bulk Retrieval

# All watersheds for a country
gdf = wr.get_watersheds("portugal")  # -> GeoDataFrame (~710 rows)

# Subset by gauge IDs
gdf = wr.get_watersheds("portugal", ["04K/04A", "05G/01A"])

# With rivers
result = wr.get_watersheds_with_rivers("portugal")
result.watershed  # GeoDataFrame
result.rivers     # GeoDataFrame

Gauge ID Normalization

Slashes are automatically normalized to dashes:

wr.get_watershed("portugal", "04K/04A")   # slash
wr.get_watershed("portugal", "04K-04A")   # dash — equivalent

Errors

from watershed_retrieve import (
    WatershedRetrieveError,     # base class
    CountryNotFoundError,       # invalid country name
    GaugeNotFoundError,         # gauge ID not in dataset
    DataNotFoundError,          # parquet file missing
    DataUnavailableError,       # region exists but data not yet extracted
    R2ConnectionError,          # CDN fetch failed
)

DataUnavailableError is raised for regions where gauging stations are registered in RivRetrieve but basin delineation is pending (e.g., UK regions — the British Isles fall outside MERIT-Hydro coverage).

Supported Countries

Country MERIT-Hydro HydroSHEDS v1 Status
Australia ~6,210 ~6,240 Available
Brazil ~4,600 ~4,610 Available
Canada ~7,630 ~7,240 Available
Chile ~540 ~530 Available
Czech Republic ~820 ~820 Available
France ~5,330 ~5,360 Available
Germany ~190 ~190 Available
Japan ~820 ~810 Available
Lithuania ~100 ~100 Available
Norway ~4,540 ~1,460 Available
Poland ~1,300 ~1,300 Available
Portugal ~710 ~710 Available
Slovenia ~710 ~710 Available
South Africa ~1,290 ~1,290 Available
Spain ~1,480 ~1,490 Available
UK (EA) — — Pending — coverage gap
UK (NRFA) — — Pending — coverage gap
USA ~23,860 ~23,700 Available

Development

# Install
git clone https://github.com/CooperBigFoot/watershed-retrieve.git
cd watershed-retrieve
uv sync

# Unit tests (no data or network needed)
uv run pytest tests/ -v -m "not integration and not network"

# Integration tests (requires local parquet data)
WATERSHED_RETRIEVE_DATA_DIR=/path/to/data uv run pytest tests/ -v -m integration

# Lint & format
uv run ruff check --fix src/ tests/
uv run ruff format src/ tests/

See CONTRIBUTING.md for full development guidelines.

License

MIT

Metadata

Release files for watershed-retrieve 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for watershed-retrieve 1.2.0
File Size Uploaded Provenance Actions
watershed_retrieve-1.2.0.tar.gz 8.7 kB Without provenance Details for watershed_retrieve-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for watershed-retrieve 1.2.0
File Interpreter ABI Platform Actions
watershed_retrieve-1.2.0-py3-none-any.whl Python 3 none any Details for watershed_retrieve-1.2.0-py3-none-any.whl

Total release size: 19.5 kB

Release files / watershed_retrieve-1.2.0.tar.gz

Download URL watershed_retrieve-1.2.0.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
86a22ba5b1625d9126cd21dca37c866be8b63729a9d4443dabb293abcbe7d511
BLAKE2b-256 checksum
How to use checksums
2f5d2e5d38139b85634ba01d8c22064b2cd8e7667b4506cd8f0e432a383b2381
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / watershed_retrieve-1.2.0-py3-none-any.whl

Download URL watershed_retrieve-1.2.0-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
72963f9f0429c8afb9536952237946d34d7e65f8f684d2260e6a1ddc27e5c642
BLAKE2b-256 checksum
How to use checksums
c0d86dccf8ad00ad931d1707e5f1f10e3746764e56116667792ff253e8c344de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for watershed-retrieve 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page