Skip to content

async_dust_client

Async KMA Yellow Dust (PM10) Observation API client.

This module provides a client for accessing the Korea Meteorological Administration's Yellow Dust (황사관측) API for PM10 particle observations.

Yellow dust observations monitor Asian dust storms and particulate matter concentrations for air quality assessment and public health alerts.

AsyncDustClient

Async client for KMA Yellow Dust (PM10) Observation API.

The Yellow Dust observation system monitors PM10 particulate matter concentrations from Asian dust storms and other sources, providing critical air quality data for public health protection.

Source code in python/src/kma_mcp/surface/async_dust_client.py
class AsyncDustClient:
    """Async client for KMA Yellow Dust (PM10) Observation API.

    The Yellow Dust observation system monitors PM10 particulate matter
    concentrations from Asian dust storms and other sources, providing
    critical air quality data for public health protection.
    """

    BASE_URL = 'https://apihub.kma.go.kr/api/typ01/url'

    def __init__(self, auth_key: str, timeout: float = 30.0) -> None:
        """Initialize Yellow Dust 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.AsyncClient(timeout=timeout)

    async def __aenter__(self) -> 'AsyncDustClient':
        """Async context manager entry."""
        return self

    async def __aexit__(self, *args: object) -> None:
        """Async context manager exit."""
        await self.close()

    async def close(self) -> None:
        """Close the HTTP client."""
        await self._client.aclose()

    async def _make_request(self, endpoint: str, params: dict[str, Any]) -> dict[str, Any]:
        """Make HTTP request to Yellow Dust 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 = await self._client.get(url, params=params)
        response.raise_for_status()
        return response.json()

    async def get_hourly_data(
        self,
        tm: str | datetime,
        stn: int | str = 0,
    ) -> dict[str, Any]:
        """Get hourly PM10 observation data for a single time.

        Args:
            tm: Time in 'YYYYMMDDHHmm' format or datetime object
            stn: Station number (0 for all stations)

        Returns:
            Hourly PM10 observation data

        Example:
            >>> async with AsyncDustClient('your_auth_key')
            >>> ...     data = await client.get_hourly_data('202501011200')
            >>> # Or using datetime
            >>> from datetime import datetime
            >>> ...     data = await client.get_hourly_data(datetime(2025, 1, 1, 12, 0))
        """
        if isinstance(tm, datetime):
            tm = tm.strftime('%Y%m%d%H%M')

        params = {'tm': tm, 'stn': str(stn), 'help': '0'}
        return await self._make_request('kma_pm10.php', params)

    async def get_hourly_period(
        self,
        tm1: str | datetime,
        tm2: str | datetime,
        stn: int | str = 0,
    ) -> dict[str, Any]:
        """Get hourly PM10 observation data for a time period.

        Args:
            tm1: Start time in 'YYYYMMDDHHmm' format or datetime object
            tm2: End time in 'YYYYMMDDHHmm' format or datetime object
            stn: Station number (0 for all stations)

        Returns:
            Hourly PM10 observation data for the period

        Example:
            >>> async with AsyncDustClient('your_auth_key')
            >>> ...     data = await client.get_hourly_period('202501010000', '202501020000')
        """
        if isinstance(tm1, datetime):
            tm1 = tm1.strftime('%Y%m%d%H%M')
        if isinstance(tm2, datetime):
            tm2 = tm2.strftime('%Y%m%d%H%M')

        params = {'tm1': tm1, 'tm2': tm2, 'stn': str(stn), 'help': '0'}
        return await self._make_request('kma_pm10_2.php', params)

    async def get_daily_data(
        self,
        tm: str | datetime,
        stn: int | str = 0,
    ) -> dict[str, Any]:
        """Get daily PM10 observation data for a single day.

        Args:
            tm: Date in 'YYYYMMDD' format or datetime object
            stn: Station number (0 for all stations)

        Returns:
            Daily PM10 observation data

        Example:
            >>> async with AsyncDustClient('your_auth_key')
            >>> ...     data = await client.get_daily_data('20250101')
        """
        if isinstance(tm, datetime):
            tm = tm.strftime('%Y%m%d')

        params = {'tm': tm, 'stn': str(stn), 'help': '0'}
        return await self._make_request('kma_pm10_day.php', params)

    async def get_daily_period(
        self,
        tm1: str | datetime,
        tm2: str | datetime,
        stn: int | str = 0,
    ) -> dict[str, Any]:
        """Get daily PM10 observation data for a time period.

        Args:
            tm1: Start date in 'YYYYMMDD' format or datetime object
            tm2: End date in 'YYYYMMDD' format or datetime object
            stn: Station number (0 for all stations)

        Returns:
            Daily PM10 observation data for the period

        Example:
            >>> async with AsyncDustClient('your_auth_key')
            >>> ...     data = await client.get_daily_period('20250101', '20250131')
        """
        if isinstance(tm1, datetime):
            tm1 = tm1.strftime('%Y%m%d')
        if isinstance(tm2, datetime):
            tm2 = tm2.strftime('%Y%m%d')

        params = {'tm1': tm1, 'tm2': tm2, 'stn': str(stn), 'help': '0'}
        return await self._make_request('kma_pm10_day2.php', params)

close() async

Close the HTTP client.

Source code in python/src/kma_mcp/surface/async_dust_client.py
async def close(self) -> None:
    """Close the HTTP client."""
    await self._client.aclose()

get_daily_data(tm, stn=0) async

Get daily PM10 observation data for a single day.

Parameters:

  • tm (str | datetime) –

    Date in 'YYYYMMDD' format or datetime object

  • stn (int | str, default: 0 ) –

    Station number (0 for all stations)

