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.
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
/healthendpoint will indicate if the upstream API is reachable. - Dependency Issues: Make sure you have run
uv syncand 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 lcraoruv 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
- LCRA Hydromet for providing public data
- Built with FastAPI, Pydantic, and httpx
- Documentation powered by MkDocs and Material for MkDocs
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lcra-0.2.1.tar.gz.
File metadata
- Download URL: lcra-0.2.1.tar.gz
- Upload date:
- Size: 120.9 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
beea9ba1ed51e5948b30851f791b0424e8d76ec4f31580458b37b3c345cf47b6
|
|
| MD5 |
15eda32e6a0a6c7dbb217c43ce41c1ed
|
|
| BLAKE2b-256 |
249896ee19dbfc05a3e0f9f3e22412a50fba9064d0beb305d29379a9f0d72c96
|
File details
Details for the file lcra-0.2.1-py3-none-any.whl.
File metadata
- Download URL: lcra-0.2.1-py3-none-any.whl
- Upload date:
- Size: 10.4 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a62d64f429d8be922558dca6b7d722c1e7f60007db162d1bfad18f5e298efe76
|
|
| MD5 |
0ade15a7f564f2458406e6820688db74
|
|
| BLAKE2b-256 |
52571ab4ddf54c0e0ee0ed368a5bc57d4ec5bd8891cf7c13227d5087b78ed619
|