Registry / data / pykrx
library1.2.8pypypi✓ verified 87d ago

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 pykrx
INSTALL
IMPORT
SIG · PYKRX
P
pykrx
datapythonv1.2.8
Install
12.8s avg
Import
3911ms
Disk
270MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.2.8 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 4.034s · 261.3MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 12.8s · import 3.787s · 250MB
270MB installed
● package 270MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

get_market_ohlcv_by_date
from pykrx import stock
import pykrx
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.

This quickstart demonstrates how to fetch historical OHLCV data for a specific stock and market capitalization data for KOSPI using `pykrx`.

from pykrx import stock from datetime import datetime, timedelta # Get today's date and 30 days ago today = datetime.now().strftime('%Y%m%d') start_date = (datetime.now() - timedelta(days=30)).strftime('%Y%m%d') # Example: Get OHLCV data for Samsung Electronics (ticker: 005930) for the last 30 days df = stock.get_market_ohlcv_by_date(start_date, today, "005930") print(f"OHLCV data for 005930 from {start_date} to {today}:") print(df.head()) # Example: Get market cap data for KOSPI on a specific date df_cap = stock.get_market_cap_by_date("20231026", "KOSPI") print(f"\nMarket cap data for KOSPI on 20231026:") print(df_cap.head())
Debug
Known issues
breakingpykrx 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.
fix
Upgrade pykrx to the latest version: `pip install --upgrade pykrx`.
affects: <1.1.1
gotchaDate 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.
fix
Ensure all date strings are formatted as 'YYYYMMDD'. For `datetime` objects, use `date_obj.strftime('%Y%m%d')`.
affects: All versions
gotchaData 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.
fix
Add checks for empty DataFrames (e.g., `if not df.empty:`) and consider error handling for `PyKRXError` in production code.
affects: All versions
Errors
Common errors & fixes
AttributeError: module 'pykrx' has no attribute 'stock'
Attempting to access submodules like `stock` directly from the top-level `pykrx` import, e.g., `import pykrx; pykrx.stock.get_market_ohlcv_by_date(...)`.
fix
Import the specific submodule directly: `from pykrx import stock` or the function: `from pykrx.stock import get_market_ohlcv_by_date`.
ValueError: invalid literal for int() with base 10: '2023-01-01'
Incorrect date format provided to a `pykrx` function. Dates must be in 'YYYYMMDD' string format.
fix
Format your date strings correctly. For example, `start_date = '20230101'` or `datetime_obj.strftime('%Y%m%d')`.
pykrx.errors.PyKRXError: Fail to read data
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.
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.
Upgrade
Version history
1.2.8latest on PyPI · released May 4, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
85 hits · last 30 days
node
76
Resources
pykrx — pip install pykrx · libregistry