Returns:

Example

async with AsyncDustClient('your_auth_key') ... data = await client.get_daily_data('20250101')

Source code in python/src/kma_mcp/surface/async_dust_client.py
async def get_daily_data(
    self,
    tm: str | datetime,
    stn: int | str = 0,
) -> dict[str, Any]:
    """Get daily PM10 observation data for a single day.

    Args:
        tm: Date in 'YYYYMMDD' format or datetime object
        stn: Station number (0 for all stations)

    Returns:
        Daily PM10 observation data

    Example:
        >>> async with AsyncDustClient('your_auth_key')
        >>> ...     data = await client.get_daily_data('20250101')
    """
    if isinstance(tm, datetime):
        tm = tm.strftime('%Y%m%d')

    params = {'tm': tm, 'stn': str(stn), 'help': '0'}
    return await self._make_request('kma_pm10_day.php', params)

get_daily_period(tm1, tm2, stn=0) async

Get daily PM10 observation data for a time period.

Parameters:

  • tm1 (str | datetime) –

    Start date in 'YYYYMMDD' format or datetime object

  • tm2 (str | datetime) –

    End date in 'YYYYMMDD' format or datetime object

  • stn (int | str, default: 0 ) –

    Station number (0 for all stations)

Returns:

  • dict[str, Any]

    Daily PM10 observation data for the period

Example

async with AsyncDustClient('your_auth_key') ... data = await client.get_daily_period('20250101', '20250131')

Source code in python/src/kma_mcp/surface/async_dust_client.py
async def get_daily_period(
    self,
    tm1: str | datetime,
    tm2: str | datetime,
    stn: int | str = 0,
) -> dict[str, Any]:
    """Get daily PM10 observation data for a time period.

    Args:
        tm1: Start date in 'YYYYMMDD' format or datetime object
        tm2: End date in 'YYYYMMDD' format or datetime object
        stn: Station number (0 for all stations)

    Returns:
        Daily PM10 observation data for the period

    Example:
        >>> async with AsyncDustClient('your_auth_key')
        >>> ...     data = await client.get_daily_period('20250101', '20250131')
    """
    if isinstance(tm1, datetime):
        tm1 = tm1.strftime('%Y%m%d')
    if isinstance(tm2, datetime):
        tm2 = tm2.strftime('%Y%m%d')

    params = {'tm1': tm1, 'tm2': tm2, 'stn': str(stn), 'help': '0'}
    return await self._make_request('kma_pm10_day2.php', params)

get_hourly_data(tm, stn=0) async

Get hourly PM10 observation data for a single time.

Parameters:

  • tm (str | datetime) –

    Time in 'YYYYMMDDHHmm' format or datetime object

  • stn (int | str, default: 0 ) –

    Station number (0 for all stations)

Returns:

Example

async with AsyncDustClient('your_auth_key') ... data = await client.get_hourly_data('202501011200')

Or using datetime

from datetime import datetime ... data = await client.get_hourly_data(datetime(2025, 1, 1, 12, 0))

Source code in python/src/kma_mcp/surface/async_dust_client.py
async def get_hourly_data(
    self,
    tm: str | datetime,
    stn: int | str = 0,
) -> dict[str, Any]:
    """Get hourly PM10 observation data for a single time.

    Args:
        tm: Time in 'YYYYMMDDHHmm' format or datetime object
        stn: Station number (0 for all stations)

    Returns:
        Hourly PM10 observation data

    Example:
        >>> async with AsyncDustClient('your_auth_key')
        >>> ...     data = await client.get_hourly_data('202501011200')
        >>> # Or using datetime
        >>> from datetime import datetime
        >>> ...     data = await client.get_hourly_data(datetime(2025, 1, 1, 12, 0))
    """
    if isinstance(tm, datetime):
        tm = tm.strftime('%Y%m%d%H%M')

    params = {'tm': tm, 'stn': str(stn), 'help': '0'}
    return await self._make_request('kma_pm10.php', params)

get_hourly_period(tm1, tm2, stn=0) async

Get hourly PM10 observation data for a time period.

Parameters:

  • tm1 (str | datetime) –

    Start time in 'YYYYMMDDHHmm' format or datetime object

  • tm2 (str | datetime) –

    End time in 'YYYYMMDDHHmm' format or datetime object

  • stn (int | str, default: 0 ) –

    Station number (0 for all stations)

Returns:

  • dict[str, Any]

    Hourly PM10 observation data for the period

Example

async with AsyncDustClient('your_auth_key') ... data = await client.get_hourly_period('202501010000', '202501020000')

Source code in python/src/kma_mcp/surface/async_dust_client.py
async def get_hourly_period(
    self,
    tm1: str | datetime,
    tm2: str | datetime,
    stn: int | str = 0,
) -> dict[str, Any]:
    """Get hourly PM10 observation data for a time period.

    Args:
        tm1: Start time in 'YYYYMMDDHHmm' format or datetime object
        tm2: End time in 'YYYYMMDDHHmm' format or datetime object
        stn: Station number (0 for all stations)

    Returns:
        Hourly PM10 observation data for the period

    Example:
        >>> async with AsyncDustClient('your_auth_key')
        >>> ...     data = await client.get_hourly_period('202501010000', '202501020000')
    """
    if isinstance(tm1, datetime):
        tm1 = tm1.strftime('%Y%m%d%H%M')
    if isinstance(tm2, datetime):
        tm2 = tm2.strftime('%Y%m%d%H%M')

    params = {'tm1': tm1, 'tm2': tm2, 'stn': str(stn), 'help': '0'}
    return await self._make_request('kma_pm10_2.php', params)