Skip to content

Commit ca5926c

Browse files
thodson-usgsclaude
andcommitted
refactor(api)!: expose service submodules, not a flattened top-level namespace
`dataretrieval/__init__.py` star-imported every service module, flattening all their public functions into the top-level package namespace. That: - leaked one large, ambiguous namespace (`dataretrieval.get_dv`, `dataretrieval.get_results`, ...), and - silently collided on names defined by more than one service: `get_ratings` (nwis vs waterdata) and `what_sites` (nwis vs wqp) resolved to whichever module was star-imported last; the other was shadowed. Replace the star-imports with submodule imports, so callers reach each service through its own module -- the pattern the README, the docs (per-module autodoc), and the tests already use: from dataretrieval import waterdata df, meta = waterdata.get_ratings(...) from dataretrieval import nwis df, meta = nwis.get_ratings(...) `dataretrieval.<name>` and `from dataretrieval import <name>` still work for every service module, and `__version__` is unchanged. `nldi` remains import-on-demand (it pulls in the optional geopandas dependency). The collision is now impossible -- each `get_ratings` / `what_sites` lives only under its module. BREAKING CHANGE: top-level function access (e.g. `dataretrieval.get_dv`) is removed; use the service module (`dataretrieval.nwis.get_dv`). Exception and helper classes likewise move under their modules (e.g. `dataretrieval.utils.NoSitesError`). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 1adf174 commit ca5926c

1 file changed

Lines changed: 39 additions & 7 deletions

File tree

dataretrieval/__init__.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,46 @@
1+
"""Discover and retrieve water data from U.S. federal hydrologic web services.
2+
3+
Access each service through its submodule::
4+
5+
from dataretrieval import waterdata # modern USGS Water Data API
6+
7+
df, meta = waterdata.get_daily(monitoring_location_id="USGS-05427718")
8+
9+
from dataretrieval import nwis # legacy NWIS services
10+
11+
df, meta = nwis.get_dv(sites="05427718")
12+
13+
Available service modules: ``waterdata``, ``wqp`` (Water Quality Portal),
14+
``nldi``, ``samples``, ``streamstats``, ``nadp``, and the deprecated ``nwis``.
15+
16+
``nldi`` requires geopandas (``pip install dataretrieval[nldi]``) and is
17+
imported on demand: ``from dataretrieval import nldi``.
18+
"""
19+
120
from importlib.metadata import PackageNotFoundError, version
221

322
try:
423
__version__ = version("dataretrieval")
524
except PackageNotFoundError:
625
__version__ = "version-unknown"
726

8-
from dataretrieval.nadp import *
9-
from dataretrieval.nwis import *
10-
from dataretrieval.samples import *
11-
from dataretrieval.streamstats import *
12-
from dataretrieval.utils import *
13-
from dataretrieval.waterdata import *
14-
from dataretrieval.wqp import *
27+
from . import (
28+
nadp,
29+
nwis,
30+
samples,
31+
streamstats,
32+
utils,
33+
waterdata,
34+
wqp,
35+
)
36+
37+
__all__ = [
38+
"nadp",
39+
"nwis",
40+
"samples",
41+
"streamstats",
42+
"utils",
43+
"waterdata",
44+
"wqp",
45+
"__version__",
46+
]

0 commit comments

Comments
 (0)