Skip to main content

A Python package for interacting with the National Imagery Management System (NIMS)

Project description

PyNIMS

Python client and CLI (command-line interface) for the USGS NIMS (National Imagery Management System) API. Use it to query camera metadata, list and download imagery, and construct image URLs — from Python scripts or the command line.


Installation

Requires Python 3.10+.

From git

Choose SSH or HTTPS depending on your GitLab setup:

# SSH (if you have a GitLab SSH key configured)
pip install git+ssh://git@code.usgs.gov/wim/usgs-imagery/sdk/pynims.git

# HTTPS (prompts for GitLab username/password)
pip install git+https://code.usgs.gov/wim/usgs-imagery/sdk/pynims.git

Need to set up an SSH key? See the GitLab SSH key docs.


API Key

The NIMS API works without a key, but unauthenticated requests are rate-limited. We strongly recommend signing up for a free API key:

👉 https://api.waterdata.usgs.gov/signup/

You can provide your key in two ways:

# Option 1: Constructor parameter
client = NIMSClient(api_key="your-key-here")

# Option 2: Environment variable
# export NIMS_API_KEY=your-key-here
client = NIMSClient()  # picks up NIMS_API_KEY automatically

If no key is found, the client will issue a warning but continue to work.


Python API

Use the Python API in your scripts or an interactive Python session (e.g., python, IPython, or a Jupyter notebook). The typical workflow is: find cameras → list images → download or get URLs.

from pynims import NIMSClient

with NIMSClient(api_key="your-key-here") as client:
    # 1. Find cameras at a site (omit site_id to get all cameras)
    cameras = client.get_cameras(site_id="05366800")
    cam_id = cameras[0]["camId"]

    # 2. List images for a time range
    images = client.get_image_list(cam_id, start="2023-06-01", end="2023-06-02")

    # 3. Construct image URLs (full, thumb, or small)
    urls = client.get_image_urls(images)                      # full-size
    thumb_urls = client.get_image_urls(images, size="thumb")  # thumbnails

    # 4. Or download directly
    client.download_image(images[0])                      # full-size
    client.download_image(images[0], size="small")        # 720px

    # 5. Quick access to timelapse and newest image
    timelapse = client.get_timelapse_url(cam_id)
    newest = client.get_newest_image_url(cam_id)

CLI

After installing, the pynims command is available in your terminal. Run these commands from any command prompt (Terminal on macOS/Linux, Command Prompt or PowerShell on Windows).

# Check version
pynims --version

# List all camera IDs
pynims cameras

# List cameras at a site, or with full details / JSON output
pynims cameras --site-id 05366800
pynims cameras --full
pynims cameras --json

# Get details for a single camera
pynims camera CAM_ID

# List images (prints to stdout by default)
pynims image-list CAM_ID --start=2023-06-01 --end=2023-06-10
pynims image-list CAM_ID --start=2023-06-01 --end=2023-06-10 --json
pynims image-list CAM_ID --start=2023-06-01 --end=2023-06-10 --save-dir=./out

# Download images
pynims download-images CAM_ID --start=2023-06-01 --end=2023-06-10 --api-key=your-key
pynims download-images CAM_ID --start=2023-06-01 --end=2023-06-10 --size=thumb
pynims download-images --image-list-file=images.json

Use --help on any command for details:

pynims --help
pynims download-images --help

Filtering

Filter image lists by time of day, season, date range, and more — from Python or the CLI.

# Daytime summer images
pynims image-list CAM1 --start 2023-01-01 --end 2023-12-31 --hours 8-17 --months 6,7,8

# Download one image per day
pynims download-images CAM1 --start 2023-06-01 --end 2023-06-30 --interval 24h

See the Filtering Guide for full documentation, including the Python API, chaining examples, and all available filters.


Development

git clone https://code.usgs.gov/wim/usgs-imagery/sdk/pynims.git
cd pynims

# Using pip
python -m venv .venv
source .venv/bin/activate   # macOS/Linux
pip install -e ".[dev]"

# Or using uv
uv sync

# Run tests
pytest

# Lint / format
ruff check .
ruff format .

Suggested Citation

Johnson, K.E., 2026, PyNIMS: Python client and CLI for the USGS NIMS API (v1.0.0), U.S. Geological Survey Software Release, https://doi.org/10.5066/P13FBPDN.


Releases

A newer version of this software may be available. See all releases.


Use of Artificial Intelligence

AI-assisted coding tools were used during development, specifically Kiro CLI (multiple versions). All code was reviewed, tested, and validated by the author to ensure correctness and reproducibility.


License and Disclaimer

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

pynims-1.0.0.tar.gz (115.8 kB view details)

Uploaded Source

Built Distribution

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

pynims-1.0.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file pynims-1.0.0.tar.gz.

File metadata

  • Download URL: pynims-1.0.0.tar.gz
  • Upload date:
  • Size: 115.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for pynims-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7fcff4ae0401241af53c6233cadbb80ac9f9686b26db05c8a93c64639ea9be08
MD5 898be0a6e7c1cc0094d89353e737714a
BLAKE2b-256 09311cc84f505511b83d698820616b6b3dd17b729132cd2de92451c7887ca92e

See more details on using hashes here.

File details

Details for the file pynims-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pynims-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for pynims-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e519e7eed13c6693f6109803cf391ddf80f0b667b563c40c218a765e752e83b9
MD5 0c3fa1187a60fb38c6cb6f16503a88d2
BLAKE2b-256 46b380f186fc6e70b98b8059b6465f100e8a7dec25772dc9cce6dfd51c74e4f7

See more details on using hashes here.

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