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+.

pip install pynims

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.1.0.tar.gz (116.9 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.1.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pynims-1.1.0.tar.gz
Algorithm Hash digest
SHA256 d780802cb8c6a2e2d852d0f44c785d51a5350a41e4d11a297c8337c309e434d1
MD5 5df5d5efcad69bc84d685a10186a1261
BLAKE2b-256 1e0aeb5ade8e4d19ff91c35bfcc62ca56ea1361dd9078673fdce4c0bd4037cb9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pynims-1.1.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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d384cf4378ce663ebb3294aa3956e64a3d29f3583b8cfb401a103f72ad80739a
MD5 187c7002dfd58b6c7bd86e579e0129e8
BLAKE2b-256 f88b78ff6aa8edc02d0a0601447cd66dbd4dce44277f77cbb9a50a1aa9e23efd

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