# krx-news-client

> Async Python client that returns Korean stock-market news and filings from DART (OpenDART official API), Yonhap News RSS (no key, non-commercial use) and the Naver Search API (official, free key) as one schema: `Disclosure` and `NewsArticle` share `id`, `source`, `title`, `url` and `published_at` (KST, timezone-aware). Includes per-company news search, filing documents, polling de-duplication and correction-filing detection. A library, not a server: no storage, scheduler or cache.

Install `pip install krx-news-client`, Python 3.11+, import name `krx_news_client`.

CLI: `uvx krx-news-client` prints the latest Yonhap Market+ articles with no key; `krx-news watch -t 005930`, `krx-news dart -k 자기주식`, `krx-news doc <rcept_no>`, `krx-news search 삼성전자`, `--json`.
MCP server (DART only, read-only): `claude mcp add krx-news -e DART_API_KEY=... -- uvx --from 'krx-news-client[mcp]' krx-news-client-mcp`; tools `recent_disclosures` and `read_disclosure`. News sources are not exposed over MCP because their terms forbid AI use.

Rules for writing code against this library:

- Everything is async: `async with DartScraper.from_env() as dart, YonhapScraper() as yna, NaverNewsScraper.from_env() as naver:`. In a script wrap it in `asyncio.run(main())`.
- `DartScraper.from_env()` reads `DART_API_KEY` (free key from https://opendart.fss.or.kr). `NaverNewsScraper.from_env()` reads `NAVER_CLIENT_ID` and `NAVER_CLIENT_SECRET` (free, https://developers.naver.com/apps/#/register, enable "Search"). Never hard-code or print keys. `YonhapScraper()` needs no key.
- Main calls: `dart.scrape_disclosures()` (yesterday and today, newest first), `dart.fetch_document(rcept_no)`, `yna.scrape_news(["market"])`, `naver.search_news("삼성전자", tickers=["005930"], since=date(...))`. Results are newest first.
- Terms: Yonhap RSS is for personal, non-commercial use and forbids AI use; Naver Search API results must not be stored (beyond 21 days), cached, given to third parties or fed to AI. For LLM input or backtest storage use DART filings.
- Toss Securities blocks session-less requests since 2026-11-26: `TossScraper` raises `TossBlockedError`. Do not try to bypass it.
- Stock codes are 6 characters (`005930`); an invalid code or page size raises `ValueError`. Toss pages start at 1, page size is at most 100, and the offset limit is 10,000.
- A changed Toss response shape raises `TossResponseError` instead of returning an empty list; DART daily quota exhaustion raises `DartQuotaExceededError`. Do not treat an exception as "no news".
- `Deduplicator().filter_new(items)` drops items already seen in a polling loop; `Disclosure.is_correction` marks correction filings.
- Strict vs tolerant: `search_disclosures*` raises on errors (for backfills), `scrape_disclosures` logs and continues (for polling). Do not mix them up.
- Timestamps are KST with tzinfo. Do not make them naive.

## Docs

- [README (한국어)](https://raw.githubusercontent.com/younghwan91/krx-news-client/main/README.md): quick start, example gallery (watch-list alerts, keyless breaking news, company news search, news plus filings, filing text as LLM input), news-source terms, Toss caveats
- [README (English)](https://raw.githubusercontent.com/younghwan91/krx-news-client/main/README.en.md): the same, in English
- [Guide (한국어)](https://raw.githubusercontent.com/younghwan91/krx-news-client/main/docs/guide.md): detailed usage, design background, Toss API caveats, response fields, structure
- [Guide (English)](https://raw.githubusercontent.com/younghwan91/krx-news-client/main/docs/guide.en.md): the same, in English
- [Comparison with other approaches](https://raw.githubusercontent.com/younghwan91/krx-news-client/main/docs/comparison.md): direct OpenDART calls, Naver, pykrx and FinanceDataReader: scope and code side by side
- [Example: basic usage](https://raw.githubusercontent.com/younghwan91/krx-news-client/main/examples/basic_usage.py): latest Yonhap news
- [Example: stock alert](https://raw.githubusercontent.com/younghwan91/krx-news-client/main/examples/stock_alert.py): polling alert for a watch list

## Optional

- [Changelog](https://raw.githubusercontent.com/younghwan91/krx-news-client/main/CHANGELOG.md): release history
- [CONTRIBUTING](https://raw.githubusercontent.com/younghwan91/krx-news-client/main/CONTRIBUTING.md): dev setup, tests, commit convention
- [Sibling: krx-fundamentals-client](https://github.com/younghwan91/krx-fundamentals-client): company fundamentals (financial statements, ratios, dividends) from DART and Naver
- [Sibling: kiwoom-client](https://github.com/younghwan91/kiwoom-client): Kiwoom Securities REST API client for prices and orders
