dataretrieval-python

A Python alternative to USGS-R's dataRetrieval package for obtaining USGS or EPA water quality data, streamflow data, and metadata directly from web services.
https://github.com/DOI-USGS/dataretrieval-python

Category: Natural Resources
Sub Category: Water Supply and Quality

Keywords from Contributors

hydrology usgs water modflow prms ows

Last synced: about 22 hours ago
JSON representation

Repository metadata

Python package for retrieving water data from USGS or the multi-agency Water Quality Portal

README.md

dataretrieval: Download hydrologic data

PyPI - Version
Conda Version
Downloads

Latest Announcements

📣 12/04/2025: dataretrieval now features the new waterdata module,
which provides access to USGS's modernized Water Data
APIs
. The Water Data API endpoints include
daily values, instantaneous values, field measurements, time series metadata,
and discrete water quality data from the Samples database. This new module will
eventually replace the nwis module, which provides access to the legacy NWIS
Water Services
.

Check out the NEWS file for all updates and announcements.

Important: Users of the Water Data APIs are strongly encouraged to obtain an
API key for higher rate limits and greater access to USGS data. Register for
an API key
and set it as an
environment variable:

import os
os.environ["API_USGS_PAT"] = "your_api_key_here"

What is dataretrieval?

dataretrieval simplifies the process of loading hydrologic data into Python.
Like the original R version
dataRetrieval, it retrieves major
U.S. Geological Survey (USGS) hydrology data types available on the Web, as well
as data from the Water Quality Portal (WQP) and Network Linked Data Index
(NLDI).

Installation

Install dataretrieval using pip:

pip install dataretrieval

Or using conda:

conda install -c conda-forge dataretrieval

To install the "main" branch directly from GitHub, use:

pip install git+https://github.com/DOI-USGS/dataretrieval-python.git

Usage Examples

Water Data API (Recommended - Modern USGS Data)

The waterdata module provides access to modern USGS Water Data APIs.

Some basic usage examples include retrieving daily streamflow data for a
specific monitoring location, where the / in the time argument indicates
the desired range:

from dataretrieval import waterdata

# Get daily streamflow data (returns DataFrame and metadata)
df, metadata = waterdata.get_daily(
    monitoring_location_id='USGS-01646500', 
    parameter_code='00060',  # Discharge
    time='2024-10-01/2025-09-30'
)

print(f"Retrieved {len(df)} records")
print(f"Site: {df['monitoring_location_id'].iloc[0]}")
print(f"Mean discharge: {df['value'].mean():.2f} {df['unit_of_measure'].iloc[0]}")

Retrieving streamflow at multiple locations from October 1, 2024 to the present:

df, metadata = waterdata.get_daily(
    monitoring_location_id=["USGS-13018750","USGS-13013650"],
    parameter_code='00060',
    time='2024-10-01/..'
)

print(f"Retrieved {len(df)} records")

Retrieving location information for all monitoring locations categorized as
stream sites in the state of Maryland:

# Get monitoring location information
df, metadata = waterdata.get_monitoring_locations(
    state_name='Maryland',
    site_type_code='ST'  # Stream sites
)

print(f"Found {len(df)} stream monitoring locations in Maryland")

Finally, retrieving continuous (a.k.a. "instantaneous") data
for one location. We strongly advise breaking up continuous data requests into smaller time periods and collections to avoid timeouts and other issues:

# Get continuous data for a single monitoring location and water year
df, metadata = waterdata.get_continuous(
    monitoring_location_id='USGS-01646500', 
    parameter_code='00065',  # Gage height
    time='2024-10-01/2025-09-30'
)
print(f"Retrieved {len(df)} continuous gage height measurements")

Visit the
API Reference
for more information and examples on available services and input parameters.

NEW: This new module implements
logging
in which users can view the URL requests sent to the USGS Water Data APIs
and the number of requests they have remaining each hour. These messages can
be helpful for troubleshooting and support. To enable logging in your python
console or notebook:

import logging
logging.basicConfig(level=logging.INFO)

To log messages to a file, you can specify a filename in the
basicConfig call:

logging.basicConfig(filename='waterdata.log', level=logging.INFO)

NWIS Legacy Services (Deprecated but still functional)

The nwis module accesses legacy NWIS Water Services:

from dataretrieval import nwis

# Get site information
info, metadata = nwis.get_info(sites='01646500')
    
print(f"Site name: {info['station_nm'].iloc[0]}")

# Get daily values
dv, metadata = nwis.get_dv(
  sites='01646500',
  start='2024-10-01',
  end='2024-10-02',
  parameterCd='00060',
)
    
print(f"Retrieved {len(dv)} daily values")

Water Quality Portal (WQP)

