{"id":10103,"library":"pykrx","title":"pykrx: KRX Data Scraper","description":"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.","status":"active","version":"1.2.7","language":"en","source_language":"en","source_url":"https://github.com/sharebook-kr/pykrx/","tags":["finance","korea","stock market","data scraping","KRX","OHLCV","ETFs","bonds"],"install":[{"cmd":"pip install pykrx","lang":"bash","label":"Install pykrx"}],"dependencies":[],"imports":[{"note":"Submodules like `stock`, `etf`, `bond` are designed to be imported directly, or their functions individually. Importing just `pykrx` does not expose these high-level functions directly under the `pykrx` namespace.","wrong":"import pykrx","symbol":"get_market_ohlcv_by_date","correct":"from pykrx import stock"}],"quickstart":{"code":"from pykrx import stock\nfrom datetime import datetime, timedelta\n\n# Get today's date and 30 days ago\ntoday = datetime.now().strftime('%Y%m%d')\nstart_date = (datetime.now() - timedelta(days=30)).strftime('%Y%m%d')\n\n# Example: Get OHLCV data for Samsung Electronics (ticker: 005930) for the last 30 days\ndf = stock.get_market_ohlcv_by_date(start_date, today, \"005930\")\n\nprint(f\"OHLCV data for 005930 from {start_date} to {today}:\")\nprint(df.head())\n\n# Example: Get market cap data for KOSPI on a specific date\ndf_cap = stock.get_market_cap_by_date(\"20231026\", \"KOSPI\")\nprint(f\"\\nMarket cap data for KOSPI on 20231026:\")\nprint(df_cap.head())","lang":"python","description":"This quickstart demonstrates how to fetch historical OHLCV data for a specific stock and market capitalization data for KOSPI using `pykrx`."},"warnings":[{"fix":"Upgrade pykrx to the latest version: `pip install --upgrade pykrx`.","message":"pykrx relies on scraping external websites (KRX, Naver Finance). Changes in their website structure or API policies (e.g., 'New 2026 Login Policy' mentioned in v1.1.1 release) can break existing functionality. Always keep pykrx updated to the latest version to ensure compatibility.","severity":"breaking","affected_versions":"<1.1.1"},{"fix":"Ensure all date strings are formatted as 'YYYYMMDD'. For `datetime` objects, use `date_obj.strftime('%Y%m%d')`.","message":"Date parameters (start_date, end_date) for most functions expect a strict 'YYYYMMDD' string format. Providing dates in other formats (e.g., 'YYYY-MM-DD', `datetime` objects) will lead to errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Add checks for empty DataFrames (e.g., `if not df.empty:`) and consider error handling for `PyKRXError` in production code.","message":"Data availability can be inconsistent. Queries for non-trading days (weekends, holidays), delisted tickers, or very old/future dates might return empty dataframes or raise specific `PyKRXError` exceptions. Always handle potential empty results.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Import the specific submodule directly: `from pykrx import stock` or the function: `from pykrx.stock import get_market_ohlcv_by_date`.","cause":"Attempting to access submodules like `stock` directly from the top-level `pykrx` import, e.g., `import pykrx; pykrx.stock.get_market_ohlcv_by_date(...)`.","error":"AttributeError: module 'pykrx' has no attribute 'stock'"},{"fix":"Format your date strings correctly. For example, `start_date = '20230101'` or `datetime_obj.strftime('%Y%m%d')`.","cause":"Incorrect date format provided to a `pykrx` function. Dates must be in 'YYYYMMDD' string format.","error":"ValueError: invalid literal for int() with base 10: '2023-01-01'"},{"fix":"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.","cause":"This generic error indicates that `pykrx` failed to retrieve data, often due to an invalid ticker symbol, an invalid or non-trading date, or a temporary issue with the data source.","error":"pykrx.errors.PyKRXError: Fail to read data"}]}