Asynchronous Python client for the Vigicrues API (French flood monitoring service)
Project description
Vigicrues Python Client
A Python client for the Vigicrues API (French flood monitoring service). This library allows you to search for monitoring stations and retrieve real-time water level and flow rate observations.
Features
- Search Stations: Find monitoring stations using the OpenDataSoft API
- Station Details: Get comprehensive information about specific stations
- Real-time Observations: Retrieve latest water level (H) and flow rate (Q) data
- Territory Management: List territories and river sections
- CLI Interface: Command-line tool for quick data access
- Async Support: Fully asynchronous implementation for high performance
Installation
pip install vigicrues
Or install from source:
git clone git@github.com:enavarro222/vigicrues.git
cd vigicrues
pip install -e .[dev]
Quick Start
import asyncio
from vigicrues import Vigicrues
async def main():
# Initialize client
async with Vigicrues() as client:
# Search for stations
stations = await client.search_stations("Paris")
print(f"Found {len(stations)} stations:")
for station in stations:
print(f"- {station.name} (ID: {station.id})")
# Get station details
if stations:
details = await client.get_station_details(stations[0].id)
print(f"\nStation details for {details.name}:")
print(f" River: {details.river}")
print(f" Location: {details.city}")
print(f" Coordinates: ({details.latitude}, {details.longitude})")
# Get latest observations
if details.has_height_data:
observation = await client.get_latest_observations(details.id, "H")
print(f" Latest water level: {observation.value} {observation.unit} at {observation.timestamp}")
if details.has_flow_data:
observation = await client.get_latest_observations(details.id, "Q")
print(f" Latest flow rate: {observation.value} {observation.unit} at {observation.timestamp}")
if __name__ == "__main__":
asyncio.run(main())
CLI Usage
# Search for stations
vigicrues search "Paris"
# Get latest observations for a station
vigicrues get O408101001
# List all territories
vigicrues territories
# List troncons in a territory
vigicrues troncons 25
# List stations in a troncon
vigicrues stations TL12
API Documentation
Client Initialization
The Vigicrues client supports two initialization patterns:
Pattern 1: Async Context Manager (Recommended)
async with Vigicrues() as client:
# Use client here
pass
# Session automatically closed
Pattern 2: External Session (Advanced)
async with aiohttp.ClientSession() as session:
client = Vigicrues(session=session)
# Use client here
# User responsible for closing session
Main Client Methods
Search Stations
async def search_stations(self, query: str) -> list[Station]:
"""Search for stations by name or location.
Args:
query: Search term (station name, city, etc.)
Returns:
List of matching stations
"""
Get Station Details
async def get_station_details(self, station_id: str) -> StationDetails:
"""Get comprehensive details for a specific station.
Args:
station_id: Station identifier (e.g., "O408101001")
Returns:
Detailed station information including location, historical floods, etc.
"""
Get Latest Observations
async def get_latest_observations(self, station_id: str, obs_type: str) -> Observation:
"""Get the latest observation for a station.
Args:
station_id: Station identifier
obs_type: Observation type ("H" for height, "Q" for flow)
Returns:
Latest observation with timestamp
"""
Data Models
Territory
Represents a Vigicrues territory.
id:str(e.g., "25")name:str(e.g., "Garonne-Tarn-Lot")
Troncon
Represents a river section/segment within a territory.
id:str(e.g., "TL12")name:str(e.g., "Célé")
Station
Base model for a Vigicrues monitoring station.
id:str(e.g., "O494101001")name:str
StationDetails
Extends Station with additional detailed information.
river:strcity:strlatitude:floatlongitude:floatpicture_url:str | Nonecommune_code:str | Noneis_prediction_station:boolhas_height_data:boolhas_flow_data:boolhas_predictions:boolhistorical_floods:list[dict]related_stations:list[dict]
Observation
A single data point for water level or flow.
timestamp:datetimevalue:floattype:ObservationType(Enum:Hfor Height,Qfor Flow)unit:str(e.g., "m" or "m³/s")
Development
Requirements
- Python 3.10+
aiohttpfor HTTP requestspydanticfor data validationrufffor linting and formattingmypyfor type checkingpytestfor testing
Running Tests
# Install development dependencies
pip install -e .[dev]
# Run tests with coverage
pytest --cov=vigicrues --cov-report=html
# Run linting and type checking
ruff check vigicrues tests
mypy vigicrues
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
API Sources
This client uses the following official Vigicrues APIs:
- OpenDataSoft API: Station metadata and search
- Vigicrues API: Real-time observations and station details
Support
For issues and questions, please open an issue on the GitHub repository.
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 vigicrues-0.1.0.tar.gz.
File metadata
- Download URL: vigicrues-0.1.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
144ce54b249a6030777bc5486c9dea1f753664d2411863473246410243b67f35
|
|
| MD5 |
6cfb9c11193a57f031ecf84419a8bec6
|
|
| BLAKE2b-256 |
1d9856a6187befb755c7af2dcd75401df69e3ccd0af054cd1fecb06a7e07bd18
|
File details
Details for the file vigicrues-0.1.0-py3-none-any.whl.
File metadata
- Download URL: vigicrues-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
064ec73902bfcf17f7a71ee59d05b2802f07d9463afc670f77449ed391bf4602
|
|
| MD5 |
5cc872e78cfd4836284c3c7da92baba7
|
|
| BLAKE2b-256 |
e6285fc0b8b6afc95fc179a42aeb24ea300c3a9fe203068359eec40e7ad3a92c
|