Access water quality data from multiple agencies:

from dataretrieval import wqp

# Find water quality monitoring sites
sites = wqp.what_sites(
    statecode='US:55',  # Wisconsin
    siteType='Stream'
)

print(f"Found {len(sites)} stream monitoring sites in Wisconsin")

# Get water quality results
results = wqp.get_results(
    siteid='USGS-05427718',
    characteristicName='Temperature, water'
)

print(f"Retrieved {len(results)} temperature measurements")

Network Linked Data Index (NLDI)

Discover and navigate hydrologic networks:

from dataretrieval import nldi

# Get watershed basin for a stream reach
basin = nldi.get_basin(
    feature_source='comid',
    feature_id='13293474'  # NHD reach identifier  
)

print(f"Basin contains {len(basin)} feature(s)")

# Find upstream flowlines
flowlines = nldi.get_flowlines(
    feature_source='comid',
    feature_id='13293474',
    navigation_mode='UT',  # Upstream tributaries
    distance=50  # km
)

print(f"Found {len(flowlines)} upstream tributaries within 50km")

Available Data Services

Modern USGS Water Data APIs (Recommended)

  • Daily values: Daily statistical summaries (mean, min, max)
  • Instantaneous values: High-frequency continuous data
  • Field measurements: Discrete measurements from field visits
  • Monitoring locations: Site information and metadata
  • Time series metadata: Information about available data parameters
  • Latest daily values: Most recent daily statistical summary data
  • Latest instantaneous values: Most recent high-frequency continuous data
  • Samples data: Discrete USGS water quality data

Legacy NWIS Services (Deprecated)

  • Daily values (dv): Legacy daily statistical data
  • Instantaneous values (iv): Legacy continuous data
  • Site info (site): Basic site information
  • Statistics (stat): Statistical summaries
  • Discharge peaks (peaks): Annual peak discharge events
  • Discharge measurements (measurements): Direct flow measurements

Water Quality Portal

  • Results: Water quality analytical results from USGS, EPA, and other agencies
  • Sites: Monitoring location information
  • Organizations: Data provider information
  • Projects: Sampling project details

Network Linked Data Index (NLDI)

  • Basin delineation: Watershed boundaries for any point
  • Flow navigation: Upstream/downstream network traversal
  • Feature discovery: Find monitoring sites, dams, and other features
  • Hydrologic connectivity: Link data across the stream network

More Examples

Explore additional examples in the
demos
directory, including Jupyter notebooks demonstrating advanced usage patterns.

Getting Help

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for
development guidelines.

Acknowledgments

This material is partially based upon work supported by the National Science
Foundation (NSF) under award 1931297. Any opinions, findings, conclusions, or
recommendations expressed in this material are those of the authors and do not
necessarily reflect the views of the NSF.

Disclaimer

This software is preliminary or provisional and is subject to revision. It is
being provided to meet the need for timely best science. The software has not
received final approval by the U.S. Geological Survey (USGS). No warranty,
expressed or implied, is made by the USGS or the U.S. Government as to the
functionality of the software and related material nor shall the fact of release
constitute any such warranty. The software is provided on the condition that
neither the USGS nor the U.S. Government shall be held liable for any damages
resulting from the authorized or unauthorized use of the software.

Citation

Hodson, T.O., Hariharan, J.A., Black, S., and Horsburgh, J.S., 2023,
dataretrieval (Python): a Python package for discovering and retrieving water
data available from U.S. federal hydrologic web services: U.S. Geological Survey
software release, https://doi.org/10.5066/P94I5TX3.


Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 2 days ago

Total Commits: 250
Total Committers: 21
Avg Commits per committer: 11.905
Development Distribution Score (DDS): 0.564

Commits in past year: 119
Committers in past year: 4
Avg Commits per committer in past year: 29.75
Development Distribution Score (DDS) in past year: 0.151

Name Email Commits
Elise Hinman e****n@u****v 109
thodson-usgs t****n@u****v 81
J. Hariharan j****n@u****v 22
Scott Black s****k@u****u 8
Pabitra Dash p****a@h****m 5
Joseph Stachelek j****a 4
nodohs t****n@R****l 3
Ibrahim El Merehbi e****i 2
Dave Tapley d****e@j****m 2
Doug Dennis d****r@g****m 2
Joshua Larsen j****n@u****v 2
Austin Raney a****y@n****v 1
Camilo J. Bastidas Pacheco c****s@g****m 1
David Blodgett d****t@u****v 1
Edwin 3****c 1
Joe Zemmels (he/him) j****s@g****m 1
Justin Bousquin j****n@y****m 1
Keith Doore 5****e 1
Lee Stanish 8****s 1
MLR m****1@g****m 1
mnfienen m****n@u****v 1

