- Python code is in
dataretrieval/;dataretrieval/waterdata/is the modern USGS Water Data API,dataretrieval/nwis.pyis legacy/deprecated. R/dataRetrieval/is the R project copy; leave it alone unless the task asks for R work.- Exclude
.claude/worktrees/from searches and edits; it contains stale worktrees that pollute results.
demos/*.ipynb— top-level Water Data tour:USGS_WaterData_Introduction_Examples.ipynbis the entry point;_ContinuousData_,_DailyStatistics_,_DiscreteSamples_,_ReferenceLists_cover individual collections;WaterData_demo.ipynb,peak_streamflow_trends.ipynb,USGS_WaterUse_Examples.ipynb(NWDC water-use data viawateruse.get_wateruse), andR Python Vignette equivalents.ipynbare standalone walkthroughs.demos/hydroshare/*.ipynb— per-service HydroShare examples (NLDI, NWIS WaterUse, and Water Data DailyValues / GroundwaterLevels / Measurements / ParameterCodes / Peaks / Ratings / Samples / SiteInfo / SiteInventory / Statistics / UnitValues). Mirror these when adding examples for a new collection.demos/nwqn_data_pull/— non-notebook example: a lithops/Docker batch pipeline (retrieve_nwqn_samples.py,retrieve_nwqn_streamflow.py) with its ownREADME.md.- Any
Untitled*.ipynb,*_test.ipynb, or notebooks not listed here are untracked local scratch; ignore them.
- Use
pip install .[test,nldi](CI uses pip, not uv despiteuv.lock). Docs:pip install .[doc,nldi].
- Lint:
ruff check .andruff format --check .. - Tests:
coverage run -m pytest tests/ && coverage report -m, or focused likepytest tests/waterdata_test.py::test_mock_get_samples. - Docs: install docs deps,
ipython kernel install --name "python3" --user, thenmake htmlfromdocs/.make docsadds doctest+linkcheck (network-dependent).
- Tests mock HTTP with
pytest-httpx'shttpx_mockfixture and fixtures undertests/data/; keep new API tests offline.tests/conftest.pyrelaxes the fixture's strict-mode defaults (unused mocks and unmocked requests are tolerated) so rerun-on-failure works. tests/nwis_test.py::test_nwis_service_livehits live NWIS.tests/waterdata_test.pyandtests/waterdata_ratings_test.pyskip on Python <3.10, so a 3.9 run does not cover them.
- HTTP client is
httpx(migrated fromrequestsin #289); new code should usehttpxand tests should mock withhttpx_mock. - Public download helpers return
(DataFrame, metadata). dataretrieval/__init__.pystar-imports service modules;dataretrieval/waterdata/__init__.pycontrols Water Data exports via__all__.dataretrieval.waterdata.utils._default_headers()addsX-Api-KeyfromAPI_USGS_PAT; never hard-code tokens in examples or tests.- Water Data request builders translate Python kwargs to API spellings (
skip_geometry->skipGeometry,filter_lang->filter-lang); tests assert exact URLs/query params. - Multi-value OGC params are comma-joined GETs, except
monitoring-locationswhich POSTs CQL2 JSON. The OGC edge WAF caps total request bytes (URL + body) at ~8200, sodataretrieval/waterdata/chunking.pyauto-splits oversized queries across sub-requests (both GET and POST paths); preserve this when adding new list-shaped kwargs. - NLDI requires
geopandasat import time (pip install .[nldi]); other modules fall back to pandas when geopandas is absent.