KMA Surface Observation Station Information API client.
This module provides a client for accessing the Korea Meteorological Administration's
Surface Observation Station Information (지상관측 지점정보) API.
Station information provides metadata about weather observation stations
including location, altitude, and operational status.
StationClient
Client for KMA Surface Observation Station Information API.
The Station Information system provides metadata about weather
observation stations including location coordinates, altitude,
station type, and operational status.
Source code in python/src/kma_mcp/surface/station_client.py
| class StationClient:
"""Client for KMA Surface Observation Station Information API.
The Station Information system provides metadata about weather
observation stations including location coordinates, altitude,
station type, and operational status.
"""
BASE_URL = 'https://apihub.kma.go.kr/api/typ01/url'
def __init__(self, auth_key: str, timeout: float = 30.0) -> None:
"""Initialize Station Information client.
Args:
auth_key: KMA API authentication key
timeout: Request timeout in seconds (default: 30.0)
"""
self.auth_key = auth_key
self.timeout = timeout
self._client = httpx.Client(timeout=timeout)
def __enter__(self) -> 'StationClient':
"""Context manager entry."""
return self
def __exit__(self, *args: object) -> None:
"""Context manager exit."""
self.close()
def close(self) -> None:
"""Close the HTTP client."""
self._client.close()
def _make_request(self, endpoint: str, params: dict[str, Any]) -> dict[str, Any]:
"""Make HTTP request to Station Information API.
Args:
endpoint: API endpoint path
params: Query parameters
Returns:
API response as dictionary
Raises:
httpx.HTTPError: If request fails
"""
params['authKey'] = self.auth_key
url = f'{self.BASE_URL}/{endpoint}'
response = self._client.get(url, params=params)
response.raise_for_status()
return response.json()
def get_asos_stations(self, stn: int | str = 0) -> dict[str, Any]:
"""Get ASOS station information.
Args:
stn: Station number (0 for all stations)
Returns:
ASOS station information
Example:
>>> client = StationClient('your_auth_key')
>>> data = client.get_asos_stations() # All stations
>>> data = client.get_asos_stations(108) # Specific station
"""
params = {'stn': str(stn), 'help': '0'}
return self._make_request('kma_stnlist.php', params)
def get_aws_stations(self, stn: int | str = 0) -> dict[str, Any]:
"""Get AWS station information.
Args:
stn: Station number (0 for all stations)
Returns:
AWS station information
Example:
>>> client = StationClient('your_auth_key')
>>> data = client.get_aws_stations() # All stations
"""
params = {'stn': str(stn), 'help': '0'}
return self._make_request('kma_aws_stnlist.php', params)
|
close()
Close the HTTP client.
Source code in python/src/kma_mcp/surface/station_client.py
| def close(self) -> None:
"""Close the HTTP client."""
self._client.close()
|
get_asos_stations(stn=0)
Get ASOS station information.
Parameters:
-
stn
(int | str, default:
0
)
–
Station number (0 for all stations)
Returns:
Example
client = StationClient('your_auth_key')
data = client.get_asos_stations() # All stations
data = client.get_asos_stations(108) # Specific station
Source code in python/src/kma_mcp/surface/station_client.py
| def get_asos_stations(self, stn: int | str = 0) -> dict[str, Any]:
"""Get ASOS station information.
Args:
stn: Station number (0 for all stations)
Returns:
ASOS station information
Example:
>>> client = StationClient('your_auth_key')
>>> data = client.get_asos_stations() # All stations
>>> data = client.get_asos_stations(108) # Specific station
"""
params = {'stn': str(stn), 'help': '0'}
return self._make_request('kma_stnlist.php', params)
|
get_aws_stations(stn=0)
Get AWS station information.
Parameters:
-
stn
(int | str, default:
0
)
–
Station number (0 for all stations)
Returns:
Example
client = StationClient('your_auth_key')
data = client.get_aws_stations() # All stations
Source code in python/src/kma_mcp/surface/station_client.py
| def get_aws_stations(self, stn: int | str = 0) -> dict[str, Any]:
"""Get AWS station information.
Args:
stn: Station number (0 for all stations)
Returns:
AWS station information
Example:
>>> client = StationClient('your_auth_key')
>>> data = client.get_aws_stations() # All stations
"""
params = {'stn': str(stn), 'help': '0'}
return self._make_request('kma_aws_stnlist.php', params)
|