Committer domains:


Issue and Pull Request metadata

Last synced: 6 days ago

Total issues: 98
Total pull requests: 114
Average time to close issues: 4 months
Average time to close pull requests: 12 days
Total issue authors: 50
Total pull request authors: 20
Average comments per issue: 1.96
Average comments per pull request: 1.91
Merged pull request: 94
Bot issues: 0
Bot pull requests: 0

Past year issues: 10
Past year pull requests: 12
Past year average time to close issues: about 2 months
Past year average time to close pull requests: 15 days
Past year issue authors: 6
Past year pull request authors: 3
Past year average comments per issue: 1.4
Past year average comments per pull request: 2.25
Past year merged pull request: 8
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/DOI-USGS/dataretrieval-python

Top Issue Authors

  • thodson-usgs (15)
  • ehinman (10)
  • lstanish-usgs (7)
  • SorooshMani-NOAA (5)
  • davetapley (5)
  • elbeejay (5)
  • putmanannie (4)
  • pkdash (2)
  • jpouliot10 (2)
  • msweier (2)
  • jsta (2)
  • jreniel (1)
  • oconnelljon (1)
  • hwreeves-USGS (1)
  • horsburgh (1)

Top Pull Request Authors

  • thodson-usgs (27)
  • ehinman (22)
  • elbeejay (21)
  • pkdash (6)
  • jsta (5)
  • davetapley (4)
  • sblack-usu (4)
  • jlarsen-usgs (4)
  • elmerehbi (3)
  • cjbas22 (3)
  • dblodgett-usgs (2)
  • aaraney (2)
  • kjdoore (2)
  • lstanish-usgs (2)
  • edsaac (2)

Top Issue Labels

  • bug (6)
  • enhancement (6)
  • question (4)
  • documentation (4)

Top Pull Request Labels

  • bug (7)
  • enhancement (2)
  • documentation (2)
  • upstream bug (2)

Package metadata

pypi.org: dataretrieval

Discover and retrieve water data from U.S. federal hydrologic web services.

  • Homepage:
  • Documentation: https://dataretrieval.readthedocs.io/
  • Licenses: License ======= Unless otherwise noted, this project is in the public domain in the United States because it contains materials that originally came from the United States Geological Survey, an agency of the United States Department of Interior. For more information, see the official USGS copyright policy at https://www.usgs.gov/information-policies-and-instructions/copyrights-and-credits Additionally, we waive copyright and related rights in the work worldwide through the CC0 1.0 Universal public domain dedication. CC0 1.0 Universal Summary ------------------------- This is a human-readable summary of the [Legal Code (read the full text)][1]. ### No Copyright The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission. ### Other Information In no way are the patent or trademark rights of any person affected by CC0, nor are the rights that other persons may have in the work or in how the work is used, such as publicity or privacy rights. Unless expressly stated otherwise, the person who associated a work with this deed makes no warranties about the work, and disclaims liability for all uses of the work, to the fullest extent permitted by applicable law. When using or citing the work, you should not imply endorsement by the author or the affirmer. [1]: https://creativecommons.org/publicdomain/zero/1.0/legalcode
  • Latest release: 1.1.0 (published 29 days ago)
  • Last Synced: 2025-12-21T22:07:12.429Z (4 days ago)
  • Versions: 20
  • Dependent Packages: 8
  • Dependent Repositories: 11
  • Downloads: 8,182 Last month
  • Rankings:
    • Dependent packages count: 1.865%
    • Average: 3.454%
    • Downloads: 4.125%
    • Dependent repos count: 4.373%
  • Maintainers (2)
proxy.golang.org: github.com/doi-usgs/dataretrieval-python

proxy.golang.org: github.com/DOI-USGS/dataretrieval-python


Dependencies

.github/workflows/python-package.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
.github/workflows/python-publish.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v3 composite
  • pypa/gh-action-pypi-publish 27b31702a0e7fc50959f5ad993c78deac1bdfc29 composite
.github/workflows/sphinx-docs.yml actions
  • JamesIves/github-pages-deploy-action v4.4.1 composite
  • actions/checkout v3 composite
requirements-dev.txt pypi
  • coverage * development
  • flake8 * development
  • ipykernel * development
  • ipython * development
  • matplotlib * development
  • nbsphinx * development
  • nbsphinx_link * development
  • numpy * development
  • pandas * development
  • pytest * development
  • python-dateutil * development
  • requests * development
  • requests-mock * development
  • scipy * development
  • sphinx * development
  • sphinx-rtd-theme * development
requirements.txt pypi
  • numpy *
  • pandas *
  • python-dateutil *
  • requests *

Score: 17.590167146453695