Skip to main content

A Python library and CLI tool for extracting flood status, lake levels, river conditions, and floodgate operations from the LCRA Hydromet system

Project description

LCRA Flood Status API

A Python library and CLI tool for extracting real-time flood status, lake levels, river conditions, and floodgate operations from the Lower Colorado River Authority (LCRA) Hydromet system.

Python 3.10+ License: MIT

Overview

This project provides both a command-line interface and a RESTful API to access current flood status, lake levels, river conditions, and floodgate operations for the Lower Colorado River basin in Texas. It fetches data directly from LCRA's public APIs, structures it with Pydantic models, and exposes it via a modern, documented FastAPI interface.

Features

  • Real-time Data: Fetches up-to-date information from LCRA's official APIs
  • Structured Models: Uses Pydantic for data validation and serialization
  • Multiple Endpoints: Access lake levels, river conditions, floodgate operations, and complete flood reports
  • CLI Tool: Command-line interface for quick data extraction
  • REST API: FastAPI-based service with interactive documentation
  • Async & Fast: Built with FastAPI and httpx for high performance
  • Type Safe: Full type hints and Pydantic models
  • Well Tested: Comprehensive test suite with pytest

Installation

From PyPI

pip install lcra

Or using uv:

uv pip install lcra

From Source

git clone https://github.com/lancereinsmith/lcra.git
cd lcra
uv sync  # or: pip install -e .

Requirements

  • Python 3.10 or higher
  • uv (recommended) or pip

Quick Start

CLI Usage

Extract flood operations report:

lcra get --report

Get lake levels:

lcra get --lake-levels

Save to file:

lcra get --report --save

API Server

Start the API server:

lcra serve

Then visit http://localhost:8080/docs for interactive API documentation.

Usage

Command Line Interface

The CLI provides several commands for extracting LCRA data:

Get Data

# Full flood operations report
lcra get --report

# Lake levels only
lcra get --lake-levels

# River conditions only
lcra get --river-conditions

# Floodgate operations only
lcra get --floodgate-operations

Save Output

# Auto-named timestamped file
lcra get --report --save
# Creates: reports/report_2025-01-15T10-30-45.json

# Custom filename
lcra get --report --saveas my_report
# Creates: reports/my_report.json

Start API Server

# Default (localhost:8080)
lcra serve

# Custom host and port
lcra serve --host 0.0.0.0 --port 9000

Python API

from scraper import LCRAFloodDataScraper
from lcra import FloodOperationsReport

async with LCRAFloodDataScraper() as scraper:
    # Get complete report
    report: FloodOperationsReport = await scraper.scrape_all_data()

    # Get specific data
    lake_levels = await scraper.scrape_lake_levels()
    river_conditions = await scraper.scrape_river_conditions()
    floodgate_operations = await scraper.scrape_floodgate_operations()

REST API Endpoints

Endpoint Method Description
/ GET API root info
/health GET Health check (LCRA API connectivity)
/flood-report GET Complete flood operations report
/lake-levels GET Current lake levels at dams
/river-conditions GET Current river conditions
/floodgate-operations GET Current floodgate operations
/docs GET Swagger UI (interactive API docs)
/redoc GET ReDoc (alternative API docs)

Example API Usage

# Get complete flood report
curl http://localhost:8080/flood-report

# Get lake levels
curl http://localhost:8080/lake-levels

# Health check
curl http://localhost:8080/health

Visit http://localhost:8080/docs for interactive API documentation.


Development

Setup

# Clone repository
git clone https://github.com/lancereinsmith/lcra.git
cd lcra

# Install with dev dependencies
uv sync --group dev

Running Tests

pytest

With coverage:

pytest --cov

Code Quality

# Format code
black .

# Lint code
ruff check .

# Type check
mypy .

Building Documentation

mkdocs serve  # Local development
mkdocs build  # Build static site

Project Structure

lcra/
├── src/
│   ├── api/             # FastAPI application
│   │   └── __init__.py
│   ├── scraper/         # LCRA data scraper
│   │   └── __init__.py
│   └── lcra/            # Data models and CLI
│       ├── __init__.py
│       └── cli.py       # CLI entrypoint
├── tests/               # Test suite
├── docs/                # Documentation
├── pyproject.toml       # Project configuration
└── README.md            # This file

Data Sources

This library accesses data from the LCRA Hydromet system, which provides:

  • Lake Levels: Current elevations at major dams (Buchanan, Inks, LBJ, Marble Falls, Travis, Austin, Bastrop)
  • River Conditions: Stage, flow, and flood status at various gauge locations
  • Floodgate Operations: Current and forecasted floodgate operations
  • Narrative Summaries: Text summaries of current flood conditions

Troubleshooting

  • No Data Returned: Ensure the LCRA website and APIs are accessible from your network. The /health endpoint will indicate if the upstream API is reachable.
  • Dependency Issues: Make sure you have run uv sync and are using Python 3.10 or higher.
  • Port Conflicts: If port 8080 is in use, specify another port with --port <number>.
  • Import Errors: Ensure the package is installed: pip install lcra or uv pip install lcra

Contributing

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

Documentation

Full documentation is available at: https://lancereinsmith.github.io/lcra/

Or build locally:

mkdocs serve

License

MIT License - see LICENSE file for details.

Credits

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

lcra-0.3.0.tar.gz (80.0 kB view details)

Uploaded Source

Built Distribution

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

lcra-0.3.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file lcra-0.3.0.tar.gz.

File metadata

  • Download URL: lcra-0.3.0.tar.gz
  • Upload date:
  • Size: 80.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lcra-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d4971139342545dcd5296c9d9ab000c36b200199a1446ed5e448c7f2f42b4f8b
MD5 6c23f16bbc54b2d60a20da4b3b1d9880
BLAKE2b-256 a457877c718993b58a42e255e93533119439f89ea95f8b71d7919dc1ec00456f

See more details on using hashes here.

File details

Details for the file lcra-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: lcra-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lcra-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 abd081445df2383c55e428aff7eef434a92d036be938404a7ad405f5170e0282
MD5 1d4d7a9d976d674d91e4f007ee5badfb
BLAKE2b-256 e015271e0d86ec83f567e406b5eb5e7d53458f6677653475e88c3a2108f6987b

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