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.9+ 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.9 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/
├── main.py              # CLI entrypoint
├── api/                 # FastAPI application
│   └── __init__.py
├── scraper/             # LCRA data scraper
│   └── __init__.py
├── lcra/                # Data models
│   └── __init__.py
├── 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.9 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.2.0.tar.gz (149.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.2.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lcra-0.2.0.tar.gz
  • Upload date:
  • Size: 149.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for lcra-0.2.0.tar.gz
Algorithm Hash digest
SHA256 714727cdd52c4a9c909b1d2d5c3cf7ee140ceb028da00e029abe618e42c8fcbc
MD5 a1405a4b7946c1950d7a80d3d01feb2b
BLAKE2b-256 d3303d74ed42af114a13e2646d4dd1ee0ec5096a435d7b56fd8f78e6e9ed4c73

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lcra-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for lcra-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1a3b4eb3bb2ad33b688dd80550ffcd68d4478812632beea6058d81288b27ab9c
MD5 c873d2c5da265a49d4c969dbe9245763
BLAKE2b-256 ac37ef8310bca9979f90f574d4d89a02750b9a8696729dc8c3a14eb34aef7073

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