pykrx is a Python library for scraping data from the Korea Exchange (KRX) and related financial data sources (e.g., Naver Finance). It provides functions to retrieve stock prices, market capitalization, OHLCV data, ETF, and bond information. The library is actively maintained with frequent updates to adapt to changes in upstream data sources and API policies. The current version is 1.2.7.
pip install pykrxVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to fetch historical OHLCV data for a specific stock and market capitalization data for KOSPI using `pykrx`.
Upgrade pykrx to the latest version: `pip install --upgrade pykrx`.
Ensure all date strings are formatted as 'YYYYMMDD'. For `datetime` objects, use `date_obj.strftime('%Y%m%d')`.Add checks for empty DataFrames (e.g., `if not df.empty:`) and consider error handling for `PyKRXError` in production code.
Import the specific submodule directly: `from pykrx import stock` or the function: `from pykrx.stock import get_market_ohlcv_by_date`.
Format your date strings correctly. For example, `start_date = '20230101'` or `datetime_obj.strftime('%Y%m%d')`.Double-check the ticker symbol, ensure the date range includes trading days, and verify internet connectivity. If the issue persists, try updating `pykrx` as the upstream API might have changed.
No dependency data recorded yet.